This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathci.Dockerfile
67 lines (50 loc) · 1.81 KB
/
ci.Dockerfile
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# syntax=docker/dockerfile:1
# Build stage
FROM --platform=$BUILDPLATFORM golang:1.23-alpine3.20 AS app-builder
# Install git for revision info and ca-certificates for potential downloads
RUN apk add --no-cache git ca-certificates tzdata
# Create non-root user for build
RUN adduser -D -g '' appuser
WORKDIR /src
# Copy dependency files first for better cache utilization
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY cmd/ ./cmd/
COPY internal/ ./internal/
# Copy rest of the files
COPY . .
ARG VERSION=dev
ARG REVISION=dev
ARG BUILDTIME
ARG TARGETOS TARGETARCH
# Build with security flags and proper versioning
# Network is disabled during build
RUN --network=none --mount=target=. \
BUILDTIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
REVISION=$(git rev-parse --short HEAD) \
CGO_ENABLED=0 \
GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -trimpath \
-ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.buildDate=${BUILDTIME} -extldflags '-static'" \
-o /out/bin/redactedhook cmd/redactedhook/main.go
# Runtime stage
FROM gcr.io/distroless/static-debian12:nonroot
LABEL org.opencontainers.image.source="https://github.com/s0up4200/redactedhook"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.base.name="distroless/static-debian12:nonroot"
LABEL org.opencontainers.image.description="RedactedHook CI image"
# Set environment variables
ENV HOME="/redactedhook" \
XDG_CONFIG_HOME="/redactedhook" \
XDG_DATA_HOME="/redactedhook"
WORKDIR /redactedhook
VOLUME /redactedhook
# Copy the binary from builder
COPY --from=app-builder /out/bin/redactedhook /usr/local/bin/
# Expose the application port
EXPOSE 42135
# Use nonroot user
USER nonroot:nonroot
# Set entry point
ENTRYPOINT ["/usr/local/bin/redactedhook", "--config", "config.toml"]