Dockerfile 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. FROM golang:1.22-alpine as builder
  2. ARG VERSION=unknown
  3. # copy project
  4. COPY . /app
  5. # set working directory
  6. WORKDIR /app
  7. # using goproxy if you have network issues
  8. # ENV GOPROXY=https://goproxy.cn,direct
  9. # build
  10. RUN go build -ldflags "-X 'internal.manifest.VersionX=${VERSION}' -X 'internal.manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" -o /app/main cmd/server/main.go
  11. # copy entrypoint.sh
  12. COPY entrypoint.sh /app/entrypoint.sh
  13. RUN chmod +x /app/entrypoint.sh
  14. FROM ubuntu:24.04
  15. COPY --from=builder /app/main /app/main
  16. COPY --from=builder /app/entrypoint.sh /app/entrypoint.sh
  17. WORKDIR /app
  18. # check build args
  19. ARG PLATFORM=local
  20. # Install python3.12 if PLATFORM is local
  21. RUN if [ "$PLATFORM" = "local" ]; then \
  22. apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y python3.12 python3.12-venv python3.12-dev \
  23. && apt-get clean \
  24. && rm -rf /var/lib/apt/lists/* \
  25. && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1; \
  26. fi
  27. ENV PLATFORM=$PLATFORM
  28. ENV GIN_MODE=release
  29. # run the server, using sh as the entrypoint to avoid process being the root process
  30. # and using bash to recycle resources
  31. CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]