-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (44 loc) · 1.79 KB
/
Dockerfile
File metadata and controls
57 lines (44 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Multi-stage build with explicit platform specification
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
WORKDIR /build
ARG VERSION=main
ARG TARGETOS=linux
ARG TARGETARCH
WORKDIR /go/src/app
RUN apk add --no-cache upx ca-certificates tzdata
ENV CGO_ENABLED=0 \
GOOS=linux
# Copy only module files first to maximize layer caching for deps.
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
# Now copy the rest of the source code.
COPY . .
# Build args should be as late as possible so they don't bust the deps cache.
ARG BUILD="N/A"
RUN CGO_ENABLED=0 \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
go build -a -installsuffix cgo \
-ldflags="-w -s -X github.com/bakito/adguardhome-sync/version.Version=${VERSION} -X github.com/bakito/adguardhome-sync/version.Build=${BUILD}" \
-o adguardhome-sync .
RUN go version && upx -q adguardhome-sync
# application image
FROM scratch
ARG VERSION=main
ARG BUILD="N/A"
WORKDIR /opt/go
LABEL org.opencontainers.image.title="adguardhome-sync" \
org.opencontainers.image.description="Sync AdGuard Home configuration between instances" \
org.opencontainers.image.url="https://github.com/bakito/adguardhome-sync" \
org.opencontainers.image.source="https://github.com/bakito/adguardhome-sync" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.created="${BUILD}" \
org.opencontainers.image.authors="bakito <github@bakito.ch>"
EXPOSE 8080
ENTRYPOINT ["/opt/go/adguardhome-sync"]
CMD ["run", "--config", "/config/adguardhome-sync.yaml"]
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /usr/share/zoneinfo/ /usr/share/zoneinfo/
COPY --from=builder /go/src/app/adguardhome-sync /opt/go/adguardhome-sync
USER 1001