Skip to content

Commit

Permalink
chore: matrix build-and-push
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPulse committed Apr 1, 2024
1 parent b428caf commit 395d1df
Showing 1 changed file with 61 additions and 15 deletions.
76 changes: 61 additions & 15 deletions .github/workflows/build-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,73 @@ on:
push:
branches:
- main
env:
TMP_LOCAL_IMAGE: localhost:5000/user/app

jobs:
build-and-push:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout repository
uses: actions/checkout@v4


- name: Prepare
run: |
mkdir -p /tmp/images
platform=${{ matrix.platform }}
echo "TARFILE=${platform//\//-}.tar" >> $GITHUB_ENV
echo "TAG=${{ env.TMP_LOCAL_IMAGE }}:${platform//\//-}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
buildkitd-config: ./buildkitd.toml

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
tags: ${{ env.TAG }}
outputs: type=docker,dest=/tmp/images/${{ env.TARFILE }}
secrets: |
SCCACHE_ENDPOINT=${{ secrets.SCCACHE_ENDPOINT }}
SCCACHE_AWS_ACCESS_KEY_ID=${{ secrets.SCCACHE_AWS_ACCESS_KEY_ID }}
SCCACHE_AWS_SECRET_ACCESS_KEY=${{ secrets.SCCACHE_AWS_SECRET_ACCESS_KEY }}
push:
runs-on: ubuntu-latest
needs:
- build
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: actions/download-artifact@v3
with:
name: images
path: /tmp/images

- name: Load images
run: |
for image in /tmp/images/*.tar; do
docker load -i $image
done
- name: Push images to local registry
run: |
docker push -a ${{ env.TMP_LOCAL_IMAGE }}
- name: Login to Harbor
uses: docker/login-action@v3
with:
Expand All @@ -33,15 +86,8 @@ jobs:
tags: |
type=sha,prefix=commit-,format=long
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}
secrets: |
SCCACHE_ENDPOINT=${{ secrets.SCCACHE_ENDPOINT }}
SCCACHE_AWS_ACCESS_KEY_ID=${{ secrets.SCCACHE_AWS_ACCESS_KEY_ID }}
SCCACHE_AWS_SECRET_ACCESS_KEY=${{ secrets.SCCACHE_AWS_SECRET_ACCESS_KEY }}
- name: Create manifest list and push
run: |
docker buildx imagetools create \
$(echo "${{ steps.meta.outputs.tags }}" | tr ',' ' ' | awk '{for(i=1;i<=NF;i++) printf "-t %s ", $i}') \
$(docker image ls --format '{{.Repository}}:{{.Tag}}' '${{ env.TMP_LOCAL_IMAGE }}' | tr '\n' ' ')

0 comments on commit 395d1df

Please sign in to comment.