-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update github workflow to build multi architecture container images
- Loading branch information
1 parent
32415ca
commit ea97631
Showing
1 changed file
with
66 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,82 @@ | ||
name: Docker build and release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
push: | ||
branches: [master,develop] | ||
pull_request: | ||
|
||
jobs: | ||
deploy_image: | ||
name: 'Publish: DockerHub' | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'release' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' | ||
build: | ||
name: 'Build container image' | ||
runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} | ||
outputs: | ||
digest_arm64: ${{ steps.export_digest.outputs.digest_arm64 }} | ||
digest_amd64: ${{ steps.export_digest.outputs.digest_amd64 }} | ||
strategy: | ||
matrix: | ||
platform: | ||
- linux/amd64 | ||
- linux/arm64 | ||
steps: | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: "ghcr.io/${{ github.repository }}" | ||
|
||
- name: Login to GHCR | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Extract branch name | ||
shell: bash | ||
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | ||
id: extract_branch | ||
|
||
- name: Generating release tags and labels | ||
if: github.event_name == 'release' | ||
id: release_meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: jaedb/snapserver | ||
tags: | | ||
latest | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
- name: Generating edge branch labels | ||
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' | ||
id: edge_meta | ||
uses: docker/metadata-action@v4 | ||
- name: Build and push by digest | ||
id: build | ||
uses: docker/build-push-action@v6 | ||
with: | ||
images: jaedb/snapserver | ||
tags: ${{ steps.extract_branch.outputs.branch }} | ||
platforms: ${{ matrix.platform }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=true | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
- name: Export digest | ||
id: export_digest | ||
run: | | ||
arch="$(echo -n ${{ matrix.platform }} | sed -e 's/linux\///')" | ||
digest="${{ steps.build.outputs.digest }}" | ||
echo "digest_${arch}=${digest#sha256:}" >> "$GITHUB_OUTPUT" | ||
merge: | ||
runs-on: "ubuntu-24.04" | ||
needs: | ||
- build | ||
steps: | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
images: ghcr.io/${{ github.repository }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
- name: Login to GHCR | ||
uses: docker/login-action@v3 | ||
with: | ||
push: true | ||
tags: ${{ steps.release_meta.outputs.tags || steps.edge_meta.outputs.tags }} | ||
labels: ${{ steps.release_meta.outputs.labels || steps.edge_meta.outputs.tags }} | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Create manifest list and push | ||
run: | | ||
docker buildx imagetools create \ | ||
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
ghcr.io/${{ github.repository }}@sha256:${{ needs.build.outputs.digest_arm64 }} \ | ||
ghcr.io/${{ github.repository }}@sha256:${{ needs.build.outputs.digest_amd64 }} | ||
- name: Inspect image | ||
run: docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }} |