Skip to content

Container Deployment

ddddd edited this page Jun 27, 2026 · 3 revisions

容器部署 / Container Deployment

SPACK 的主要使用方式是作为前端构建产物的 runtime image。发布镜像位于 GitHub Container Registry 和 Docker Hub。

The primary way to use SPACK is as a runtime image for frontend build outputs. Published images live in GitHub Container Registry and Docker Hub.

镜像 / Images

Runtime 默认镜像使用 Debian slim。Alpine 作为可选 runtime flavor 单独通过 alpine tag 发布。Compiler 镜像包含 libvips 运行依赖,用于 AOT 编译和图片变体生成,不建议作为生产 runtime 使用。

The default runtime image uses Debian slim. Alpine is published as a separate runtime flavor through alpine tags. The compiler image includes libvips runtime dependencies for AOT compilation and image variant generation, and should not be used as the production runtime.

# Runtime, Debian slim default
docker pull ghcr.io/lyonbrown4d/spack:v2.0.3
docker pull ghcr.io/lyonbrown4d/spack:latest
docker pull lyonbrown4d/spack:v2.0.3
docker pull lyonbrown4d/spack:latest

# Runtime, Alpine flavor
docker pull ghcr.io/lyonbrown4d/spack:alpine-v2.0.3
docker pull ghcr.io/lyonbrown4d/spack:alpine
docker pull lyonbrown4d/spack:alpine-v2.0.3
docker pull lyonbrown4d/spack:alpine

# Compiler, Debian slim + libvips
docker pull ghcr.io/lyonbrown4d/spack-compiler:v2.0.3
docker pull ghcr.io/lyonbrown4d/spack-compiler:latest
docker pull lyonbrown4d/spack-compiler:v2.0.3
docker pull lyonbrown4d/spack-compiler:latest

Tag 规则 / Tag Policy

Repository Tag Image Platforms
spack latest Debian slim runtime latest linux/amd64, linux/arm64
spack <version> Debian slim runtime version linux/amd64, linux/arm64
spack debian Debian slim runtime latest linux/amd64, linux/arm64
spack debian-<version> Debian slim runtime version linux/amd64, linux/arm64
spack alpine Alpine runtime latest linux/amd64 in v2.0.3
spack alpine-<version> Alpine runtime version linux/amd64 in v2.0.3
spack-compiler latest Debian slim compiler latest linux/amd64
spack-compiler <version> Debian slim compiler version linux/amd64
spack-compiler debian Debian slim compiler latest linux/amd64
spack-compiler debian-<version> Debian slim compiler version linux/amd64

v2.0.3 发布摘要 / v2.0.3 Release Summary

GitHub Release: https://github.com/lyonbrown4d/spack/releases/tag/v2.0.3

Image Tags Digest
Runtime Debian v2.0.3, latest, debian, debian-v2.0.3 sha256:cae38c9974f6aa9e9bf5714210988533749b22237e5999311b91cbf07478e600
Runtime Alpine alpine, alpine-v2.0.3 sha256:0714dadd3302affdb8fd32ddc659c9bf7b7154b34ba278af7e2ffcebe36651d7
Compiler Debian v2.0.3, latest, debian, debian-v2.0.3 sha256:2e2bb7b3ce57f0948b55c9999592208a6116a8e6973c956c3d4079a23f0b41d6

这些 digest 同时适用于 GHCR 和 Docker Hub 上对应的 tag。

These digests apply to the matching tags on both GHCR and Docker Hub.

AOT Bundle Dockerfile

AOT 模式先用 compiler 生成 .spack 文件,再把 bundle 复制到 runtime 镜像。Runtime 启动时一次性解压 bundle 到受管临时目录,请求路径不会每次重新解压。

AOT mode uses the compiler to produce a .spack bundle, then copies the bundle into the runtime image. The runtime extracts the bundle once during startup into a managed temporary directory; requests do not decompress the bundle repeatedly.

FROM node:22-alpine AS frontend
WORKDIR /workspace

COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile

COPY . .
RUN pnpm build

FROM ghcr.io/lyonbrown4d/spack-compiler:v2.0.3 AS compiler
WORKDIR /workspace
COPY --from=frontend /workspace/dist /workspace/dist
RUN spack-compiler compile /workspace/dist -o /workspace/app.spack
RUN spack-compiler verify /workspace/app.spack

FROM ghcr.io/lyonbrown4d/spack:v2.0.3
COPY --from=compiler /workspace/app.spack /app/app.spack

ENV SPACK_ASSETS_ROOT=/app/app.spack
ENV SPACK_ASSETS_PATH=/
ENV SPACK_ASSETS_ENTRY=index.html
ENV SPACK_ASSETS_FALLBACK_TARGET=index.html
ENV SPACK_HTTP_PORT=80

EXPOSE 80

Direct Dist Dockerfile

Runtime 仍然支持直接服务前端构建目录。这条路径适合迁移、调试和不需要 AOT 预优化的部署。

The runtime still supports serving a frontend build directory directly. This path is useful for migration, debugging, and deployments that do not need AOT pre-optimization.

FROM node:22-alpine AS build
WORKDIR /workspace

COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile

COPY . .
RUN pnpm build

FROM ghcr.io/lyonbrown4d/spack:v2.0.3

COPY --from=build /workspace/dist /app

ENV SPACK_ASSETS_ROOT=/app
ENV SPACK_ASSETS_PATH=/
ENV SPACK_ASSETS_ENTRY=index.html
ENV SPACK_ASSETS_FALLBACK_TARGET=index.html
ENV SPACK_HTTP_PORT=80

EXPOSE 80

使用配置文件 / Use a Config File

FROM ghcr.io/lyonbrown4d/spack:v2.0.3

COPY ./dist /app
COPY ./deploy/spack.yaml /etc/spack/spack.yaml

ENV SPACK_ASSETS_ROOT=/app

CMD ["--config", "/etc/spack/spack.yaml"]

作为基础镜像 / Runtime Base Image

FROM ghcr.io/lyonbrown4d/spack:v2.0.3 AS spack-runtime

ENV SPACK_ASSETS_ROOT=/srv/www
ENV SPACK_ASSETS_PATH=/
ENV SPACK_ASSETS_ENTRY=index.html
ENV SPACK_ASSETS_FALLBACK_TARGET=index.html
ENV SPACK_HTTP_PORT=80
ENV SPACK_DEBUG_ENABLE=true
ENV SPACK_DEBUG_LIVE_PORT=8080

FROM spack-runtime
COPY ./dist /srv/www

EXPOSE 80 8080

推荐部署策略 / Recommended Deployment Strategy

中文:

  • 优先使用 AOT bundle 部署生产环境,直接目录模式用于兼容和调试。
  • 优先把静态资源 bake 进镜像,而不是运行时挂载可变 volume。
  • 让 hashed assets 使用 immutable cache。
  • 让 index.html 保持可重新验证。
  • debug runtime 只暴露在可信网络。
  • 使用 spack_build_info 和 spack_runtime_start_time_seconds 关联发布和重启。
  • 如果前端构建工具已经生成 .br, .zst, .gz sidecar,直接随 dist 一起复制进镜像。

English:

  • Prefer AOT bundle deployment for production; keep direct directory mode for compatibility and debugging.
  • Prefer baking static assets into the image instead of mounting mutable runtime volumes.
  • Let hashed assets use immutable cache.
  • Keep index.html revalidated.
  • Expose the debug runtime only on trusted networks.
  • Use spack_build_info and spack_runtime_start_time_seconds to correlate releases and restarts.
  • If the frontend build tool already generates .br, .zst, or .gz sidecars, copy them with dist.

Kubernetes 示例 / Kubernetes Example

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: spack
          image: ghcr.io/lyonbrown4d/spack:v2.0.3
          ports:
            - containerPort: 80
            - containerPort: 8080
          env:
            - name: SPACK_ASSETS_ROOT
              value: /app/app.spack
            - name: SPACK_ASSETS_FALLBACK_TARGET
              value: index.html
          readinessProbe:
            httpGet:
              path: /readyz
              port: 80
          livenessProbe:
            httpGet:
              path: /livez
              port: 80

注意:这个示例假设镜像内已经包含 /app/app.spack。如果使用 ConfigMap 或 PVC 挂载资源,需要确保挂载在 SPACK 启动前可用。

Note: This example assumes /app/app.spack is already included in the image. If assets are mounted via ConfigMap or PVC, ensure they are available before SPACK starts.

Clone this wiki locally