|
1 | | -# Build stage |
2 | | -FROM golang:1.25.5-alpine AS builder |
| 1 | +# Runtime image - binaries are pre-built on the host |
| 2 | +FROM alpine:3.21 |
3 | 3 |
|
4 | | -ARG VERSION=dev |
5 | | -ARG GIT_COMMIT=unknown |
6 | | -ARG TARGETOS |
7 | 4 | ARG TARGETARCH |
8 | 5 |
|
9 | | -WORKDIR /build |
10 | | - |
11 | | -# Install build dependencies |
12 | | -RUN apk add --no-cache git ca-certificates tzdata |
13 | | - |
14 | | -# Copy go mod files first for better caching |
15 | | -COPY go.mod go.sum ./ |
16 | | -RUN go mod download |
17 | | - |
18 | | -# Copy source code |
19 | | -COPY . . |
20 | | - |
21 | | -# Build the binary |
22 | | -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ |
23 | | - go build -trimpath -o cachewd \ |
24 | | - -ldflags "-s -w -X main.version=${VERSION} -X main.gitCommit=${GIT_COMMIT}" \ |
25 | | - ./cmd/cachewd |
26 | | - |
27 | | -# Runtime stage |
28 | | -FROM alpine:3.21 |
29 | | - |
30 | 6 | SHELL ["/bin/sh", "-o", "pipefail", "-c"] |
31 | 7 |
|
32 | 8 | # Install runtime dependencies for git operations and TLS |
33 | 9 | RUN apk add --no-cache ca-certificates git tzdata && \ |
34 | | - addgroup -g 1000 cachew && \ |
35 | | - adduser -D -u 1000 -G cachew cachew |
| 10 | + addgroup -g 1000 cachew && \ |
| 11 | + adduser -D -u 1000 -G cachew cachew |
36 | 12 |
|
37 | 13 | # Set working directory (config uses relative paths like ./state/cache) |
38 | 14 | WORKDIR /app |
39 | 15 |
|
40 | | -# Copy binary from builder |
41 | | -COPY --from=builder /build/cachewd /usr/local/bin/cachewd |
| 16 | +# Copy pre-built binary from host (built by Justfile) |
| 17 | +COPY dist/cachewd-linux-${TARGETARCH} /usr/local/bin/cachewd |
42 | 18 |
|
43 | 19 | # Copy default configuration file |
44 | 20 | COPY cachew.hcl /app/cachew.hcl |
45 | 21 |
|
46 | 22 | # Create state directory with proper permissions |
47 | 23 | RUN mkdir -p /app/state/cache && \ |
48 | | - chown -R cachew:cachew /app |
| 24 | + chown -R cachew:cachew /app |
49 | 25 |
|
50 | 26 | # Switch to non-root user |
51 | 27 | USER cachew |
|
0 commit comments