11# syntax=docker/dockerfile:1
22
3- # -✂- this stage is used to develop and build the application locally -------------------------------------------------
4- FROM docker.io/library/golang:1.24-bookworm AS develop
5-
6- # use the /var/tmp/go as the GOPATH to reuse the modules cache
7- ENV GOPATH="/var/tmp/go"
8-
9- RUN set -x \
10- # renovate: source=github-releases name=golangci/golangci-lint
11- && GOLANGCI_LINT_VERSION="2.3.0" \
12- && wget -O- -nv "https://cdn.jsdelivr.net/gh/golangci/golangci-lint@v${GOLANGCI_LINT_VERSION}/install.sh" \
13- | sh -s -- -b /bin "v${GOLANGCI_LINT_VERSION}"
14-
15- RUN set -x \
16- # customize the shell prompt (for the bash)
17- && echo "PS1='\[\0 33[1;36m\] [go] \[\0 33[1;34m\]\w\[\0 33[0;35m\] \[\0 33[1;36m\] # \[\0 33[0m\] '" >> /etc/bash.bashrc
18-
19- WORKDIR /src
20-
21- # burn the modules cache
22- RUN \
23- --mount=type=bind,source=go.mod,target=/src/go.mod \
24- --mount=type=bind,source=go.sum,target=/src/go.sum \
25- go mod download -x \
26- && find "${GOPATH}" -type d -exec chmod 0777 {} \; \
27- && find "${GOPATH}" -type f -exec chmod 0666 {} \;
28-
293# -✂- this stage is used to compile the application -------------------------------------------------------------------
30- FROM develop AS compile
4+ FROM docker.io/library/golang:1.24-alpine AS compile
315
326# can be passed with any prefix (like `v1.2.3@GITHASH`), e.g.: `docker build --build-arg "APP_VERSION=v1.2.3" .`
337ARG APP_VERSION="undefined@docker"
348
359# copy the source code
3610COPY . /src
3711
12+ WORKDIR /src
13+
3814RUN set -x \
39- && go generate ./... \
40- && CGO_ENABLED=0 LDFLAGS="-s -w -X gh.tarampamp.am/error-pages/internal/appmeta.version=${APP_VERSION}" \
41- go build -trimpath -ldflags "${LDFLAGS}" -o /tmp/error-pages ./cmd/error-pages/ \
15+ && go generate -skip readme ./... \
16+ && CGO_ENABLED=0 go build \
17+ -trimpath \
18+ -ldflags "-s -w -X gh.tarampamp.am/error-pages/internal/appmeta.version=${APP_VERSION}" \
19+ -o /tmp/error-pages \
20+ ./cmd/error-pages/ \
4221 && /tmp/error-pages --version \
4322 && /tmp/error-pages -h
4423
45- # -✂- this stage is used to prepare the runtime fs --------------------------------------------------------------------
46- FROM docker.io/library/alpine:3.22 AS rootfs
47-
4824WORKDIR /tmp/rootfs
4925
5026# prepare rootfs for runtime
5127RUN set -x \
5228 && mkdir -p ./etc/ssl/certs ./bin \
5329 && echo 'appuser:x:10001:10001::/nonexistent:/sbin/nologin' > ./etc/passwd \
5430 && echo 'appuser:x:10001:' > ./etc/group \
55- && cp /etc/ssl/certs/ca-certificates.crt ./etc/ssl/certs/
56-
57- # take the binary from the compile stage
58- COPY --from=compile /tmp/error-pages ./bin/error-pages
31+ && cp /etc/ssl/certs/ca-certificates.crt ./etc/ssl/certs/ \
32+ && mv /tmp/error-pages ./bin/error-pages \
33+ && chmod 755 ./bin/error-pages
5934
6035WORKDIR /tmp/rootfs/opt
6136
@@ -81,7 +56,7 @@ LABEL \
8156 org.opencontainers.image.licenses="MIT"
8257
8358# import from builder
84- COPY --from=rootfs /tmp/rootfs /
59+ COPY --from=compile /tmp/rootfs /
8560
8661# use an unprivileged user
8762USER 10001:10001
@@ -95,7 +70,7 @@ ENV LOG_LEVEL="warn" \
9570 LOG_FORMAT="json"
9671
9772# docs: https://docs.docker.com/reference/dockerfile/#healthcheck
98- HEALTHCHECK --interval=10s --start-interval=1s --start-period=5s --timeout=2s CMD ["/bin/error-pages" , "healthcheck" ]
73+ HEALTHCHECK --interval=10s --start-interval=1s --start-period=2s --timeout=1s CMD ["/bin/error-pages" , "healthcheck" ]
9974
10075ENTRYPOINT ["/bin/error-pages" ]
10176
0 commit comments