Dockerfile.goreleaser 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # =============================================================================
  2. # Sub2API Dockerfile for GoReleaser
  3. # =============================================================================
  4. # This Dockerfile is used by GoReleaser to build Docker images.
  5. # It only packages the pre-built binary, no compilation needed.
  6. # =============================================================================
  7. ARG ALPINE_IMAGE=alpine:3.21
  8. ARG POSTGRES_IMAGE=postgres:18-alpine
  9. FROM ${POSTGRES_IMAGE} AS pg-client
  10. FROM ${ALPINE_IMAGE}
  11. LABEL maintainer="Wei-Shaw <github.com/Wei-Shaw>"
  12. LABEL description="Sub2API - AI API Gateway Platform"
  13. LABEL org.opencontainers.image.source="https://github.com/Wei-Shaw/sub2api"
  14. # Install runtime dependencies
  15. RUN apk add --no-cache \
  16. ca-certificates \
  17. tzdata \
  18. curl \
  19. su-exec \
  20. libpq \
  21. zstd-libs \
  22. lz4-libs \
  23. krb5-libs \
  24. libldap \
  25. libedit \
  26. && rm -rf /var/cache/apk/*
  27. # Copy pg_dump and psql from a version-matched PostgreSQL image so backup and
  28. # restore work in the runtime container without requiring Docker socket access.
  29. COPY --from=pg-client /usr/local/bin/pg_dump /usr/local/bin/pg_dump
  30. COPY --from=pg-client /usr/local/bin/psql /usr/local/bin/psql
  31. COPY --from=pg-client /usr/local/lib/libpq.so.5* /usr/local/lib/
  32. # Create non-root user
  33. RUN addgroup -g 1000 sub2api && \
  34. adduser -u 1000 -G sub2api -s /bin/sh -D sub2api
  35. WORKDIR /app
  36. # Copy the pre-built binary and runtime fallback resources from GoReleaser
  37. COPY sub2api /app/sub2api
  38. COPY --chown=sub2api:sub2api backend/resources /app/resources
  39. # Create data directory
  40. RUN mkdir -p /app/data && chown -R sub2api:sub2api /app
  41. # Copy entrypoint script (fixes volume permissions then drops to sub2api)
  42. COPY deploy/docker-entrypoint.sh /app/docker-entrypoint.sh
  43. RUN chmod +x /app/docker-entrypoint.sh
  44. EXPOSE 8080
  45. HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
  46. CMD curl -f http://localhost:${SERVER_PORT:-8080}/health || exit 1
  47. # Run the application (entrypoint fixes /app/data ownership then execs as sub2api)
  48. ENTRYPOINT ["/app/docker-entrypoint.sh"]
  49. CMD ["/app/sub2api"]