Skip to content

Commit 109c526

Browse files
authored
Merge pull request #680 from geekyharsh05/feat/multistage-docker
feat: add multistage Dockerfile for reduced image size.
2 parents 4471183 + e78589c commit 109c526

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

Dockerfile.prod

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
1-
FROM node:20-alpine
2-
ARG DATABASE_URL
1+
FROM node:20-alpine AS base
32

3+
FROM base AS deps
44
RUN set -ex; \
55
apk update; \
66
apk add --no-cache \
7+
libc6-compat \
78
openssl
89

910
WORKDIR /usr/src/app
1011

12+
COPY package.json yarn.lock* ./
13+
COPY apps/web/package.json ./apps/web/
14+
COPY packages/ ./packages/
15+
16+
RUN yarn install --ignore-scripts
17+
18+
FROM base AS builder
19+
WORKDIR /usr/src/app
20+
21+
COPY --from=deps /usr/src/app/node_modules ./node_modules
1122
COPY . .
1223

13-
RUN yarn
14-
RUN cd packages/db && DATABASE_URL=$DATABASE_URL npx [email protected] generate && cd ../..
15-
## put DATABASE_URL in apps/web/.env
16-
RUN echo DATABASE_URL=$DATABASE_URL >> apps/web/.env
17-
RUN DATABASE_URL=$DATABASE_URL yarn build
18-
## Remove .env file
19-
RUN rm apps/web/.env
24+
RUN yarn global add turbo@^2.1.1
25+
RUN DATABASE_URL=$DATABASE_URL npx [email protected] generate --schema packages/db/prisma/schema.prisma
26+
27+
RUN cd apps/web && yarn add sharp
28+
RUN yarn turbo run build --filter=web...
29+
30+
FROM base AS runner
31+
WORKDIR /usr/src/app
32+
33+
RUN addgroup --system --gid 1001 nodejs
34+
RUN adduser --system --uid 1001 nextjs
35+
36+
RUN mkdir .next && chown nextjs:nodejs .next
37+
38+
USER nextjs
39+
40+
COPY --from=builder --chown=nextjs:nodejs /usr/src/app/apps/web/.next/standalone ./
41+
COPY --from=builder --chown=nextjs:nodejs /usr/src/app/apps/web/.next/static ./apps/web/.next/static
42+
COPY --from=builder --chown=nextjs:nodejs /usr/src/app/apps/web/public ./apps/web/public
2043

2144
EXPOSE 3000
45+
ENV NODE_ENV production
46+
ENV PORT 3000
47+
ENV HOSTNAME "0.0.0.0"
2248

23-
CMD ["yarn", "start"]
49+
CMD ["node", "apps/web/server.js"]

apps/web/next.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ module.exports = {
2525

2626
transpilePackages: ["@repo/ui", "@repo/common", "@repo/recoil"],
2727
images: {
28-
domains: ["d2szwvl7yo497w.cloudfront.net", "appx-wsb-gcp.akamai.net.in"], // Add your domain here
28+
remotePatterns: [
29+
{
30+
protocol: 'https',
31+
hostname: 'd2szwvl7yo497w.cloudfront.net',
32+
pathname: '**',
33+
},
34+
{
35+
protocol: 'https',
36+
hostname: 'appx-wsb-gcp.akamai.net.in',
37+
pathname: '**',
38+
},
39+
],
2940
},
41+
output: "standalone",
3042
};

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@radix-ui/react-slot": "^1.0.2",
1919
"@repo/db": "*",
2020
"@repo/ui": "*",
21+
"@repo/store": "*",
2122
"class-variance-authority": "^0.7.0",
2223
"clsx": "^2.1.0",
2324
"date-fns": "^3.6.0",

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
services:
22
app:
3-
build: .
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
46
container_name: daily-code-docker
57
environment:
68
- DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres

0 commit comments

Comments
 (0)