Split docker builds #192
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
name: Build Multi-Arch Docker Images | |
on: | |
push: | |
branches: | |
- main | |
- cumulusci-next** | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
target: [no-browser, chromedriver, playwright, full-browser] | |
platform: [linux/amd64, linux/arm64] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set environment variables | |
run: | | |
if [ "${{ github.ref_name }}" == "main" ]; then | |
echo "IMAGE_TAG=latest" >> $GITHUB_ENV | |
else | |
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV | |
fi | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: ${{ github.event_name == 'push' }} | |
tags: ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}-${{ matrix.target }} | |
platforms: ${{ matrix.platform }} | |
target: ${{ matrix.target }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
merge-manifests: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set environment variables | |
run: | | |
if [ "${{ github.ref_name }}" == "main" ]; then | |
echo "IMAGE_TAG=latest" >> $GITHUB_ENV | |
else | |
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV | |
fi | |
- name: Create and push multi-arch manifests | |
run: | | |
for target in no-browser chromedriver playwright full-browser; do | |
docker buildx imagetools create -t ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}-${target} \ | |
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}-${target}-linux-amd64 \ | |
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}-${target}-linux-arm64 | |
done |