Skip to content

Commit cfa97b7

Browse files
maxproskendom91
andauthored
chore(examples): migrate to docker-compose v2 and cleanup Dockerfile example (#11040)
Co-authored-by: Nico Domino <[email protected]>
1 parent a858656 commit cfa97b7

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

apps/examples/nextjs/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
FROM node:20-alpine AS base
23

34
# Install dependencies only when needed
@@ -7,9 +8,8 @@ RUN apk add --no-cache libc6-compat
78
WORKDIR /app
89

910
# Install dependencies
10-
COPY package.json pnpm-lock.yaml ./
11-
RUN corepack enable && pnpm install
12-
11+
COPY package.json pnpm-lock.yaml* ./
12+
RUN corepack enable pnpm && pnpm i --frozen-lockfile
1313

1414
# Rebuild the source code only when needed
1515
FROM base AS builder
@@ -22,7 +22,7 @@ COPY . .
2222
# Uncomment the following line in case you want to disable telemetry during the build.
2323
# ENV NEXT_TELEMETRY_DISABLED 1
2424

25-
RUN npm run build
25+
RUN corepack enable pnpm && pnpm build
2626

2727
# Production image, copy all the files and run next
2828
FROM base AS runner
@@ -51,7 +51,8 @@ USER nextjs
5151
EXPOSE 3000
5252

5353
ENV PORT 3000
54+
ENV HOSTNAME "0.0.0.0"
5455

5556
# server.js is created by next build from the standalone output
5657
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
57-
CMD HOSTNAME="0.0.0.0" node server.js
58+
CMD ["node", "server.js"]
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
version: "3"
2-
31
services:
42
authjs-docker-test:
3+
build: .
54
environment:
65
- TEST_KEYCLOAK_USERNAME
76
- TEST_KEYCLOAK_PASSWORD
@@ -10,8 +9,5 @@ services:
109
- AUTH_KEYCLOAK_ISSUER
1110
- AUTH_SECRET="MohY0/2zSQw/psWEnejC2ka3Al0oifvY4YjOkUaFfnI="
1211
- AUTH_URL=http://localhost:3000/auth
13-
build:
14-
context: .
15-
dockerfile: Dockerfile
1612
ports:
1713
- "3000:3000"

apps/examples/nextjs/test-docker.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Easier to read `docker-compose up` output
3+
# Easier to read `docker compose up` output
44
# export BUILDKIT_PROGRESS=plain
55

66
args=("-f" "docker-compose.yml")
@@ -9,9 +9,9 @@ if [[ -z "${CI}" ]]; then
99
fi
1010
args+=("up" "--detach" "--build")
1111

12-
echo "Running: docker-compose ${args[*]}"
12+
echo "Running: docker compose ${args[*]}"
1313

14-
if ! docker-compose "${args[@]}"; then
14+
if ! docker compose "${args[@]}"; then
1515
echo "Failed to start container"
1616
exit 1
1717
fi
@@ -24,7 +24,7 @@ export TEST_DOCKER=1
2424

2525
# Always stop container, but exit with 1 when tests are failing
2626
if playwright test -c ../../../packages/utils/playwright.config.ts; then
27-
docker-compose down
27+
docker compose down
2828
else
29-
docker-compose down && exit 1
29+
docker compose down && exit 1
3030
fi

docs/pages/getting-started/deployment.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ In a Docker environment, make sure to set either `trustHost: true` in your Auth.
106106
Our example application is also hosted via Docker [here](https://nextjs-docker-example.authjs.dev) (see the [source code](https://github.com/nextauthjs/next-auth-example)). Below is an example `Dockerfile` for a Next.js application using Auth.js.
107107

108108
```docker filename="Dockerfile"
109+
# syntax=docker/dockerfile:1
109110
FROM node:20-alpine AS base
110111
111112
# Install dependencies only when needed
@@ -115,9 +116,8 @@ RUN apk add --no-cache libc6-compat
115116
WORKDIR /app
116117
117118
# Install dependencies
118-
COPY package.json ./
119-
RUN npm i
120-
119+
COPY package.json pnpm-lock.yaml* ./
120+
RUN corepack enable pnpm && pnpm i --frozen-lockfile
121121
122122
# Rebuild the source code only when needed
123123
FROM base AS builder
@@ -130,9 +130,10 @@ COPY . .
130130
# Uncomment the following line in case you want to disable telemetry during the build.
131131
# ENV NEXT_TELEMETRY_DISABLED 1
132132
133-
# This should be replaced with an actual secret in production.
134-
# REVIEW: Can we make this not required during build?
135-
RUN AUTH_SECRET=dummy npm run build
133+
ARG AUTH_SECRET
134+
ENV AUTH_SECRET $AUTH_SECRET
135+
136+
RUN corepack enable pnpm && pnpm build
136137
137138
# Production image, copy all the files and run next
138139
FROM base AS runner
@@ -161,10 +162,11 @@ USER nextjs
161162
EXPOSE 3000
162163
163164
ENV PORT 3000
165+
ENV HOSTNAME "0.0.0.0"
164166
165167
# server.js is created by next build from the standalone output
166168
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
167-
CMD HOSTNAME="0.0.0.0" node server.js
169+
CMD ["node", "server.js"]
168170
```
169171

170172
## Securing a preview deployment

packages/adapter-upstash-redis/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3"
21
services:
32
redis:
43
image: redis

0 commit comments

Comments
 (0)