2022-10-28 21:42:36 +02:00
|
|
|
# ----------- stage: ca-certs
|
|
|
|
# get newest certificates in seperate stage for caching
|
2022-09-20 19:24:00 +02:00
|
|
|
FROM --platform=$BUILDPLATFORM alpine:3.16 AS ca-certs
|
|
|
|
RUN apk add --no-cache 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 \
|
|
|
|
update-ca-certificates 2>/dev/null || true
|
|
|
|
|
2022-10-28 21:42:36 +02:00
|
|
|
# ----------- stage: zig-env
|
|
|
|
# zig compiler is used for CGO cross compilation
|
|
|
|
# even though CGO is disabled it is used in the os and net package
|
2022-09-20 10:44:56 +02:00
|
|
|
FROM --platform=$BUILDPLATFORM ghcr.io/euantorano/zig:master AS zig-env
|
2022-09-20 18:57:02 +02:00
|
|
|
|
2022-10-28 21:42:36 +02:00
|
|
|
# ----------- stage: build
|
2022-09-19 23:18:06 +02:00
|
|
|
FROM --platform=$BUILDPLATFORM golang:1-alpine 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
|
|
|
|
|
|
|
# auto provided by Docker
|
|
|
|
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
|
2022-09-14 20:58:17 +02:00
|
|
|
ARG TARGETOS
|
|
|
|
ARG TARGETARCH
|
2022-09-16 09:57:21 +02:00
|
|
|
ARG TARGETVARIANT
|
2022-09-14 14:04:25 +02:00
|
|
|
|
2022-09-14 16:07:38 +02:00
|
|
|
# set working directory
|
|
|
|
WORKDIR /go/src
|
2020-01-12 18:23:35 +01:00
|
|
|
|
2022-09-17 13:20:25 +02:00
|
|
|
# download packages
|
2022-09-16 18:45:50 +02:00
|
|
|
COPY go.mod go.sum ./
|
2022-09-16 10:09:02 +02:00
|
|
|
RUN --mount=type=cache,target=/go/pkg \
|
2022-09-16 18:45:50 +02:00
|
|
|
go mod download
|
|
|
|
|
2022-09-17 13:20:25 +02:00
|
|
|
# add source
|
|
|
|
COPY . .
|
2022-09-16 10:09:02 +02:00
|
|
|
|
2022-10-28 21:42:36 +02:00
|
|
|
# setup go & zig as CGO compiler
|
2022-09-20 16:54:17 +02:00
|
|
|
COPY --from=zig-env /usr/local/bin/zig /usr/local/bin/zig
|
2022-10-21 20:56:26 +02:00
|
|
|
ENV PATH="/usr/local/bin/zig:${PATH}" \
|
|
|
|
CC="zigcc" \
|
2022-09-20 10:56:38 +02:00
|
|
|
CXX="zigcpp" \
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
GOOS="linux" \
|
2022-10-21 20:56:26 +02:00
|
|
|
GOARCH=$TARGETARCH \
|
|
|
|
GO_SKIP_GENERATE=1\
|
|
|
|
GO_BUILD_FLAGS="-tags static -v " \
|
|
|
|
BIN_USER=100\
|
|
|
|
BIN_AUTOCAB=1 \
|
|
|
|
BIN_OUT_DIR="/bin"
|
2022-09-20 10:44:56 +02:00
|
|
|
|
2022-10-28 21:42:36 +02:00
|
|
|
# add make & libcap
|
2022-10-21 20:56:26 +02:00
|
|
|
RUN apk add --no-cache make libcap
|
2022-10-11 16:16:20 +02:00
|
|
|
|
2022-09-20 16:54:17 +02:00
|
|
|
# build binary
|
2022-09-20 19:32:47 +02:00
|
|
|
RUN --mount=type=bind,target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
2022-09-14 20:58:17 +02:00
|
|
|
--mount=type=cache,target=/go/pkg \
|
2022-10-21 23:59:02 +02:00
|
|
|
make build GOARM=${TARGETVARIANT##*v}
|
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
|
|
|
|
2022-09-20 18:57:02 +02:00
|
|
|
LABEL org.opencontainers.image.source="https://github.com/0xERR0R/blocky" \
|
|
|
|
org.opencontainers.image.url="https://github.com/0xERR0R/blocky" \
|
|
|
|
org.opencontainers.image.title="DNS proxy as ad-blocker for local network"
|
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
|
|
|
|
|
2022-09-20 19:24:00 +02:00
|
|
|
COPY --from=ca-certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
2022-09-15 09:20:03 +02:00
|
|
|
COPY --from=build /bin/blocky /app/blocky
|
|
|
|
|
2022-09-08 22:34:08 +02:00
|
|
|
ENV BLOCKY_CONFIG_FILE=/app/config.yml
|
|
|
|
|
|
|
|
ENTRYPOINT ["/app/blocky"]
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=1m --timeout=3s CMD ["/app/blocky", "healthcheck"]
|