-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (37 loc) · 1.44 KB
/
Dockerfile
File metadata and controls
53 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# syntax=docker/dockerfile:1
FROM golang:1.25-alpine AS builder
WORKDIR /src
# Copy dependency files first for better layer caching
COPY go.mod go.sum ./
# Download dependencies with cache mount for better performance
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
# Copy source code
COPY . .
# Generate GraphQL code with cache mount
RUN --mount=type=cache,target=/go/pkg/mod \
go generate .
ENV GOEXPERIMENT="greenteagc,jsonv2" CGO_ENABLED=0
# Build the applications with cache mount for build cache
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
go build -ldflags="-w -s" -trimpath -o backend ./cmd/backend && \
go build -ldflags="-w -s" -trimpath -o admin-cli ./cmd/admin-cli
# Final stage with minimal runtime image
FROM alpine:3.23 AS runtime
# Install ca-certificates for HTTPS requests
RUN apk --no-cache add ca-certificates
# Create non-root user for security
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
WORKDIR /app
# Copy binaries from builder stage
COPY --from=builder --chown=appuser:appgroup /src/backend /app/backend
COPY --from=builder --chown=appuser:appgroup /src/admin-cli /app/admin-cli
# Switch to non-root user
USER appuser
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080 || exit 1
CMD ["/app/backend"]