|
1 | | -# CONTAINER FOR BUILDING BINARY |
2 | | -FROM --platform=${BUILDPLATFORM} golang:1.24.4 AS build |
| 1 | +# ================================ |
| 2 | +# STAGE 1: Build binary |
| 3 | +# ================================ |
| 4 | +FROM --platform=${BUILDPLATFORM} golang:1.24.4-alpine AS builder |
| 5 | + |
| 6 | +# Install build dependencies |
| 7 | +RUN apk add --no-cache gcc musl-dev make sqlite-dev |
3 | 8 |
|
4 | 9 | WORKDIR /app |
5 | 10 |
|
6 | | -# INSTALL DEPENDENCIES |
| 11 | +# Download Go dependencies |
7 | 12 | COPY go.mod go.sum ./ |
8 | 13 | RUN go mod download |
9 | 14 |
|
10 | | -# BUILD BINARY |
| 15 | +# Copy source and build |
11 | 16 | COPY . . |
12 | | -RUN make build-aggkit build-tools |
13 | | - |
14 | | -# CONTAINER FOR RUNNING BINARY |
15 | | -FROM --platform=${BUILDPLATFORM} debian:bookworm-slim |
16 | | -RUN apt-get update && \ |
17 | | - apt-get install -y --no-install-recommends \ |
18 | | - ca-certificates \ |
19 | | - sqlite3 \ |
20 | | - procps \ |
21 | | - libssl-dev && \ |
22 | | - rm -rf /var/lib/apt/lists/* |
23 | | -COPY --from=build /app/target/aggkit /usr/local/bin/ |
24 | | - |
25 | | -# ADD NON-ROOT USER |
26 | | -RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser |
| 17 | + |
| 18 | +# Compile binary |
| 19 | +RUN make build-aggkit |
| 20 | + |
| 21 | +# ================================ |
| 22 | +# STAGE 2: Final runtime image |
| 23 | +# ================================ |
| 24 | +FROM alpine:3.22 |
| 25 | + |
| 26 | +# Install runtime dependencies and remove shell |
| 27 | +RUN apk add --no-cache sqlite-libs ca-certificates |
| 28 | + |
| 29 | +# Add non-root user with home and nologin shell |
| 30 | +RUN addgroup appgroup && \ |
| 31 | + adduser -D -G appgroup -h /home/appuser -s /sbin/nologin appuser && \ |
| 32 | + mkdir -p /home/appuser && \ |
| 33 | + chown -R appuser:appgroup /home/appuser |
| 34 | + |
| 35 | +# Set the working directory and user |
| 36 | +# This ensures that the application runs as a non-root user |
| 37 | +WORKDIR /home/appuser |
27 | 38 | USER appuser |
28 | 39 |
|
| 40 | +# Copy the built binary from the builder stage |
| 41 | +COPY --from=builder /app/target/aggkit /usr/local/bin/aggkit |
| 42 | + |
29 | 43 | EXPOSE 5576/tcp |
30 | 44 |
|
31 | 45 | ENTRYPOINT ["/usr/local/bin/aggkit"] |
0 commit comments