feat: health check for backend in docker-compose;
feat: go dockerfile preinstalls curl; refactor: reduced go image size by using a 2 stage dockerfile; refactor: switch frontend dockerfile
This commit is contained in:
@@ -1,12 +1,30 @@
|
||||
FROM golang:1.24
|
||||
# Stage 1: Build the binary
|
||||
FROM golang:1.24 AS builder
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
WORKDIR /app
|
||||
|
||||
# Copy dependencies and download
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy source and build static binary
|
||||
COPY . .
|
||||
RUN go build -v -o /usr/local/bin/app ./...
|
||||
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /main ./cmd/main.go
|
||||
|
||||
CMD ["app"]
|
||||
# Stage 2: Lightweight runtime with tools
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
# Install curl, shell (sh), and SSL certificates
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends curl ca-certificates && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create non-root user and set ownership
|
||||
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
||||
USER appuser
|
||||
|
||||
# Copy compiled binary
|
||||
COPY --from=builder /main /main
|
||||
|
||||
# Execute the binary
|
||||
CMD ["/main"]
|
||||
|
||||
Reference in New Issue
Block a user