Skip to content

Commit

Permalink
Refactor GitHub Actions workflow to optimize
Browse files Browse the repository at this point in the history
Docker image building and pushing
  • Loading branch information
n4ze3m committed Nov 18, 2023
1 parent 0a7bb4d commit 2c4b188
Showing 1 changed file with 7 additions and 63 deletions.
70 changes: 7 additions & 63 deletions .github/workflows/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,12 @@ on:
push:
branches: [ next ]

env:
REGISTRY_IMAGE: n4z3m/dialoqbase-next

jobs:
build:
docker:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: type=sha,prefix=latest
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -33,54 +18,13 @@ jobs:
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PWD }}
- name: Build and push by digest
id: docker_build
password: ${{ secrets.DOCKERHUB_PWD }}
- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: ${{ matrix.platform }}
tags: |
n4z3m/dialoqbase-next:latest
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Export digest
run: |
echo "${{ steps.docker_build.outputs.digest }}" > digest.txt
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: digest.txt
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs: [ build ]
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: type=semver,pattern={{version}}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PWD }}
- name: Create manifest list and push
run: |
while IFS= read -r digest; do
docker buildx imagetools create -t ${{ env.REGISTRY_IMAGE }}:latest ${{ env.REGISTRY_IMAGE }}@${digest}
done < digests
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:latest
cache-to: type=gha,mode=max

0 comments on commit 2c4b188

Please sign in to comment.