Skip to content

Commit c0b151c

Browse files
committed
refactor: docker compatibility with single instance next application
1 parent deb742f commit c0b151c

File tree

2 files changed

+26
-44
lines changed

2 files changed

+26
-44
lines changed

src/Dockerfile

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,21 @@
1-
FROM node:17-alpine AS deps
1+
FROM node:18-alpine AS builder
22

33
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
44
RUN apk add --no-cache libc6-compat
55

66
WORKDIR /app
77

8-
COPY package.json yarn.lock ./
9-
10-
RUN yarn install --frozen-lockfile
11-
12-
FROM node:17-alpine AS builder
13-
14-
WORKDIR /app
15-
16-
COPY --from=deps /app/node_modules ./node_modules
178
COPY . .
189

19-
ARG API_URL
20-
21-
ENV NEXT_TELEMETRY_DISABLED=1
22-
ENV API_URL=${API_URL:-http://localhost:3000}
23-
24-
RUN yarn build
10+
RUN corepack enable && corepack prepare pnpm@latest --activate
11+
RUN pnpm install --frozen-lockfile
2512

26-
FROM node:17-alpine AS runner
27-
28-
WORKDIR /app
29-
30-
ARG NODE_ENV
13+
ARG DATABASE_URL
3114

3215
ENV NEXT_TELEMETRY_DISABLED=1
33-
ENV NODE_ENV=${NODE_ENV:-production}
34-
35-
RUN addgroup --system --gid 1001 nodejs
36-
RUN adduser --system --uid 1001 nextjs
37-
38-
COPY --from=builder /app/next.config.mjs ./
39-
COPY --from=builder /app/public ./public
40-
COPY --from=builder /app/package.json ./package.json
41-
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
42-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
43-
44-
USER nextjs
45-
46-
ENV PORT=3001
16+
ENV DATABASE_URL=${DATABASE_URL}
17+
ENV DRIFT_URL=${DRIFT_URL:-http://localhost:3000}
4718

48-
EXPOSE 3001
19+
RUN pnpm prisma && pnpm build
4920

50-
CMD ["node", "server.js"]
21+
CMD pnpm start

src/docker-compose.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,44 @@ services:
22
drift:
33
build:
44
context: ./
5+
dockerfile: Dockerfile
6+
args:
7+
- DATABASE_URL=postgressql://maxleiter:wHaQdWJcZz2pWd0@localhost:5432/postgres
58
container_name: drift
69
restart: unless-stopped
710
user: 1000:1000
811
environment:
9-
- WELCOME_CONTENT="## Drift is a self-hostable clone of GitHub Gist. \nIt is a simple way to share code and text snippets with your friends, with support for the following:\n \n - Render GitHub Extended Markdown (including images)\n - User authentication\n - Private, public, and password protected posts\n - Markdown is rendered and stored on the server\n - Syntax highlighting and automatic language detection\n - Drag-and-drop file uploading\n\n If you want to signup, you can join at [/signup](/signup) as long as you have a passcode provided by the administrator (which you don\'t need for this demo). **This demo is on a memory-only database, so accounts and pastes can be deleted at any time.** \n\nYou can find the source code on [GitHub](https://github.com/MaxLeiter/drift)."
10-
- WELCOME_TITLE="Drift"
11-
- REGISTRATION_PASSWORD=""
12+
- WELCOME_CONTENT=## Drift is a self-hostable clone of GitHub Gist. \nIt is a simple way to share code and text snippets with your friends, with support for the following:\n \n - Render GitHub Extended Markdown (including images)\n - User authentication\n - Private, public, and password protected posts\n - Markdown is rendered and stored on the server\n - Syntax highlighting and automatic language detection\n - Drag-and-drop file uploading\n\n If you want to signup, you can join at [/signup](/signup) as long as you have a passcode provided by the administrator (which you don\'t need for this demo). **This demo is on a memory-only database, so accounts and pastes can be deleted at any time.** \n\nYou can find the source code on [GitHub](https://github.com/MaxLeiter/drift).
13+
- WELCOME_TITLE=Drift
14+
- REGISTRATION_PASSWORD=
1215
- NEXTAUTH_URL=http://localhost:3000
1316
- NEXTAUTH_SECRET=secret
1417
- GITHUB_CLIENT_ID=64100c941c2474a5698a
1518
- GITHUB_CLIENT_SECRET=cf4c1d510741a439c77d0593e36469d234eca894
16-
- DATABASE_URL=postgressql://maxleiter:wHaQdWJcZz2pWd0@postgres:5432/postgres
1719
- DRIFT_URL=http://localhost:3000
1820
ports:
1921
- "3000:3000"
20-
volumes:
21-
- ./drift:/app
22+
networks:
23+
- drift_network
2224
depends_on:
2325
- postgres
26+
2427
postgres:
25-
image: postgres:13
28+
image: postgres:15
2629
container_name: postgres
2730
restart: unless-stopped
2831
user: 1000:1000
2932
environment:
3033
- POSTGRES_PASSWORD=wHaQdWJcZz2pWd0
3134
- POSTGRES_USER=maxleiter
3235
- POSTGRES_DB=postgres
36+
ports:
37+
- 5432:5432
3338
volumes:
3439
- ./postgres:/var/lib/postgresql/data
40+
networks:
41+
- drift_network
42+
43+
networks:
44+
drift_network:
45+
external: true

0 commit comments

Comments
 (0)