feat: multi architectual split into two jobs #57
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 and Push Docker Images | |
on: | |
push: | |
branches: | |
- '*' | |
workflow_dispatch: | |
inputs: | |
version: | |
default: 'latest' | |
description: 'Version tag for Docker images' | |
required: true | |
env: | |
DOCKERHUB_ORGANIZATION: vleerapp | |
DOCKERHUB_REPOSITORY: vleerapp/backend | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
GITHUB_IMAGE_NAME: ${{ github.repository_owner }}/backend | |
GITHUB_REGISTRY: ghcr.io | |
jobs: | |
build-and-push-amd64: | |
permissions: | |
contents: read | |
packages: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ env.DOCKERHUB_TOKEN }} | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ${{ env.GITHUB_REGISTRY }} | |
username: ${{ github.actor }} | |
- name: Set version | |
id: set_version | |
run: | | |
if [ "${{ github.event_name }}" = "push" ]; then | |
echo "VERSION=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | |
else | |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Build and push AMD64 | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }}-amd64 | |
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }}-amd64 | |
build-and-push-arm64: | |
permissions: | |
contents: read | |
packages: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ env.DOCKERHUB_TOKEN }} | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ${{ env.GITHUB_REGISTRY }} | |
username: ${{ github.actor }} | |
- name: Set version | |
id: set_version | |
run: | | |
if [ "${{ github.event_name }}" = "push" ]; then | |
echo "VERSION=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | |
else | |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Build and push ARM64 | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/arm64 | |
push: true | |
tags: | | |
${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }}-arm64 | |
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }}-arm64 | |
create-manifest: | |
needs: [build-and-push-amd64, build-and-push-arm64] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ env.DOCKERHUB_TOKEN }} | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ${{ env.GITHUB_REGISTRY }} | |
username: ${{ github.actor }} | |
- name: Set version | |
id: set_version | |
run: | | |
if [ "${{ github.event_name }}" = "push" ]; then | |
echo "VERSION=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | |
else | |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Create and push manifest | |
run: | | |
# Create and push DockerHub manifest | |
docker manifest create ${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }} \ | |
${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }}-amd64 \ | |
${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }}-arm64 | |
docker manifest push ${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }} | |
# Create and push GitHub Container Registry manifest | |
docker manifest create ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }} \ | |
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }}-amd64 \ | |
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }}-arm64 | |
docker manifest push ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }} |