Dockerfile 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # ------ Builder stage ------
  2. FROM golang:1.22 AS builder
  3. WORKDIR /app
  4. COPY go.* ./
  5. RUN go mod download
  6. COPY . ./
  7. # Build the application binary with optimisations for a smaller, static binary
  8. RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -ldflags="-s -w" -o pixivfe
  9. # ------ Final image ------
  10. FROM alpine:3.19
  11. WORKDIR /app
  12. # Create a non-root user `pixivfe` for security purposes and set ownership
  13. RUN addgroup -g 1000 -S pixivfe && \
  14. adduser -u 1000 -S pixivfe -G pixivfe && \
  15. chown -R pixivfe:pixivfe /app
  16. # Copy the compiled application and other necessary files from the builder stage
  17. COPY --from=builder /app/pixivfe /app/pixivfe
  18. COPY --from=builder /app/assets /app/assets
  19. COPY ./docker/entrypoint.sh /entrypoint.sh
  20. # Include entrypoint script and ensure it's executable
  21. RUN chmod +x /entrypoint.sh && \
  22. chown pixivfe:pixivfe /entrypoint.sh
  23. # Use the non-root user to run the application
  24. USER pixivfe
  25. EXPOSE 8282
  26. ENTRYPOINT ["/entrypoint.sh"]
  27. HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --start-interval=5s --retries=3 \
  28. CMD wget --spider -q --tries=1 http://127.0.0.1:8282/about || exit 1