2023-09-03 16:16:50 +00:00
|
|
|
# syntax=docker/dockerfile:1
|
2020-07-08 11:12:21 +00:00
|
|
|
|
2023-09-03 16:16:50 +00:00
|
|
|
# this stage is used to build the application
|
2024-03-17 07:39:51 +00:00
|
|
|
FROM docker.io/library/golang:1.22-bookworm AS builder
|
2023-09-03 16:16:50 +00:00
|
|
|
|
|
|
|
COPY ./go.* /src/
|
|
|
|
|
|
|
|
WORKDIR /src
|
|
|
|
|
|
|
|
# burn the modules cache
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
# this stage is used to compile the application
|
|
|
|
FROM builder AS compiler
|
2021-04-13 13:55:03 +00:00
|
|
|
|
2021-09-29 15:38:50 +00:00
|
|
|
# can be passed with any prefix (like `v1.2.3@GITHASH`), e.g.: `docker build --build-arg "APP_VERSION=v1.2.3@GITHASH" .`
|
|
|
|
ARG APP_VERSION="undefined@docker"
|
2020-07-08 11:12:21 +00:00
|
|
|
|
2021-04-13 13:55:03 +00:00
|
|
|
WORKDIR /src
|
2020-07-08 11:12:21 +00:00
|
|
|
|
2021-09-29 15:38:50 +00:00
|
|
|
COPY . .
|
|
|
|
|
|
|
|
# arguments to pass on each go tool link invocation
|
2023-02-23 17:49:45 +00:00
|
|
|
ENV LDFLAGS="-s -w -X gh.tarampamp.am/error-pages/internal/version.version=$APP_VERSION"
|
2021-09-29 15:38:50 +00:00
|
|
|
|
2023-09-03 16:16:50 +00:00
|
|
|
# build the application
|
2021-09-29 15:38:50 +00:00
|
|
|
RUN set -x \
|
|
|
|
&& CGO_ENABLED=0 go build -trimpath -ldflags "$LDFLAGS" -o ./error-pages ./cmd/error-pages/ \
|
2023-01-29 10:54:56 +00:00
|
|
|
&& ./error-pages --version \
|
2021-09-29 15:38:50 +00:00
|
|
|
&& ./error-pages -h
|
|
|
|
|
2021-04-13 13:55:03 +00:00
|
|
|
WORKDIR /tmp/rootfs
|
2021-09-29 15:38:50 +00:00
|
|
|
|
|
|
|
# prepare rootfs for runtime
|
2020-07-08 11:12:21 +00:00
|
|
|
RUN set -x \
|
2021-04-13 13:55:03 +00:00
|
|
|
&& mkdir -p \
|
2021-09-29 15:38:50 +00:00
|
|
|
./etc \
|
|
|
|
./bin \
|
|
|
|
./opt/html \
|
|
|
|
&& echo 'appuser:x:10001:10001::/nonexistent:/sbin/nologin' > ./etc/passwd \
|
|
|
|
&& echo 'appuser:x:10001:' > ./etc/group \
|
|
|
|
&& mv /src/error-pages ./bin/error-pages \
|
|
|
|
&& mv /src/templates ./opt/templates \
|
2022-01-27 12:29:49 +00:00
|
|
|
&& rm ./opt/templates/*.md \
|
2021-09-29 15:38:50 +00:00
|
|
|
&& mv /src/error-pages.yml ./opt/error-pages.yml
|
|
|
|
|
|
|
|
WORKDIR /tmp/rootfs/opt
|
|
|
|
|
|
|
|
# generate static error pages (for usage inside another docker images, for example)
|
|
|
|
RUN set -x \
|
2023-01-29 10:54:56 +00:00
|
|
|
&& ./../bin/error-pages --verbose build --config-file ./error-pages.yml --index ./html \
|
2021-09-29 15:38:50 +00:00
|
|
|
&& ls -l ./html
|
|
|
|
|
|
|
|
# use empty filesystem
|
2023-09-03 16:17:07 +00:00
|
|
|
FROM scratch AS runtime
|
2021-09-29 15:38:50 +00:00
|
|
|
|
|
|
|
ARG APP_VERSION="undefined@docker"
|
2020-07-08 11:12:21 +00:00
|
|
|
|
2021-04-13 13:55:03 +00:00
|
|
|
LABEL \
|
|
|
|
# Docs: <https://github.com/opencontainers/image-spec/blob/master/annotations.md>
|
|
|
|
org.opencontainers.image.title="error-pages" \
|
2021-09-29 15:38:50 +00:00
|
|
|
org.opencontainers.image.description="Static server error pages in the docker image" \
|
2021-04-13 13:55:03 +00:00
|
|
|
org.opencontainers.image.url="https://github.com/tarampampam/error-pages" \
|
|
|
|
org.opencontainers.image.source="https://github.com/tarampampam/error-pages" \
|
|
|
|
org.opencontainers.image.vendor="tarampampam" \
|
2021-09-29 15:38:50 +00:00
|
|
|
org.opencontainers.version="$APP_VERSION" \
|
2021-04-13 13:55:03 +00:00
|
|
|
org.opencontainers.image.licenses="MIT"
|
2020-07-08 11:12:21 +00:00
|
|
|
|
2021-04-13 13:55:03 +00:00
|
|
|
# Import from builder
|
2023-09-03 16:17:07 +00:00
|
|
|
COPY --from=compiler /tmp/rootfs /
|
2021-04-13 16:51:23 +00:00
|
|
|
|
2021-09-29 15:38:50 +00:00
|
|
|
# Use an unprivileged user
|
2022-04-09 15:39:52 +00:00
|
|
|
USER 10001:10001
|
2021-09-29 15:38:50 +00:00
|
|
|
|
|
|
|
WORKDIR /opt
|
|
|
|
|
|
|
|
ENV LISTEN_PORT="8080" \
|
2021-10-06 17:38:00 +00:00
|
|
|
TEMPLATE_NAME="ghost" \
|
2022-01-03 16:51:30 +00:00
|
|
|
DEFAULT_ERROR_PAGE="404" \
|
2022-01-27 12:29:49 +00:00
|
|
|
DEFAULT_HTTP_CODE="404" \
|
2022-04-12 10:34:35 +00:00
|
|
|
SHOW_DETAILS="false" \
|
2023-11-20 08:27:40 +00:00
|
|
|
DISABLE_L10N="false" \
|
|
|
|
READ_BUFFER_SIZE="2048"
|
2021-09-29 15:38:50 +00:00
|
|
|
|
2021-09-06 06:47:10 +00:00
|
|
|
# Docs: <https://docs.docker.com/engine/reference/builder/#healthcheck>
|
2023-01-29 10:54:56 +00:00
|
|
|
HEALTHCHECK --interval=7s --timeout=2s CMD ["/bin/error-pages", "--log-json", "healthcheck"]
|
2021-09-06 06:47:10 +00:00
|
|
|
|
2021-09-29 15:38:50 +00:00
|
|
|
ENTRYPOINT ["/bin/error-pages"]
|
|
|
|
|
2023-01-29 10:54:56 +00:00
|
|
|
CMD ["--log-json", "serve"]
|