mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
builds(ci): containers build additional architectures (#1265)
* refactor(dockerfile): optimize Docker builds Combined multiple run commands into single statements in both main and CI dockerfiles, leveraging Docker's caching mechanism more effectively. This change aims to reduce image size and build time. * hmm. * Update ci.Dockerfile * newline * what about this * three quorum members, three opinions * true believer, right? * when needed * it sounds like music * equals what * really though, what? * which one of you is the captain * is that Kwejian whiskey * ARG * ARGH * k. * take me to your leader * asd * Update ci.Dockerfile * try cache * Revert * Run Seperate platforms * docker_build * mother * aggressive elephant * leave me to my bath * introduce buildx cache * czechout manifests * front left paw * kill tags * dealing with a child * Update release.yml * try outputs * consolidation * - = * oxygen depleted * where's the soup * thanks buildx * what's a little avx among friends * Fine, I'll bring my own matches * zenuuuu * space, the final frontier * but why * ARE YOU HAPPY NOW * link those binaries * fast fail * just the time killer you need * add back generic arm * ruthless dictator barbie * kat * build: docker add more labels --------- Co-authored-by: Kyle Sanderson <kyle.leet@gmail.com> Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
This commit is contained in:
parent
1563ce5e9f
commit
4884fec89c
3 changed files with 107 additions and 62 deletions
131
.github/workflows/release.yml
vendored
131
.github/workflows/release.yml
vendored
|
@ -9,6 +9,10 @@ on:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
REGISTRY_IMAGE: ghcr.io/autobrr/autobrr
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
packages: write
|
packages: write
|
||||||
|
@ -64,7 +68,7 @@ jobs:
|
||||||
POSTGRES_USER: testdb
|
POSTGRES_USER: testdb
|
||||||
POSTGRES_PASSWORD: testdb
|
POSTGRES_PASSWORD: testdb
|
||||||
POSTGRES_DB: autobrr
|
POSTGRES_DB: autobrr
|
||||||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
options: --health-cmd pg_isready --health-interval 1s --health-timeout 5s --health-retries 60
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
@ -82,8 +86,7 @@ jobs:
|
||||||
run: go test -v ./...
|
run: go test -v ./...
|
||||||
|
|
||||||
goreleaserbuild:
|
goreleaserbuild:
|
||||||
name: Build Go binaries
|
name: Build distribution binaries
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
needs: [web, test]
|
needs: [web, test]
|
||||||
steps:
|
steps:
|
||||||
|
@ -106,50 +109,17 @@ jobs:
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
- name: Run GoReleaser build
|
- name: Run GoReleaser build
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
uses: goreleaser/goreleaser-action@v5
|
uses: goreleaser/goreleaser-action@v5
|
||||||
with:
|
with:
|
||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
version: latest
|
version: latest
|
||||||
args: release --clean --skip-validate --skip-publish --parallelism 5
|
args: release --clean --skip=validate --skip=publish --parallelism 5
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Upload assets
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: autobrr
|
|
||||||
path: |
|
|
||||||
dist/*.tar.gz
|
|
||||||
dist/*.zip
|
|
||||||
dist/*.apk
|
|
||||||
dist/*.deb
|
|
||||||
dist/*.rpm
|
|
||||||
|
|
||||||
goreleaser:
|
|
||||||
name: Build and publish binaries
|
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [web, test]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Download web production build
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: web-dist
|
|
||||||
path: web/dist
|
|
||||||
|
|
||||||
# 1.20 is the last version to support Windows < 10, Server < 2016, and MacOS < 1.15.
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.20.12'
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: Run GoReleaser build and publish tags
|
- name: Run GoReleaser build and publish tags
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
uses: goreleaser/goreleaser-action@v5
|
uses: goreleaser/goreleaser-action@v5
|
||||||
with:
|
with:
|
||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
|
@ -170,8 +140,24 @@ jobs:
|
||||||
dist/*.rpm
|
dist/*.rpm
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
name: Build and publish Docker images
|
name: Build Docker images
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- linux/386
|
||||||
|
- linux/amd64
|
||||||
|
- linux/amd64/v2
|
||||||
|
- linux/amd64/v3
|
||||||
|
- linux/arm/v6
|
||||||
|
- linux/arm/v7
|
||||||
|
- linux/arm64
|
||||||
|
# - linux/mips64le
|
||||||
|
# - linux/mips64
|
||||||
|
- linux/ppc64le
|
||||||
|
# - linux/riscv64
|
||||||
|
- linux/s390x
|
||||||
needs: [web, test]
|
needs: [web, test]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
@ -188,7 +174,7 @@ jobs:
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
@ -196,7 +182,7 @@ jobs:
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/autobrr/autobrr
|
images: ${{ env.REGISTRY_IMAGE }}
|
||||||
tags: |
|
tags: |
|
||||||
type=semver,pattern={{raw}}
|
type=semver,pattern={{raw}}
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
|
@ -208,20 +194,71 @@ jobs:
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Supported Architectures
|
||||||
|
run: docker buildx ls
|
||||||
|
|
||||||
- name: Build and publish image
|
- name: Build and publish image
|
||||||
id: docker_build
|
id: docker_build
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./ci.Dockerfile
|
file: ./ci.Dockerfile
|
||||||
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
|
platforms: ${{ matrix.platform }}
|
||||||
push: ${{ github.event.pull_request.head.repo.full_name == 'autobrr/autobrr' || github.event_name != 'pull_request' }}
|
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
build-args: |
|
build-args: |
|
||||||
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
|
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
|
||||||
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
|
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
|
||||||
REVISION=${{ github.event.pull_request.head.sha }}
|
REVISION=${{ github.event.pull_request.head.sha }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
- name: Export digest
|
||||||
|
run: |
|
||||||
|
mkdir -p /tmp/digests
|
||||||
|
digest="${{ steps.docker_build.outputs.digest }}"
|
||||||
|
touch "/tmp/digests/${digest#sha256:}"
|
||||||
|
- name: Upload digest
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: digests
|
||||||
|
path: /tmp/digests/*
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
- name: Image digest
|
docker-merge:
|
||||||
run: echo ${{ steps.docker_build.outputs.digest }}
|
name: Publish Docker multi-arch manifest
|
||||||
|
if: ${{ github.event.pull_request.head.repo.full_name == 'autobrr/autobrr' || github.event_name != 'pull_request' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [docker, test]
|
||||||
|
steps:
|
||||||
|
- name: Download digests
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: digests
|
||||||
|
path: /tmp/digests
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY_IMAGE }}
|
||||||
|
|
||||||
|
- name: Create manifest list and push
|
||||||
|
working-directory: /tmp/digests
|
||||||
|
run: |
|
||||||
|
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
||||||
|
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
|
||||||
|
|
||||||
|
- name: Inspect image
|
||||||
|
run: |
|
||||||
|
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
|
||||||
|
|
|
@ -33,8 +33,8 @@ COPY --from=web-builder /web/build.go ./web
|
||||||
#ENV GOOS=linux
|
#ENV GOOS=linux
|
||||||
#ENV CGO_ENABLED=0
|
#ENV CGO_ENABLED=0
|
||||||
|
|
||||||
RUN go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrr cmd/autobrr/main.go
|
RUN go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrr cmd/autobrr/main.go && \
|
||||||
RUN go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrrctl cmd/autobrrctl/main.go
|
go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o bin/autobrrctl cmd/autobrrctl/main.go
|
||||||
|
|
||||||
# build runner
|
# build runner
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
|
@ -1,30 +1,38 @@
|
||||||
# build app
|
# build app
|
||||||
FROM --platform=$BUILDPLATFORM golang:1.20-alpine3.19 AS app-builder
|
FROM --platform=$BUILDPLATFORM golang:1.20-alpine3.19 AS app-builder
|
||||||
|
|
||||||
RUN apk add --no-cache git tzdata
|
RUN apk add --no-cache git tzdata
|
||||||
|
|
||||||
ENV SERVICE=autobrr
|
ENV SERVICE=autobrr
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY . ./
|
|
||||||
|
|
||||||
RUN --mount=target=. \
|
# Cache Go modules
|
||||||
go mod download
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY . ./
|
||||||
|
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
ARG REVISION=dev
|
ARG REVISION=dev
|
||||||
ARG BUILDTIME
|
ARG BUILDTIME
|
||||||
ARG TARGETOS TARGETARCH
|
ARG TARGETOS TARGETARCH TARGETVARIANT
|
||||||
|
|
||||||
RUN --mount=target=. \
|
RUN --network=none --mount=target=. \
|
||||||
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrr cmd/autobrr/main.go
|
export GOOS=$TARGETOS; \
|
||||||
RUN --mount=target=. \
|
export GOARCH=$TARGETARCH; \
|
||||||
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrrctl cmd/autobrrctl/main.go
|
[[ "$GOARCH" == "amd64" ]] && export GOAMD64=$TARGETVARIANT; \
|
||||||
|
[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v6" ]] && export GOARM=6; \
|
||||||
|
[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v7" ]] && export GOARM=7; \
|
||||||
|
echo $GOARCH $GOOS $GOARM$GOAMD64; \
|
||||||
|
go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrr cmd/autobrr/main.go && \
|
||||||
|
go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/autobrrctl cmd/autobrrctl/main.go
|
||||||
|
|
||||||
# build runner
|
# build runner
|
||||||
FROM alpine:latest
|
FROM alpine:latest AS runner
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source = "https://github.com/autobrr/autobrr"
|
LABEL org.opencontainers.image.source = "https://github.com/autobrr/autobrr"
|
||||||
|
LABEL org.opencontainers.image.licenses = "GPL-2.0-or-later"
|
||||||
|
LABEL org.opencontainers.image.base.name = "alpine:latest"
|
||||||
|
|
||||||
ENV HOME="/config" \
|
ENV HOME="/config" \
|
||||||
XDG_CONFIG_HOME="/config" \
|
XDG_CONFIG_HOME="/config" \
|
||||||
|
@ -35,7 +43,7 @@ RUN apk --no-cache add ca-certificates curl tzdata jq
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
VOLUME /config
|
VOLUME /config
|
||||||
EXPOSE 7474
|
EXPOSE 7474
|
||||||
ENTRYPOINT ["/usr/local/bin/autobrr", "--config", "/config"]
|
|
||||||
|
|
||||||
COPY --from=app-builder /out/bin/autobrr /usr/local/bin/
|
COPY --link --from=app-builder /out/bin/autobrr* /usr/local/bin/
|
||||||
COPY --from=app-builder /out/bin/autobrrctl /usr/local/bin/
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/autobrr", "--config", "/config"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue