chore: restore Dockerfile to upstream v0.1.110

Reverting Dockerfile to match upstream version:
- Use golang:1.26.2-alpine instead of 1.25
- Use Alpine as final runtime image (not Debian)
- Remove LS binary and certificate setup
- Restore apk-based package management
- Remove multi-architecture build targets

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
win 2026-04-09 00:43:10 +08:00
parent c2db74a24c
commit d6100ae39e

View File

@ -7,9 +7,8 @@
# =============================================================================
ARG NODE_IMAGE=node:24-alpine
ARG GOLANG_IMAGE=golang:1.25-alpine
ARG GOLANG_IMAGE=golang:1.26.2-alpine
ARG ALPINE_IMAGE=alpine:3.21
ARG DEBIAN_IMAGE=debian:bookworm-slim
ARG POSTGRES_IMAGE=postgres:18-alpine
ARG GOPROXY=https://goproxy.cn,direct
ARG GOSUMDB=sum.golang.google.cn
@ -64,12 +63,10 @@ COPY --from=frontend-builder /app/backend/internal/web/dist ./internal/web/dist
# Build the binary (BuildType=release for CI builds, embed frontend)
# Version precedence: build arg VERSION > cmd/server/VERSION
ARG TARGETARCH
ARG TARGETOS=linux
RUN VERSION_VALUE="${VERSION}" && \
if [ -z "${VERSION_VALUE}" ]; then VERSION_VALUE="$(tr -d '\r\n' < ./cmd/server/VERSION)"; fi && \
DATE_VALUE="${DATE:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}" && \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
CGO_ENABLED=0 GOOS=linux go build \
-tags embed \
-ldflags="-s -w -X main.Version=${VERSION_VALUE} -X main.Commit=${COMMIT} -X main.Date=${DATE_VALUE} -X main.BuildType=release" \
-trimpath \
@ -82,9 +79,9 @@ RUN VERSION_VALUE="${VERSION}" && \
FROM ${POSTGRES_IMAGE} AS pg-client
# -----------------------------------------------------------------------------
# Stage 4: Final Runtime Image (Debian for glibc — LS binary requires it)
# Stage 4: Final Runtime Image
# -----------------------------------------------------------------------------
FROM ${DEBIAN_IMAGE}
FROM ${ALPINE_IMAGE}
# Labels
LABEL maintainer="Wei-Shaw <github.com/Wei-Shaw>"
@ -92,25 +89,27 @@ LABEL description="Sub2API - AI API Gateway Platform"
LABEL org.opencontainers.image.source="https://github.com/Wei-Shaw/sub2api"
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
RUN apk add --no-cache \
ca-certificates \
curl \
wget \
gosu \
proxychains4 \
tzdata \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
su-exec \
libpq \
zstd-libs \
lz4-libs \
krb5-libs \
libldap \
libedit \
&& rm -rf /var/cache/apk/*
# Copy pg_dump and psql from the same postgres image used in docker-compose
# This ensures version consistency between backup tools and the database server
COPY --from=pg-client /usr/local/bin/pg_dump /usr/local/bin/pg_dump
COPY --from=pg-client /usr/local/bin/psql /usr/local/bin/psql
COPY --from=pg-client /usr/local/lib/libpq.so.5* /usr/local/lib/
RUN ldconfig
# Create non-root user
RUN groupadd -g 1000 sub2api && \
useradd -u 1000 -g sub2api -m -s /bin/sh sub2api
RUN addgroup -g 1000 sub2api && \
adduser -u 1000 -G sub2api -s /bin/sh -D sub2api
# Set working directory
WORKDIR /app
@ -119,21 +118,6 @@ WORKDIR /app
COPY --from=backend-builder --chown=sub2api:sub2api /app/sub2api /app/sub2api
COPY --from=backend-builder --chown=sub2api:sub2api /app/backend/resources /app/resources
# Copy Language Server binary and cert (for LS pool mode)
# Enable with: ANTIGRAVITY_LS_MODE=true ANTIGRAVITY_APP_ROOT=/app/ls
# TARGETARCH is set automatically by buildx (amd64 or arm64)
ARG TARGETARCH
COPY --chown=sub2api:sub2api deploy/ls-bin/language_server_linux_* /tmp/ls-bin/
COPY --chown=sub2api:sub2api deploy/ls-bin/cert.pem /app/ls/extensions/antigravity/dist/languageServer/
RUN mkdir -p /app/ls/extensions/antigravity/bin && \
if [ "$TARGETARCH" = "arm64" ]; then \
cp /tmp/ls-bin/language_server_linux_arm /app/ls/extensions/antigravity/bin/language_server_linux_arm; \
else \
cp /tmp/ls-bin/language_server_linux_x64 /app/ls/extensions/antigravity/bin/language_server_linux_x64; \
fi && \
chmod +x /app/ls/extensions/antigravity/bin/language_server_linux_* && \
rm -rf /tmp/ls-bin
# Create data directory
RUN mkdir -p /app/data && chown sub2api:sub2api /app/data