-
-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implemented docker support for nextjs app #255
base: main
Are you sure you want to change the base?
Changes from all commits
3588b78
3a9ad4d
968d995
03967d0
15ab276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.env | ||
|
||
Dockerfile | ||
./**/*/Dockerfile | ||
|
||
.dockerignore | ||
|
||
node_modules | ||
./**/*/node_modules | ||
|
||
pnpm-debug.log | ||
./**/*/pnpm-debug.log | ||
|
||
|
||
README.md | ||
.next | ||
.git | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18 | ||
18.15.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
##### DEPENDENCIES | ||
|
||
FROM --platform=linux/amd64 node:18-alpine AS builder | ||
RUN apk add --no-cache libc6-compat openssl1.1-compat && apk update | ||
WORKDIR /app | ||
RUN yarn global add turbo | ||
COPY . . | ||
RUN turbo prune --scope=@acme/nextjs --docker | ||
|
||
FROM --platform=linux/amd64 node:18-alpine AS installer | ||
RUN apk add --no-cache libc6-compat openssl1.1-compat && apk update | ||
WORKDIR /app | ||
|
||
ENV NODE_ENV production | ||
ENV CI true | ||
ENV SKIP_ENV_VALIDATION true | ||
|
||
COPY .gitignore .gitignore | ||
COPY --from=builder /app/tsconfig.json ./tsconfig.json | ||
COPY --from=builder /app/out/json . | ||
COPY --from=builder /app/out/pnpm-lock.yaml\* ./ | ||
|
||
RUN yarn global add pnpm && pnpm fetch --prod && pnpm install -r --offline --prod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why mix with yarn and pnpm ?? |
||
|
||
|
||
COPY --from=builder /app/out/full . | ||
|
||
|
||
|
||
RUN pnpm turbo build --filter=nextjs | ||
|
||
FROM --platform=linux/amd64 node:18-alpine AS runner | ||
RUN apk add --no-cache libc6-compat openssl1.1-compat && apk update | ||
WORKDIR /app | ||
|
||
# Don't run production as root | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
USER nextjs | ||
EXPOSE 3000 | ||
ENV PORT 3000 | ||
|
||
ENV NODE_ENV production | ||
|
||
# ENV NEXT_TELEMETRY_DISABLED 1 Optional | ||
|
||
COPY --from=installer /app/apps/nextjs/next.config.mjs ./ | ||
COPY --from=installer /app/apps/nextjs/package.json ./ | ||
|
||
COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/standalone ./ | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/static ./apps/nextjs/.next/static | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/public ./apps/nextjs/public | ||
|
||
|
||
CMD node apps/nextjs/server.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,18 +27,17 @@ | |
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"superjson": "1.9.1", | ||
"@types/node": "^18.15.11", | ||
"@types/react": "^18.0.31", | ||
"tailwindcss": "^3.3.1", | ||
"postcss": "^8.4.21", | ||
"autoprefixer": "^10.4.14", | ||
Comment on lines
+30
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im no docker expert but why do these need to be production deps all of a sudden? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when you run |
||
"zod": "^3.21.4" | ||
}, | ||
"devDependencies": { | ||
"@acme/eslint-config": "^0.1.0", | ||
"@types/node": "^18.15.11", | ||
"@types/react": "^18.0.31", | ||
"@types/react-dom": "^18.0.11", | ||
"autoprefixer": "^10.4.14", | ||
"dotenv-cli": "^7.1.0", | ||
"eslint": "^8.37.0", | ||
"postcss": "^8.4.21", | ||
"tailwindcss": "^3.3.1", | ||
"typescript": "^5.0.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: "3.7" | ||
|
||
services: | ||
nextjs: | ||
ports: | ||
- "3000:3000" | ||
build: | ||
context: . | ||
dockerfile: ./apps/nextjs/Dockerfile | ||
environment: | ||
- DATABASE_URL=${DATABASE_URL} | ||
- NEXTAUTH_URL=${NEXTAUTH_URL} | ||
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET} | ||
- DISCORD_CLIENT_ID=${DISCORD_CLIENT_ID} | ||
- DISCORD_CLIENT_SECRET=${DISCORD_CLIENT_SECRET} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,11 @@ | |
"with-env": "dotenv -e ../../.env --" | ||
}, | ||
"dependencies": { | ||
"prisma": "^4.12.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the turbo.json we declare that before build it should run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend leaving the devDependencies and prod dependencies as they are, but limit the number of packages installed with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as you're using |
||
"@prisma/client": "^4.12.0" | ||
}, | ||
"devDependencies": { | ||
"dotenv-cli": "^7.1.0", | ||
"prisma": "^4.12.0", | ||
"typescript": "^5.0.3" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not work it on /app/out/tsconfig.ts not in /app/tsconfig.ts i get error as not found when i try run at in server