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:
soup 2023-12-25 19:41:33 +01:00 committed by GitHub
parent 1563ce5e9f
commit 4884fec89c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 62 deletions

View file

@ -9,6 +9,10 @@ on:
- 'v*'
pull_request:
env:
REGISTRY: ghcr.io
REGISTRY_IMAGE: ghcr.io/autobrr/autobrr
permissions:
contents: write
packages: write
@ -64,7 +68,7 @@ jobs:
POSTGRES_USER: testdb
POSTGRES_PASSWORD: testdb
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:
- name: Checkout
uses: actions/checkout@v4
@ -82,8 +86,7 @@ jobs:
run: go test -v ./...
goreleaserbuild:
name: Build Go binaries
if: github.event_name == 'pull_request'
name: Build distribution binaries
runs-on: windows-latest
needs: [web, test]
steps:
@ -106,50 +109,17 @@ jobs:
cache: true
- name: Run GoReleaser build
if: github.event_name == 'pull_request'
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean --skip-validate --skip-publish --parallelism 5
args: release --clean --skip=validate --skip=publish --parallelism 5
env:
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
if: startsWith(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
@ -170,8 +140,24 @@ jobs:
dist/*.rpm
docker:
name: Build and publish Docker images
name: Build Docker images
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]
steps:
- name: Checkout
@ -188,7 +174,7 @@ jobs:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
@ -196,7 +182,7 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/autobrr/autobrr
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=semver,pattern={{raw}}
type=ref,event=branch
@ -208,20 +194,71 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Supported Architectures
run: docker buildx ls
- name: Build and publish image
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
file: ./ci.Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
push: ${{ github.event.pull_request.head.repo.full_name == 'autobrr/autobrr' || github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
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
run: echo ${{ steps.docker_build.outputs.digest }}
docker-merge:
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 }}