GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SpaceWorks-Inventory/Dockerfile at main · SpaceWorks-Labs/SpaceWorks-Inventory

Expand file tree

/

Dockerfile

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
196 lines (172 loc) · 9.39 KB
/

Dockerfile

Copy path

File metadata and controls

196 lines (172 loc) · 9.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# syntax=docker/dockerfile:1
# check=skip=SecretsUsedInArgOrEnv
# (The skipped check flags the NEXT_SERVER_ACTIONS_ENCRYPTION_KEY build-arg
# fallback in the builder stage; see the comment there for the tradeoff.)
# Stage 1: Install dependencies
FROM node:22-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json .npmrc ./
COPY frontend/package.json ./frontend/package.json
# `npm ci` runs the Prisma postinstall hook, which needs the schema available.
COPY prisma/schema.prisma ./prisma/schema.prisma
RUN npm ci
# A small migration-only target for platforms with a separate migration job. Releases
# migrate with the backend image's `migrate` role instead.
# scripts/prisma.mjs defaults DIRECT_URL to DATABASE_URL when it is unset.
FROM deps AS migrator
WORKDIR /app
COPY prisma ./prisma
COPY scripts/prisma.mjs ./scripts/prisma.mjs
CMD ["node", "scripts/prisma.mjs", "migrate", "deploy"]
# Prisma CLI only, pinned to the lockfile's version, so the runner can apply
# migrations on start (MIGRATE_ON_START=1) on platforms without a release job,
# such as the Render free plan. Kept apart from the app's node_modules.
FROM node:22-alpine AS prisma-cli
WORKDIR /opt/prisma-cli
COPY --from=deps /app/node_modules/prisma/package.json /tmp/prisma-package.json
COPY package.json /tmp/application-package.json
# Keep the isolated migration CLI's transitive security pins aligned with the app.
# Copy only dependency overrides; application scripts/workspaces do not run here.
RUN node -e 'const fs=require("node:fs"),p=require("/tmp/application-package.json");fs.writeFileSync("package.json",JSON.stringify({private:true,overrides:p.overrides||{}}))' \
&& npm install --omit=dev --no-save --no-audit --no-fund \
"prisma@$(node -p "require('/tmp/prisma-package.json').version")" \
&& npm cache clean --force
# Clients the VPS operator tools (docker/vps/*.mjs) import, pinned to the
# lockfile's versions. The application bundles its own copies into its build.
FROM node:22-alpine AS ops-modules
WORKDIR /opt/ops
COPY --from=deps /app/node_modules/ioredis/package.json /tmp/ioredis-package.json
COPY --from=deps /app/node_modules/@aws-sdk/client-s3/package.json /tmp/s3-package.json
COPY --from=deps /app/node_modules/nodemailer/package.json /tmp/nodemailer-package.json
COPY --from=deps /app/node_modules/bullmq/package.json /tmp/bullmq-package.json
RUN npm install --omit=dev --no-save --no-audit --no-fund \
"ioredis@$(node -p "require('/tmp/ioredis-package.json').version")" \
"@aws-sdk/client-s3@$(node -p "require('/tmp/s3-package.json').version")" \
"nodemailer@$(node -p "require('/tmp/nodemailer-package.json').version")" \
"bullmq@$(node -p "require('/tmp/bullmq-package.json').version")" \
&& npm cache clean --force
# Stage 2: Rebuild the source code
FROM node:22-alpine AS builder
WORKDIR /app
ARG NEXT_PUBLIC_BASE_URL
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
# Fallback for builders without BuildKit secrets wired up. Render passes every
# service environment variable to `docker build` as a build arg of the same
# name, so the runtime key is reused for the build without extra setup. The
# value then exists in this builder stage's metadata and build cache, but not
# in the final runner image (a separate stage). Prefer the secret mount below
# wherever the builder supports it (local Docker, GitHub Actions, Compose).
ARG NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
# This stage starts fresh; avoid writing a compiler cache that the runner never uses.
ENV SWI_DISABLE_BUILD_CACHE=1
ENV NODE_OPTIONS=--max-old-space-size=4096
RUN npx prisma generate && npm run build:jobs
# The key is consumed by Next.js while compiling Server Actions. Every image
# replica must be built with one stable key and receive that same key at runtime.
# A BuildKit secret (`--secret id=NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,...`, or a
# Render secret file with that name) takes precedence over the build arg.
RUN --mount=type=secret,id=NEXT_SERVER_ACTIONS_ENCRYPTION_KEY \
if [ -s /run/secrets/NEXT_SERVER_ACTIONS_ENCRYPTION_KEY ]; then \
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY="$(cat /run/secrets/NEXT_SERVER_ACTIONS_ENCRYPTION_KEY)"; \
fi; \
if [ -z "$NEXT_SERVER_ACTIONS_ENCRYPTION_KEY" ]; then \
echo "NEXT_SERVER_ACTIONS_ENCRYPTION_KEY is required: pass it as a BuildKit secret or build arg." >&2; \
exit 1; \
fi; \
export NEXT_SERVER_ACTIONS_ENCRYPTION_KEY; \
npm run build
# The separately deployable rendering frontend (the frontend/ npm workspace),
# published as spaceworks-inventory-frontend. It holds no database, mail, Redis or
# storage client and reaches the backend only through the authenticated gateway.
FROM node:22-alpine AS frontend-builder
WORKDIR /app
ARG NEXT_PUBLIC_BASE_URL
ARG NEXT_PUBLIC_BACKEND_ORIGIN
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
ENV NEXT_PUBLIC_BACKEND_ORIGIN=$NEXT_PUBLIC_BACKEND_ORIGIN
ENV BACKEND_ORIGIN=$NEXT_PUBLIC_BACKEND_ORIGIN
ARG NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
COPY --from=deps /app ./
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
ENV SWI_DISABLE_BUILD_CACHE=1
ENV NODE_OPTIONS=--max-old-space-size=4096
ENV SWI_FRONTEND_STANDALONE=1
RUN npx prisma generate
RUN --mount=type=secret,id=NEXT_SERVER_ACTIONS_ENCRYPTION_KEY \
if [ -s /run/secrets/NEXT_SERVER_ACTIONS_ENCRYPTION_KEY ]; then \
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY="$(cat /run/secrets/NEXT_SERVER_ACTIONS_ENCRYPTION_KEY)"; \
fi; \
if [ -z "$NEXT_SERVER_ACTIONS_ENCRYPTION_KEY" ]; then \
echo "NEXT_SERVER_ACTIONS_ENCRYPTION_KEY is required: pass it as a BuildKit secret or build arg." >&2; \
exit 1; \
fi; \
export NEXT_SERVER_ACTIONS_ENCRYPTION_KEY; \
npm run build:frontend
FROM node:22-alpine AS frontend
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
# Standalone output for a space keeps its path below the repository root.
COPY --from=frontend-builder --chown=nextjs:nodejs /app/frontend/.next/standalone ./
COPY --from=frontend-builder --chown=nextjs:nodejs /app/frontend/.next/static ./frontend/.next/static
COPY --from=frontend-builder --chown=nextjs:nodejs /app/frontend/public ./frontend/public
COPY --chmod=755 scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN rm -f frontend/.env frontend/.env.local frontend/.env.production .env
# Runtime roles execute Node directly; dependency installation stays in build stages.
RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Where docker-entrypoint.sh finds the build to apply the public origins to.
ENV SWI_NEXT_DIR=/app/frontend/.next
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 CMD node -e "fetch('http://127.0.0.1:' + (process.env.PORT || 3000) + '/brand/icon-192.png').then((response) => process.exit(response.ok ? 0 : 1)).catch(() => process.exit(1))"
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "frontend/server.js"]
# Stage 3: Production runner, published as spaceworks-inventory-backend (keep this
# the LAST stage: Render builds the final stage because a Blueprint cannot
# select a build target). The same image applies migrations (`migrate`) and
# runs the VPS operator tools (scripts/, docker/vps/) as root.
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Sharp renders images and previews on the server. Alpine needs fonts for text.
# OpenSSL creates the VPS's private CA and service certificates (ops role).
RUN apk add --no-cache font-dejavu fontconfig openssl && fc-cache -f
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Leverage Next.js standalone 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/dist ./dist
# Prisma CLI for the optional MIGRATE_ON_START=1 path (root-owned, read-only).
COPY --from=prisma-cli /opt/prisma-cli/node_modules /opt/prisma-cli/node_modules
COPY --chmod=755 scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Operator sources stay readable when the installer uses private file modes.
# Tools needing configuration writes still run through the root operator role.
COPY --chown=nextjs:nodejs scripts/*.mjs ./scripts/
COPY --chown=nextjs:nodejs docker/vps ./docker/vps
COPY --from=ops-modules /opt/ops/node_modules ./docker/vps/node_modules
# Next's standalone trace may include dotenv files when a build is performed
# from a developer checkout. Secrets belong only in the runtime environment.
RUN rm -f .env .env.local .env.production .env.development
# Migrations use the isolated Prisma CLI through Node, without a package manager.
RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 CMD node -e "fetch('http://127.0.0.1:' + (process.env.PORT || 3000) + '/api/health').then((response) => process.exit(response.ok ? 0 : 1)).catch(() => process.exit(1))"
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "server.js"]
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.