Skip to content

Commit

Permalink
feat: add multistage docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
geekyharsh05 committed Oct 2, 2024
1 parent a27312e commit 7b43955
Show file tree
Hide file tree
Showing 28 changed files with 515 additions and 302 deletions.
9 changes: 5 additions & 4 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ FROM node:20-alpine

WORKDIR /usr/src/app

COPY package.json package-lock.json ./
COPY package.json pnpm-lock.yaml ./
COPY prisma ./prisma

RUN npm install
RUN npm i pnpm -g

RUN pnpm install

COPY . .

EXPOSE 3000

CMD ["npm", "run", "dev:docker"]

CMD ["pnpm", "dev:docker"]
31 changes: 24 additions & 7 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
FROM node:20-alpine
ARG DATABASE_URL
FROM node:20-alpine AS build

WORKDIR /usr/src/app
ARG DATABASE_URL

COPY . .

RUN npm install
RUN DATABASE_URL=$DATABASE_URL npx prisma generate
RUN DATABASE_URL=$DATABASE_URL npm run build
RUN npm install -g pnpm && \
pnpm install && \
pnpm add sharp && \
pnpm run build && \
DATABASE_URL=$DATABASE_URL pnpm dlx prisma generate

EXPOSE 3000

CMD ["npm", "run", "start"]

FROM node:20-alpine AS run

RUN mkdir /.npm && chown -R 1001:1001 /.npm

USER 1001:1001
WORKDIR /usr/src/app

COPY --from=build --chown=1001:1001 usr/src/app/.next/standalone ./
COPY --from=build --chown=1001:1001 usr/src/app/.next/static ./.next/static
COPY --from=build --chown=1001:1001 usr/src/app/public ./public

ENV NODE_ENV production
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

CMD [ "node", "server.js" ]
13 changes: 8 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: '3.5'
services:
app:
build: .
build:
context: .
dockerfile: Dockerfile.prod
args:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/cms?schema=public
container_name: cms-docker
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/cms?schema=public
Expand All @@ -10,15 +13,15 @@ services:
- '3000:3000'
- '5555:5555'
volumes:
- .:/usr/src/app
# - .:/usr/src/app
- /usr/src/app/.next
- /usr/src/app/node_modules
depends_on:
db:
condition: service_healthy

db:
image: postgres:9.6
image: postgres:alpine
container_name: db
restart: always
environment:
Expand All @@ -36,4 +39,4 @@ services:
retries: 5

volumes:
postgres-data:
postgres-data:
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const nextConfig = {
}
return config;
},
output: 'standalone',
};

module.exports = nextConfig;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@tabler/icons-react": "^3.14.0",
"@types/bcrypt": "^5.0.2",
"@types/jsonwebtoken": "^9.0.5",
"@uiw/react-markdown-preview": "^5.1.3",
"@uiw/react-md-editor": "^4.0.4",
"axios": "^1.6.2",
"bcrypt": "^5.1.1",
Expand All @@ -71,6 +72,7 @@
"ioredis": "^5.4.1",
"jose": "^5.2.2",
"jsonwebtoken": "^9.0.2",
"katex": "^0.16.11",
"lucide-react": "^0.321.0",
"moment": "^2.30.1",
"next": "14.0.2",
Expand All @@ -80,6 +82,7 @@
"node-fetch": "^3.3.2",
"notion-client": "^6.16.0",
"pdf-lib": "^1.17.1",
"prismjs": "^1.29.0",
"qs": "^6.13.0",
"react": "^18",
"react-big-calendar": "^1.13.2",
Expand Down
121 changes: 114 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7b43955

Please sign in to comment.