mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-08-26 10:56:33 +00:00
rework docker builds
This commit is contained in:
+35
-10
@@ -13,6 +13,7 @@ before:
|
||||
builds:
|
||||
- id: other
|
||||
main: ./cmd/backrest
|
||||
binary: backrest
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
@@ -25,6 +26,7 @@ builds:
|
||||
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
|
||||
- id: linux
|
||||
main: ./cmd/backrest
|
||||
binary: backrest
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
@@ -33,10 +35,28 @@ builds:
|
||||
- amd64
|
||||
- arm64
|
||||
- arm
|
||||
goarm:
|
||||
- 6
|
||||
ldflags:
|
||||
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
|
||||
- id: docker-entrypoint
|
||||
main: ./cmd/docker-entrypoint
|
||||
binary: docker-entrypoint
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
- arm
|
||||
goarm:
|
||||
- 6
|
||||
ldflags:
|
||||
- -s -w
|
||||
- id: windows
|
||||
main: ./cmd/backrest
|
||||
binary: backrest
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
goos:
|
||||
@@ -76,8 +96,9 @@ dockers:
|
||||
build_flag_templates:
|
||||
- "--pull"
|
||||
- "--platform=linux/amd64"
|
||||
extra_files:
|
||||
- ./
|
||||
ids:
|
||||
- linux
|
||||
- docker-entrypoint
|
||||
|
||||
- image_templates:
|
||||
- garethgeorge/backrest:{{ .Tag }}-alpine-arm64
|
||||
@@ -88,8 +109,9 @@ dockers:
|
||||
build_flag_templates:
|
||||
- "--pull"
|
||||
- "--platform=linux/arm64/v8"
|
||||
extra_files:
|
||||
- ./
|
||||
ids:
|
||||
- linux
|
||||
- docker-entrypoint
|
||||
|
||||
- image_templates:
|
||||
- garethgeorge/backrest:{{ .Tag }}-scratch-arm64
|
||||
@@ -100,8 +122,9 @@ dockers:
|
||||
build_flag_templates:
|
||||
- "--pull"
|
||||
- "--platform=linux/arm64/v8"
|
||||
extra_files:
|
||||
- ./
|
||||
ids:
|
||||
- linux
|
||||
- docker-entrypoint
|
||||
|
||||
- image_templates:
|
||||
- garethgeorge/backrest:{{ .Tag }}-scratch-amd64
|
||||
@@ -111,8 +134,9 @@ dockers:
|
||||
build_flag_templates:
|
||||
- "--pull"
|
||||
- "--platform=linux/amd64"
|
||||
extra_files:
|
||||
- ./
|
||||
ids:
|
||||
- linux
|
||||
- docker-entrypoint
|
||||
|
||||
- image_templates:
|
||||
- garethgeorge/backrest:{{ .Tag }}-scratch-armv6
|
||||
@@ -125,8 +149,9 @@ dockers:
|
||||
- "--pull"
|
||||
- "--provenance=false"
|
||||
- "--platform=linux/arm/v6"
|
||||
extra_files:
|
||||
- ./
|
||||
ids:
|
||||
- linux
|
||||
- docker-entrypoint
|
||||
|
||||
docker_manifests:
|
||||
- name_template: "garethgeorge/backrest:latest"
|
||||
|
||||
+3
-33
@@ -1,41 +1,11 @@
|
||||
# Stage 1: Web Builder
|
||||
FROM node:24-alpine AS web-builder
|
||||
WORKDIR /src
|
||||
COPY webui ./webui
|
||||
WORKDIR /src/webui
|
||||
RUN npm install -g pnpm
|
||||
RUN pnpm install
|
||||
RUN pnpm run build
|
||||
|
||||
# Stage 2: Go Builder
|
||||
FROM golang:1.24-alpine AS builder
|
||||
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
# Copy built web assets from web-builder to where go embed expects them
|
||||
COPY --from=web-builder /src/webui/dist ./webui/dist
|
||||
|
||||
# Magic Args provided by Docker Buildx
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG VERSION
|
||||
|
||||
# Build using the args to cross-compile FAST
|
||||
# We map Docker's args to Go's args
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
||||
go build -ldflags="-s -w -X main.version=${VERSION}" -o /backrest ./cmd/backrest
|
||||
|
||||
RUN go build -o /docker-entrypoint -ldflags "-s -w" ./cmd/docker-entrypoint
|
||||
|
||||
# Stage 3: Final Image
|
||||
FROM alpine:latest
|
||||
LABEL org.opencontainers.image.source="https://github.com/garethgeorge/backrest"
|
||||
RUN apk --no-cache add tini ca-certificates curl bash rclone openssh tzdata docker-cli
|
||||
RUN mkdir -p /tmp
|
||||
|
||||
# Copy the binary we built
|
||||
COPY --from=builder /backrest /backrest
|
||||
COPY --from=builder /docker-entrypoint /docker-entrypoint
|
||||
# Copy the binary we built via goreleaser
|
||||
COPY backrest /backrest
|
||||
COPY docker-entrypoint /docker-entrypoint
|
||||
|
||||
# Run the binary to install dependencies (may run via QEMU but necessary)
|
||||
RUN /backrest --install-deps-only
|
||||
|
||||
+7
-39
@@ -1,49 +1,17 @@
|
||||
# Stage 1: Web Builder
|
||||
FROM node:24-alpine AS web-builder
|
||||
WORKDIR /src
|
||||
COPY webui ./webui
|
||||
WORKDIR /src/webui
|
||||
RUN npm install -g pnpm
|
||||
RUN pnpm install
|
||||
RUN pnpm run build
|
||||
|
||||
# Stage 2: Go Builder
|
||||
FROM golang:1.24-alpine AS builder
|
||||
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
# Copy built web assets from web-builder to where go embed expects them
|
||||
COPY --from=web-builder /src/webui/dist ./webui/dist
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG TARGETVARIANT
|
||||
ARG VERSION
|
||||
|
||||
# Logic to handle ARMv6 specifically
|
||||
RUN if [ "$TARGETARCH" = "arm" ] && [ "$TARGETVARIANT" = "v6" ]; then \
|
||||
export GOARM=6; \
|
||||
fi; \
|
||||
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
||||
go build -ldflags="-s -w -X main.version=${VERSION}" -o /backrest ./cmd/backrest
|
||||
|
||||
RUN go build -o /docker-entrypoint -ldflags "-s -w" ./cmd/docker-entrypoint
|
||||
|
||||
|
||||
# Stage 3: Dependencies (Alpine)
|
||||
# Stage 1: Dependencies (Alpine)
|
||||
FROM alpine:latest AS alpine
|
||||
RUN apk add --no-cache ca-certificates tini-static
|
||||
RUN mkdir /tmp-orig
|
||||
|
||||
# Copy binary to run install-deps
|
||||
COPY --from=builder /backrest /backrest
|
||||
# Copy binary from goreleaser to run install-deps
|
||||
COPY backrest /backrest
|
||||
RUN /backrest --install-deps-only
|
||||
|
||||
# Setup restic path
|
||||
RUN mkdir -p /bin && mv /root/.local/share/backrest/restic /bin/restic
|
||||
|
||||
|
||||
# Stage 4: Final Image (Scratch)
|
||||
# Stage 2: Final Image (Scratch)
|
||||
FROM scratch
|
||||
LABEL org.opencontainers.image.source="https://github.com/garethgeorge/backrest"
|
||||
|
||||
@@ -52,9 +20,9 @@ COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=alpine /bin/restic /bin/restic
|
||||
COPY --from=alpine /sbin/tini-static /tini
|
||||
|
||||
# Copy binaries from builder
|
||||
COPY --from=builder /backrest /backrest
|
||||
COPY --from=builder /docker-entrypoint /docker-entrypoint
|
||||
# Copy binaries from goreleaser
|
||||
COPY backrest /backrest
|
||||
COPY docker-entrypoint /docker-entrypoint
|
||||
|
||||
ENTRYPOINT ["/tini", "--", "/docker-entrypoint"]
|
||||
CMD ["/backrest"]
|
||||
|
||||
Reference in New Issue
Block a user