2023-10-08 23:34:54 +02:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
2022-10-28 21:42:36 +02:00
|
|
|
# ----------- stage: ca-certs
|
|
|
|
# get newest certificates in seperate stage for caching
|
2024-03-15 22:22:26 +01:00
|
|
|
FROM --platform=$BUILDPLATFORM alpine:3 AS ca-certs
|
|
|
|
RUN --mount=type=cache,target=/var/cache/apk \
|
|
|
|
apk update && \
|
|
|
|
apk add ca-certificates
|
2022-10-21 23:59:02 +02:00
|
|
|
|
|
|
|
# update certificates and use the apk ones if update fails
|
2022-09-20 19:24:00 +02:00
|
|
|
RUN --mount=type=cache,target=/etc/ssl/certs \
|
2023-10-03 18:12:24 +02:00
|
|
|
update-ca-certificates 2>/dev/null || true
|
2022-09-20 18:57:02 +02:00
|
|
|
|
2022-10-28 21:42:36 +02:00
|
|
|
# ----------- stage: build
|
2023-10-03 18:12:24 +02:00
|
|
|
FROM --platform=$BUILDPLATFORM ghcr.io/kwitsch/ziggoimg AS build
|
2022-09-14 20:58:17 +02:00
|
|
|
|
2022-10-21 23:59:02 +02:00
|
|
|
# required arguments
|
2022-09-14 20:58:17 +02:00
|
|
|
ARG VERSION
|
|
|
|
ARG BUILD_TIME
|
2022-10-21 23:59:02 +02:00
|
|
|
|
2022-09-17 13:20:25 +02:00
|
|
|
# download packages
|
2024-03-15 22:22:26 +01:00
|
|
|
# bind mount go.mod and go.sum
|
|
|
|
# use cache for go packages
|
|
|
|
RUN --mount=type=bind,source=go.sum,target=go.sum \
|
|
|
|
--mount=type=bind,source=go.mod,target=go.mod \
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
--mount=type=cache,target=/go/pkg \
|
2023-10-03 18:12:24 +02:00
|
|
|
go mod download
|
2022-09-16 18:45:50 +02:00
|
|
|
|
2023-10-03 18:12:24 +02:00
|
|
|
# setup go
|
|
|
|
ENV GO_SKIP_GENERATE=1\
|
|
|
|
GO_BUILD_FLAGS="-tags static -v " \
|
|
|
|
BIN_USER=100\
|
|
|
|
BIN_AUTOCAB=1 \
|
|
|
|
BIN_OUT_DIR="/bin"
|
2022-10-11 16:16:20 +02:00
|
|
|
|
2022-09-20 16:54:17 +02:00
|
|
|
# build binary
|
2024-03-15 22:22:26 +01:00
|
|
|
# bind mount source code
|
|
|
|
# use cache for go packages
|
2022-09-20 19:32:47 +02:00
|
|
|
RUN --mount=type=bind,target=. \
|
2023-10-03 18:12:24 +02:00
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
--mount=type=cache,target=/go/pkg \
|
|
|
|
make build
|
2022-09-08 22:34:08 +02:00
|
|
|
|
2022-10-28 21:42:36 +02:00
|
|
|
# ----------- stage: final
|
2022-09-08 22:34:08 +02:00
|
|
|
FROM scratch
|
2020-11-22 22:26:15 +01:00
|
|
|
|
2023-10-07 22:22:23 +02:00
|
|
|
ARG VERSION
|
|
|
|
ARG BUILD_TIME
|
2023-10-08 23:34:54 +02:00
|
|
|
ARG DOC_PATH
|
2023-10-07 22:22:23 +02:00
|
|
|
|
|
|
|
LABEL org.opencontainers.image.title="blocky" \
|
|
|
|
org.opencontainers.image.vendor="0xERR0R" \
|
|
|
|
org.opencontainers.image.licenses="Apache-2.0" \
|
2023-10-08 23:34:54 +02:00
|
|
|
org.opencontainers.image.version="${VERSION}" \
|
|
|
|
org.opencontainers.image.created="${BUILD_TIME}" \
|
2023-10-07 22:22:23 +02:00
|
|
|
org.opencontainers.image.description="Fast and lightweight DNS proxy as ad-blocker for local network with many features" \
|
|
|
|
org.opencontainers.image.url="https://github.com/0xERR0R/blocky#readme" \
|
|
|
|
org.opencontainers.image.source="https://github.com/0xERR0R/blocky" \
|
2023-10-08 23:34:54 +02:00
|
|
|
org.opencontainers.image.documentation="https://0xerr0r.github.io/blocky/${DOC_PATH}/"
|
2023-10-07 22:22:23 +02:00
|
|
|
|
|
|
|
|
2020-11-22 22:26:15 +01:00
|
|
|
|
2022-10-11 16:16:20 +02:00
|
|
|
USER 100
|
2022-09-15 09:20:03 +02:00
|
|
|
WORKDIR /app
|
|
|
|
|
2023-10-08 23:34:54 +02:00
|
|
|
COPY --link --from=ca-certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
|
|
COPY --link --from=build /bin/blocky /app/blocky
|
2022-09-15 09:20:03 +02:00
|
|
|
|
2022-09-08 22:34:08 +02:00
|
|
|
ENV BLOCKY_CONFIG_FILE=/app/config.yml
|
|
|
|
|
|
|
|
ENTRYPOINT ["/app/blocky"]
|
|
|
|
|
2022-11-24 21:54:52 +01:00
|
|
|
HEALTHCHECK --start-period=1m --timeout=3s CMD ["/app/blocky", "healthcheck"]
|