2025-12-25 14:47:19 +08:00
|
|
|
# =============================================================================
|
|
|
|
|
# Sub2API Dockerfile for GoReleaser
|
|
|
|
|
# =============================================================================
|
|
|
|
|
# This Dockerfile is used by GoReleaser to build Docker images.
|
|
|
|
|
# It only packages the pre-built binary, no compilation needed.
|
|
|
|
|
# =============================================================================
|
|
|
|
|
|
2026-03-15 16:37:41 +08:00
|
|
|
ARG ALPINE_IMAGE=alpine:3.21
|
|
|
|
|
ARG POSTGRES_IMAGE=postgres:18-alpine
|
|
|
|
|
|
|
|
|
|
FROM ${POSTGRES_IMAGE} AS pg-client
|
|
|
|
|
|
|
|
|
|
FROM ${ALPINE_IMAGE}
|
2025-12-25 14:47:19 +08:00
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
# Install runtime dependencies
|
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
|
ca-certificates \
|
|
|
|
|
tzdata \
|
|
|
|
|
curl \
|
2026-03-15 16:37:41 +08:00
|
|
|
libpq \
|
|
|
|
|
zstd-libs \
|
|
|
|
|
lz4-libs \
|
|
|
|
|
krb5-libs \
|
|
|
|
|
libldap \
|
|
|
|
|
libedit \
|
2025-12-25 14:47:19 +08:00
|
|
|
&& rm -rf /var/cache/apk/*
|
|
|
|
|
|
2026-03-15 16:37:41 +08:00
|
|
|
# Copy pg_dump and psql from a version-matched PostgreSQL image so backup and
|
|
|
|
|
# restore work in the runtime container without requiring Docker socket access.
|
|
|
|
|
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/
|
|
|
|
|
|
2025-12-25 14:47:19 +08:00
|
|
|
# Create non-root user
|
|
|
|
|
RUN addgroup -g 1000 sub2api && \
|
|
|
|
|
adduser -u 1000 -G sub2api -s /bin/sh -D sub2api
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Copy pre-built binary from GoReleaser
|
|
|
|
|
COPY sub2api /app/sub2api
|
|
|
|
|
|
|
|
|
|
# Create data directory
|
|
|
|
|
RUN mkdir -p /app/data && chown -R sub2api:sub2api /app
|
|
|
|
|
|
|
|
|
|
USER sub2api
|
|
|
|
|
|
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
|
|
|
|
CMD curl -f http://localhost:${SERVER_PORT:-8080}/health || exit 1
|
|
|
|
|
|
|
|
|
|
ENTRYPOINT ["/app/sub2api"]
|