-
-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathDockerfile
More file actions
109 lines (85 loc) · 4.04 KB
/
Copy pathDockerfile
File metadata and controls
109 lines (85 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
ARG NODEJS_IMAGE=node:24-bookworm-slim
FROM --platform=$BUILDPLATFORM $NODEJS_IMAGE AS base
# Install dependencies only when needed
FROM base AS deps
# RUN apt update && apt install libc6-compat
WORKDIR /app
# Install Prisma Client - remove if not using Prisma
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
COPY prisma ./
RUN npx prisma@6.16.3 generate
# Install dependencies based on the preferred package manager
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM base AS builder
ARG NEXT_PUBLIC_APP_VERSION
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN SKIP_ENV_VALIDATION=1 npm run build
# Copy the ztmkworld binary based on the target platform architecture
FROM base AS ztmkworld_builder
ARG TARGETPLATFORM
WORKDIR /app
COPY ztnodeid/build/linux_amd64/ztmkworld ztmkworld_amd64
COPY ztnodeid/build/linux_arm64/ztmkworld ztmkworld_arm64
RUN \
case "${TARGETPLATFORM}" in \
"linux/amd64") cp ztmkworld_amd64 /usr/local/bin/ztmkworld ;; \
"linux/arm64") cp ztmkworld_arm64 /usr/local/bin/ztmkworld ;; \
*) echo "Unsupported architecture" && exit 1 ;; \
esac && \
chmod +x /usr/local/bin/ztmkworld
# Production image, copy all the files and run next
FROM $NODEJS_IMAGE AS runner
WORKDIR /app
# set the app version as an environment variable. Used in the github action
# used in the init-db.sh script
ARG NEXTAUTH_URL
ARG NEXTAUTH_SECRET
ARG NEXT_PUBLIC_APP_VERSION
ENV NEXT_PUBLIC_APP_VERSION=${NEXT_PUBLIC_APP_VERSION}
ENV NODE_ENV=production
# Disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Install PostgreSQL client tools for every supported server major version from
# the official apt.postgresql.org repo, so the built-in backup feature can pick
# a pg_dump that matches the connected server (see issue #957).
RUN apt update && apt install -y curl sudo ca-certificates && \
install -d /usr/share/postgresql-common/pgdg && \
curl --fail -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc && \
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(. /etc/os-release && echo "$VERSION_CODENAME")-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
apt update && \
apt install -y postgresql-client-15 postgresql-client-16 postgresql-client-17 postgresql-client-18 && \
apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Update npm to latest version to suppress update notices
RUN npm install -g npm@latest
# need to install these package for seeding the database
RUN npm install @prisma/client@6.16.3 @paralleldrive/cuid2
RUN npm install -g prisma@6.16.3 ts-node
RUN mkdir -p /var/lib/zerotier-one && chown -R nextjs:nodejs /var/lib/zerotier-one && chmod -R 777 /var/lib/zerotier-one
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/init-db.sh ./init-db.sh
COPY --from=ztmkworld_builder /usr/local/bin/ztmkworld /usr/local/bin/ztmkworld
# prepeare .env file for the init-db.sh script
RUN touch .env && chown nextjs:nodejs .env
RUN chmod u+x init-db.sh
# USER nextjs
EXPOSE 3000
ENV PORT=3000
ENTRYPOINT ["/app/init-db.sh"]
CMD ["node", "server.js"]