fix: long build times for arm by using mac #60
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 | |
continue-on-error: true | |
outputs: | |
success: ${{ steps.build.outcome == 'success' }} | |
version: ${{ steps.set_version.outputs.VERSION }} | |
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 | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }} | |
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }} | |
build-and-push-arm64: | |
permissions: | |
contents: read | |
packages: write | |
runs-on: macos-latest | |
continue-on-error: true | |
outputs: | |
success: ${{ steps.build.outcome == 'success' }} | |
version: ${{ steps.set_version.outputs.VERSION }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install Docker and Colima | |
run: | | |
brew install docker colima | |
colima start --arch aarch64 --memory 4 | |
docker context use colima | |
- 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 | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/arm64 | |
push: true | |
tags: | | |
${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }} | |
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }} |