Simplify and validate Docker deployment

This commit is contained in:
2026-07-13 01:53:09 +08:00
parent b98c519e27
commit e8c791dcde
3 changed files with 28 additions and 34 deletions
+19 -8
View File
@@ -1,17 +1,28 @@
FROM golang:1.26 AS build FROM golang:1.26 AS build
WORKDIR /src WORKDIR /src
COPY go.mod ./ COPY go.mod ./
RUN go mod download RUN go mod download
COPY . . COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /preface-tools ./cmd/preface-tools RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/preface-tools ./cmd/preface-tools
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /healthcheck ./cmd/healthcheck RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/healthcheck ./cmd/healthcheck
FROM alpine:3.21
RUN apk add --no-cache ca-certificates \
&& addgroup -S -g 10001 preface \
&& adduser -S -D -H -u 10001 -G preface preface
FROM gcr.io/distroless/static-debian12:nonroot
WORKDIR /app WORKDIR /app
COPY --from=build /preface-tools /usr/local/bin/preface-tools COPY --from=build /out/preface-tools /usr/local/bin/preface-tools
COPY --from=build /healthcheck /usr/local/bin/healthcheck COPY --from=build /out/healthcheck /usr/local/bin/healthcheck
COPY --from=build /src/prompts /app/prompts COPY --chown=preface:preface prompts /app/prompts
VOLUME ["/app/data"] RUN mkdir -p /app/data/comic-animator/uploads /app/data/comic-animator/outputs \
&& chown -R preface:preface /app/data
USER preface
EXPOSE 8080 EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 CMD ["/usr/local/bin/healthcheck", "http://127.0.0.1:8080/readyz"] HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["/usr/local/bin/healthcheck", "http://127.0.0.1:8080/readyz"]
ENTRYPOINT ["/usr/local/bin/preface-tools"] ENTRYPOINT ["/usr/local/bin/preface-tools"]
+6 -7
View File
@@ -149,14 +149,13 @@ running process immediately.
docker compose logs -f preface-tools docker compose logs -f preface-tools
``` ```
4. Put a TLS reverse proxy in front of `127.0.0.1:8080`. The Compose file binds 4. Put a TLS reverse proxy in front of port `8080`. The Compose file publishes
only to loopback deliberately. If TLS is terminated by an ingress on another that port on the host. Restrict it with the host firewall if the server is on
host, adjust the `ports` mapping or use an external Docker network while an untrusted network, or change the mapping to `127.0.0.1:8080:8080` after
keeping the application container otherwise private. confirming loopback Docker forwarding works on the deployment host.
The container runs as a non-root user with all Linux capabilities dropped, a The container runs as a dedicated non-root user and stores runtime data in a
read-only root filesystem, `no-new-privileges`, and a named volume for runtime named volume. It exposes:
data. It exposes:
- `GET /healthz` for liveness; - `GET /healthz` for liveness;
- `GET /readyz` for readiness. - `GET /readyz` for readiness.
+3 -19
View File
@@ -1,12 +1,9 @@
services: services:
preface-tools: preface-tools:
build: build: .
context: .
image: preface-tools:local image: preface-tools:local
restart: unless-stopped restart: unless-stopped
init: true env_file: .env
env_file:
- .env
environment: environment:
APP_ENV: production APP_ENV: production
HTTP_ADDRESS: :8080 HTTP_ADDRESS: :8080
@@ -14,23 +11,10 @@ services:
COMIC_ANIMATOR_UPLOAD_DIR: /app/data/comic-animator/uploads COMIC_ANIMATOR_UPLOAD_DIR: /app/data/comic-animator/uploads
COMIC_ANIMATOR_OUTPUT_DIR: /app/data/comic-animator/outputs COMIC_ANIMATOR_OUTPUT_DIR: /app/data/comic-animator/outputs
ports: ports:
- "127.0.0.1:8080:8080" - "8080:8080"
volumes: volumes:
- preface-data:/app/data - preface-data:/app/data
- ./prompts:/app/prompts:ro - ./prompts:/app/prompts:ro
read_only: true
tmpfs:
- /tmp:size=64m,mode=1777
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD", "/usr/local/bin/healthcheck", "http://127.0.0.1:8080/readyz"]
interval: 30s
timeout: 3s
start_period: 10s
retries: 3
volumes: volumes:
preface-data: preface-data: