blocky/Dockerfile

72 lines
1.7 KiB
Docker
Raw Normal View History

2022-09-14 13:41:44 +02:00
# prepare build environment
2022-09-14 21:15:35 +02:00
FROM --platform=$BUILDPLATFORM golang:1-alpine AS build
2022-09-14 20:58:17 +02:00
ARG VERSION
ARG BUILD_TIME
ARG TARGETOS
ARG TARGETARCH
2022-09-14 14:04:25 +02:00
# add blocky user
RUN adduser -S -D -H -h /app -s /sbin/nologin blocky
RUN tail -n 1 /etc/passwd > /tmp/blocky_passwd
# add packages
2020-01-12 18:23:35 +01:00
RUN apk add --no-cache \
2022-09-08 22:34:08 +02:00
build-base \
linux-headers \
coreutils \
binutils \
libtool \
musl-dev \
2020-01-12 18:23:35 +01:00
git \
make \
gcc \
libc-dev \
zip \
2022-09-08 22:34:08 +02:00
ca-certificates \
libcap
2020-01-12 18:23:35 +01:00
2022-09-14 16:07:38 +02:00
# setup environment
ENV CGO_ENABLED=0
2022-09-14 13:41:44 +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
ADD . .
2022-09-14 20:58:17 +02:00
RUN go generate ./...
2020-01-12 18:23:35 +01:00
# build binary
2022-09-14 21:21:38 +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 \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
2022-09-14 17:06:45 +02:00
go build \
2022-09-14 13:53:13 +02:00
-tags static \
-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-14 16:07:38 +02:00
-o /go/src/bin/blocky
2022-09-14 13:53:13 +02:00
2022-09-14 16:07:38 +02:00
RUN setcap 'cap_net_bind_service=+ep' /go/src/bin/blocky && \
chown blocky /go/src/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
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-14 20:59:44 +02:00
COPY --from=build /tmp/blocky_passwd /etc/passwd
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2022-09-14 16:07:38 +02:00
COPY --from=build /go/src/bin/blocky /app/blocky
2020-02-10 22:39:16 +01:00
USER blocky
2020-04-08 23:03:07 +02:00
WORKDIR /app
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"]