| |
| |
| |
| |
| |
| |
| |
|
|
| ARG NODE_IMAGE=node:24-alpine |
| ARG GOLANG_IMAGE=golang:1.26.3-alpine |
| ARG ALPINE_IMAGE=alpine:3.21 |
| ARG POSTGRES_IMAGE=postgres:18-alpine |
| ARG GOPROXY=https://goproxy.cn,direct |
| ARG GOSUMDB=sum.golang.google.cn |
|
|
| |
| |
| |
| FROM ${NODE_IMAGE} AS frontend-builder |
|
|
| WORKDIR /app/frontend |
|
|
| |
| RUN corepack enable && corepack prepare pnpm@9 --activate |
|
|
| |
| COPY frontend/package.json frontend/pnpm-lock.yaml ./ |
| RUN pnpm install --frozen-lockfile |
|
|
| |
| COPY frontend/ ./ |
| RUN pnpm run build |
|
|
| |
| |
| |
| FROM ${GOLANG_IMAGE} AS backend-builder |
|
|
| |
| ARG VERSION= |
| ARG COMMIT=docker |
| ARG DATE |
| ARG GOPROXY |
| ARG GOSUMDB |
|
|
| ENV GOPROXY=${GOPROXY} |
| ENV GOSUMDB=${GOSUMDB} |
|
|
| |
| RUN apk add --no-cache git ca-certificates tzdata |
|
|
| WORKDIR /app/backend |
|
|
| |
| COPY backend/go.mod backend/go.sum ./ |
| RUN go mod download |
|
|
| |
| COPY backend/ ./ |
|
|
| |
| COPY --from=frontend-builder /app/backend/internal/web/dist ./internal/web/dist |
|
|
| |
| |
| 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=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 \ |
| -o /app/su2a \ |
| ./cmd/server |
| |
| |
| |
| |
| FROM ${POSTGRES_IMAGE} AS pg-client |
|
|
| |
| |
| |
| FROM ${ALPINE_IMAGE} |
|
|
| |
| LABEL maintainer="Wei-Shaw <github.com/Wei-Shaw>" |
| LABEL description="Sub2API - AI API Gateway Platform" |
| LABEL org.opencontainers.image.source="https://github.com/Wei-Shaw/sub2api" |
|
|
| |
| RUN apk add --no-cache \ |
| ca-certificates \ |
| tzdata \ |
| su-exec \ |
| libpq \ |
| zstd-libs \ |
| lz4-libs \ |
| krb5-libs \ |
| libldap \ |
| libedit \ |
| python3 \ |
| py3-pip \ |
| postgresql \ |
| postgresql-client \ |
| redis \ |
| && rm -rf /var/cache/apk/* |
|
|
| RUN pip3 install --no-cache-dir --break-system-packages huggingface_hub |
|
|
| # 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/ |
|
|
| # Create non-root user |
| RUN addgroup -g 1000 su2a && \ |
| adduser -u 1000 -G su2a -s /bin/sh -D su2a |
|
|
| # Set working directory |
| WORKDIR /app |
|
|
| # Copy binary/resources with ownership to avoid extra full-layer chown copy |
| COPY --from=backend-builder --chown=su2a:su2a /app/su2a /app/su2a |
| COPY --from=backend-builder --chown=su2a:su2a /app/backend/resources /app/resources |
|
|
| # Create data directory |
| RUN mkdir -p /app/data/redis /app/data && chown su2a:su2a /app/data |
|
|
| # Copy entrypoint script (fixes volume permissions then drops to sub2api) |
| COPY deploy/docker-entrypoint.sh /app/docker-entrypoint.sh |
| RUN chmod +x /app/docker-entrypoint.sh |
|
|
| # Expose port (can be overridden by SERVER_PORT env var) |
| EXPOSE 8080 |
|
|
| # Health check |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ |
| CMD wget -q -T 5 -O /dev/null http://localhost:${SERVER_PORT:-8080}/health || exit 1 |
|
|
| # Run the application (entrypoint fixes /app/data ownership then execs as sub2api) |
| ENTRYPOINT ["/app/docker-entrypoint.sh"] |
| CMD ["/app/su2a"] |
|
|