|
1 | | -FROM quay.io/projectquay/golang:1.23 AS build-env |
| 1 | +# Stage 1: Build Go binary |
| 2 | +FROM quay.io/projectquay/golang:1.25 AS go-builder |
2 | 3 | WORKDIR /go/src/app |
3 | | -COPY . . |
4 | | - |
| 4 | +COPY go.mod go.sum ./ |
5 | 5 | RUN go mod download |
6 | | -RUN CGO_ENABLED=0 go build -o /go/bin/app main.go |
| 6 | +COPY main.go ./ |
| 7 | +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app main.go |
| 8 | + |
| 9 | +# Stage 2: Download and extract Prometheus |
| 10 | +FROM registry.access.redhat.com/ubi9/ubi:latest AS prometheus-downloader |
| 11 | +ARG PROMETHEUS_VERSION=3.12.0 |
| 12 | +ARG TARGETARCH=amd64 |
| 13 | + |
| 14 | +WORKDIR /tmp |
| 15 | +RUN curl -L -o prometheus.tar.gz "https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-${TARGETARCH}.tar.gz" && \ |
| 16 | + tar xzf prometheus.tar.gz && \ |
| 17 | + mv "prometheus-${PROMETHEUS_VERSION}.linux-${TARGETARCH}/prometheus" /prometheus |
| 18 | + |
| 19 | +# Stage 3: Runtime image |
| 20 | +FROM registry.access.redhat.com/ubi9/ubi-minimal:latest |
| 21 | + |
| 22 | +# Install CA certificates (curl-minimal is already included in ubi-minimal) |
| 23 | +RUN microdnf install -y ca-certificates && \ |
| 24 | + microdnf clean all |
| 25 | + |
| 26 | +# Copy Go binary |
| 27 | +COPY --from=go-builder /go/src/app/app /app |
| 28 | + |
| 29 | +# Copy Prometheus binary |
| 30 | +COPY --from=prometheus-downloader /prometheus /bin/prometheus |
| 31 | + |
| 32 | +# Copy configuration and scripts |
| 33 | +COPY prometheus.yml.template /etc/prometheus/prometheus.yml.template |
| 34 | +COPY start.sh /start.sh |
| 35 | +RUN chmod +x /start.sh |
| 36 | + |
| 37 | +# Create necessary directories with proper permissions |
| 38 | +RUN mkdir -p /tmp/agent-data && \ |
| 39 | + mkdir -p /etc/secrets && \ |
| 40 | + chmod 777 /tmp/agent-data && \ |
| 41 | + chmod 777 /etc/secrets |
| 42 | + |
| 43 | +# Use non-root user |
| 44 | +USER 1000:1000 |
| 45 | + |
| 46 | +ENTRYPOINT ["/start.sh"] |
7 | 47 |
|
8 | | -# Copy the exe into a smaller base image |
9 | | -FROM gcr.io/distroless/static-debian12 |
10 | | -COPY --from=build-env /go/bin/app / |
11 | | -CMD ["/app"] |
| 48 | +# Made with Bob |
0 commit comments