2022-09-14 13:41:44 +02:00
|
|
|
# prepare build environment
|
2022-09-16 09:57:21 +02:00
|
|
|
FROM --platform=$BUILDPLATFORM ghcr.io/gythialy/golang-cross-builder:v1.19.1-0 AS build
|
2022-09-14 20:58:17 +02:00
|
|
|
|
2022-09-16 16:23:50 +02:00
|
|
|
# required arguments(target will be through buildx)
|
2022-09-14 20:58:17 +02:00
|
|
|
ARG VERSION
|
|
|
|
ARG BUILD_TIME
|
|
|
|
ARG TARGETOS
|
|
|
|
ARG TARGETARCH
|
2022-09-16 09:57:21 +02:00
|
|
|
ARG TARGETVARIANT
|
2022-09-14 14:04:25 +02:00
|
|
|
|
2022-09-16 16:23:50 +02:00
|
|
|
# arguments to environment
|
2022-09-16 17:32:10 +02:00
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
ENV GOOS=$TARGETOS
|
|
|
|
ENV GOARCH=$TARGETARCH
|
2022-09-16 16:03:23 +02:00
|
|
|
|
2022-09-11 19:45:00 +02:00
|
|
|
# add blocky user
|
2022-09-17 12:58:38 +02:00
|
|
|
RUN echo "blocky:x:100:65533:Blocky User,,,:/app:/sbin/nologin" > /tmp/blocky_passwd
|
|
|
|
#adduser -home /app -shell /sbin/nologin blocky && \
|
2022-09-15 09:20:03 +02:00
|
|
|
# tail -n 1 /etc/passwd > /tmp/blocky_passwd
|
2022-09-12 10:33:14 +02:00
|
|
|
|
2022-09-14 16:07:38 +02:00
|
|
|
# set working directory
|
|
|
|
WORKDIR /go/src
|
2020-01-12 18:23:35 +01:00
|
|
|
|
|
|
|
# add source
|
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
|
|
|
|
|
|
|
|
ADD . .
|
2022-09-16 10:09:02 +02:00
|
|
|
|
2022-09-12 10:33:14 +02:00
|
|
|
# build binary
|
2022-09-16 18:36:27 +02:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
2022-09-14 20:58:17 +02:00
|
|
|
--mount=type=cache,target=/go/pkg \
|
2022-09-16 18:36:27 +02:00
|
|
|
chmod +x ./docker/*.sh && \
|
|
|
|
export GOARM=${TARGETVARIANT##*v} && \
|
|
|
|
export CC=$(./docker/getenv_cc.sh) && \
|
2022-09-16 18:36:58 +02:00
|
|
|
./docker/printenv.sh && \
|
2022-09-16 18:45:50 +02:00
|
|
|
go generate ./... && \
|
2022-09-14 17:06:45 +02:00
|
|
|
go build \
|
2022-09-16 11:03:27 +02:00
|
|
|
-tags static,osusergo,netgo \
|
2022-09-14 13:53:13 +02:00
|
|
|
-v \
|
|
|
|
-ldflags="-linkmode external -extldflags -static -X github.com/0xERR0R/blocky/util.Version=${VERSION} -X github.com/0xERR0R/blocky/util.BuildTime=${BUILD_TIME}" \
|
2022-09-15 09:20:03 +02:00
|
|
|
-o /bin/blocky
|
2022-09-16 16:23:50 +02:00
|
|
|
# ,sharing=locked
|
2022-09-14 13:53:13 +02:00
|
|
|
|
2022-09-15 09:20:03 +02:00
|
|
|
RUN setcap 'cap_net_bind_service=+ep' /bin/blocky
|
2022-09-17 12:58:38 +02:00
|
|
|
RUN chown 100 /bin/blocky
|
2022-09-08 22:34:08 +02:00
|
|
|
|
2020-01-12 18:23:35 +01:00
|
|
|
# final stage
|
2022-09-08 22:34:08 +02:00
|
|
|
FROM scratch
|
2020-11-22 22:26:15 +01: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"
|
|
|
|
|
2022-09-15 09:20:03 +02:00
|
|
|
WORKDIR /app
|
|
|
|
|
2022-09-17 12:58:38 +02:00
|
|
|
COPY --from=build /tmp/blocky_passwd /etc/passwd
|
2022-09-14 20:59:44 +02:00
|
|
|
COPY --from=build /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-17 12:58:38 +02:00
|
|
|
USER blocky
|
2020-04-08 23:03:07 +02:00
|
|
|
|
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"]
|