Files

156 lines
6.2 KiB
Docker
Raw Permalink Normal View History

2025-10-01 15:40:10 -05:00
# Stage 1: Install dependencies
2026-10-04 15:50:49 -05:00
# The builders only produce JS, so they run on the build machine's own arch
# once instead of under QEMU per target. Rolldown hangs under arm64 emulation.
2026-10-10 14:58:27 -05:00
FROM --platform=$BUILDPLATFORM node:24-slim AS deps
2025-08-07 02:20:27 -05:00
WORKDIR /app
+7
2025-11-05 10:36:16 -06:00
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
2025-08-07 02:20:27 -05:00
COPY package*.json ./
2026-10-01 16:20:16 -05:00
COPY packages/plugin-sdk/package.json ./packages/plugin-sdk/package.json
2026-05-06 15:12:07 -05:00
COPY .npmrc ./
COPY vendor ./vendor
2025-08-07 02:20:27 -05:00
2026-10-01 16:20:16 -05:00
COPY scripts/patch-ssh2-agent.cjs ./scripts/
2026-06-04 15:16:53 -04:00
2026-05-06 15:12:07 -05:00
RUN npm ci --ignore-scripts && \
+17
2026-09-20 14:56:39 -05:00
node scripts/patch-ssh2-agent.cjs && \
2025-08-07 02:20:27 -05:00
npm cache clean --force
# Stage 2: Build frontend
FROM deps AS frontend-builder
WORKDIR /app
COPY . .
2025-10-01 15:40:10 -05:00
RUN find public/fonts -name "*.ttf" ! -name "*Regular.ttf" ! -name "*Bold.ttf" ! -name "*Italic.ttf" -delete
2025-08-07 02:20:27 -05:00
2025-10-01 15:40:10 -05:00
RUN npm cache clean --force && \
TERMIX_RUNTIME_BASE_PATH=true NODE_OPTIONS="--max-old-space-size=3072" npm run build
2025-10-01 15:40:10 -05:00
# Stage 3: Build backend
2025-08-07 02:20:27 -05:00
FROM deps AS backend-builder
WORKDIR /app
COPY . .
2026-10-22 13:30:48 -05:00
RUN npm run build:backend:core
# Stage 3b: Stage the bundled plugins for one profile (minimal, standard or
# full, see docker/bundled-plugins.json). Only this stage and the final one
# differ between profiles, so the other stages are built once.
FROM deps AS plugins
WORKDIR /app
ARG PLUGIN_PROFILE=standard
COPY scripts/build-plugins.cjs ./scripts/build-plugins.cjs
COPY scripts/lib/bundled-plugins.cjs ./scripts/lib/bundled-plugins.cjs
COPY docker/bundled-plugins.json ./docker/bundled-plugins.json
2026-10-12 11:35:48 -05:00
# Bundled plugin downloads show in the plugin store, so keep them between builds.
RUN --mount=type=cache,target=/app/node_modules/.cache/termix-bundled-plugins \
2026-10-22 13:30:48 -05:00
node scripts/build-plugins.cjs --profile "$PLUGIN_PROFILE"
2025-08-07 02:20:27 -05:00
+5
2026-08-19 14:12:06 -05:00
# Stage 4: Download OPKSSH binary for the target platform so the image works offline
2026-10-10 14:58:27 -05:00
FROM node:24-slim AS opkssh-downloader
+5
2026-08-19 14:12:06 -05:00
ARG TARGETARCH
ARG OPKSSH_VERSION=v0.16.0
+17
2026-09-20 14:56:39 -05:00
ARG OPKSSH_SHA256_AMD64=c018c3e7baf98612b923e742dd87be38650bf61e3b755fb2bc90de177568b1bf
ARG OPKSSH_SHA256_ARM64=9dd10c2b6ce99cde18e52c054877ca014134b291fd82afe71741c68db4f83d44
+5
2026-08-19 14:12:06 -05:00
WORKDIR /opkssh
RUN apt-get update && apt-get install -y curl ca-certificates && rm -rf /var/lib/apt/lists/*
RUN case "$TARGETARCH" in \
+17
2026-09-20 14:56:39 -05:00
amd64) OPKSSH_ARCH=amd64; OPKSSH_SHA256="$OPKSSH_SHA256_AMD64" ;; \
arm64) OPKSSH_ARCH=arm64; OPKSSH_SHA256="$OPKSSH_SHA256_ARM64" ;; \
+5
2026-08-19 14:12:06 -05:00
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
esac && \
curl -fSL -o "opkssh-linux-${OPKSSH_ARCH}" \
"https://github.com/openpubkey/opkssh/releases/download/${OPKSSH_VERSION}/opkssh-linux-${OPKSSH_ARCH}" && \
+17
2026-09-20 14:56:39 -05:00
echo "$OPKSSH_SHA256 opkssh-linux-${OPKSSH_ARCH}" | sha256sum -c - && \
+5
2026-08-19 14:12:06 -05:00
chmod 755 "opkssh-linux-${OPKSSH_ARCH}" && \
echo -n "$OPKSSH_VERSION" > version.txt
# Stage 5: Production dependencies only
2026-10-10 14:58:27 -05:00
FROM node:24-slim AS production-deps
2025-08-07 02:20:27 -05:00
WORKDIR /app
2025-10-01 15:40:10 -05:00
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
2025-08-07 02:20:27 -05:00
COPY package*.json ./
2026-10-01 16:20:16 -05:00
# The plugin SDK is a workspace package core imports at runtime, so npm ci
# has to see it to link it and install its dependencies.
COPY packages/plugin-sdk/package.json ./packages/plugin-sdk/package.json
2026-05-06 15:12:07 -05:00
COPY .npmrc ./
COPY vendor ./vendor
2025-08-07 02:20:27 -05:00
2026-10-10 14:58:27 -05:00
COPY scripts/patch-ssh2-agent.cjs ./scripts/
2026-06-04 15:16:53 -04:00
2026-10-18 00:34:50 -05:00
# ssh2's native crypto crashes Node 24 when a cipher is freed, so ssh2 uses
# OpenSSL instead (chacha20-poly1305 is then left out).
2026-05-06 15:12:07 -05:00
RUN npm ci --omit=dev --ignore-scripts && \
+17
2026-09-20 14:56:39 -05:00
node scripts/patch-ssh2-agent.cjs && \
2026-08-22 19:47:40 -05:00
rm -rf node_modules/better-sqlite3/prebuilds && \
npm run build-release --prefix node_modules/better-sqlite3 && \
test -f node_modules/better-sqlite3/build/Release/better_sqlite3.node && \
2026-10-18 00:34:50 -05:00
npm rebuild bcryptjs && \
rm -rf node_modules/ssh2/lib/protocol/crypto/build && \
2025-08-07 02:20:27 -05:00
npm cache clean --force
+5
2026-08-19 14:12:06 -05:00
# Stage 6: Final optimized image
2026-10-10 14:58:27 -05:00
FROM node:24-slim
2025-10-01 15:40:10 -05:00
WORKDIR /app
2026-10-01 16:20:16 -05:00
# The release the opkssh-downloader stage baked in, so the plugin trusts that
# binary when the build picks a version other than its pinned one.
ARG OPKSSH_VERSION=v0.16.0
ARG OPKSSH_SHA256_AMD64=c018c3e7baf98612b923e742dd87be38650bf61e3b755fb2bc90de177568b1bf
ARG OPKSSH_SHA256_ARM64=9dd10c2b6ce99cde18e52c054877ca014134b291fd82afe71741c68db4f83d44
2025-08-07 02:20:27 -05:00
2026-10-01 16:20:16 -05:00
ENV DATA_DIR=/app/data \
OPKSSH_BUNDLED_DIR=/app/opkssh-bundled \
OPKSSH_VERSION=$OPKSSH_VERSION \
OPKSSH_SHA256_AMD64=$OPKSSH_SHA256_AMD64 \
OPKSSH_SHA256_ARM64=$OPKSSH_SHA256_ARM64 \
PORT=8080 \
NODE_ENV=production
RUN apt-get update && apt-get install -y nginx gettext-base openssl ca-certificates gosu wget && \
+4
2026-02-12 22:28:13 -06:00
update-ca-certificates && \
2025-10-01 15:40:10 -05:00
rm -rf /var/lib/apt/lists/* && \
2026-10-01 16:20:16 -05:00
mkdir -p /app/data /app/uploads /app/nginx /tmp/nginx && \
2026-05-06 15:12:07 -05:00
chown -R node:node /app /tmp/nginx && \
2026-10-01 16:20:16 -05:00
chmod 755 /app/data /app/uploads /app/nginx /tmp/nginx
2025-08-07 02:20:27 -05:00
+1
2025-12-31 22:20:12 -06:00
COPY docker/nginx.conf /app/nginx/nginx.conf.template
COPY docker/nginx-https.conf /app/nginx/nginx-https.conf.template
2025-08-07 02:20:27 -05:00
+1
2025-12-31 22:20:12 -06:00
COPY --chown=node:node --from=frontend-builder /app/dist /app/html
2025-08-07 02:20:27 -05:00
2025-10-01 15:40:10 -05:00
COPY --chown=node:node --from=production-deps /app/node_modules /app/node_modules
COPY --chown=node:node --from=backend-builder /app/dist/backend ./dist/backend
2026-10-22 13:30:48 -05:00
# Plugins of the chosen profile pinned in docker/bundled-plugins.json, resolved
# as dist/plugins by getBundledPluginsDir().
COPY --chown=node:node --from=plugins /app/dist/plugins ./dist/plugins
2026-10-10 14:58:27 -05:00
# Target of node_modules/@termix-ssh/plugin-sdk, which core and the plugins import.
2026-10-01 16:20:16 -05:00
COPY --chown=node:node --from=backend-builder /app/packages/plugin-sdk/package.json ./packages/plugin-sdk/package.json
COPY --chown=node:node --from=backend-builder /app/packages/plugin-sdk/dist ./packages/plugin-sdk/dist
# Pre-baked OPKSSH binary. The opkssh plugin uses it when its checksum
# matches, so an offline install never downloads one.
+5
2026-08-19 14:12:06 -05:00
COPY --chown=node:node --from=opkssh-downloader /opkssh /app/opkssh-bundled
2025-10-01 15:40:10 -05:00
COPY --chown=node:node package.json ./
+3
2026-08-06 14:41:39 -05:00
# Schema for Postgres and MySQL. Unused by the default SQLite deployment, which
# builds its tables at startup instead.
COPY --chown=node:node drizzle ./drizzle
2025-08-07 02:20:27 -05:00
VOLUME ["/app/data"]
+17
2026-09-20 14:56:39 -05:00
EXPOSE ${PORT}
2025-08-07 02:20:27 -05:00
+5
2026-03-08 18:02:14 -05:00
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD wget -q -O /dev/null http://localhost:30001/health || exit 1
2026-01-24 19:49:42 -06:00
2025-08-07 02:20:27 -05:00
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
+1
2025-12-31 22:20:12 -06:00
+7
2025-11-05 10:36:16 -06:00
CMD ["/entrypoint.sh"]