Update Dockerfile and GitHub Actions for multi-architecture support #84
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 flAPI | |
permissions: | |
contents: read | |
packages: write | |
issues: write | |
pull-requests: write | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
# ------------------------------------------------------------------------------------------------- | |
# Linux AMD64 | |
# ------------------------------------------------------------------------------------------------- | |
linux-amd64: | |
runs-on: ubuntu-latest | |
env: | |
BUILD_ARCH: amd64 | |
BUILD_IMAGE: flapi_build_amd64 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup Ccache | |
uses: hendrikmuhs/ccache-action@main | |
with: | |
key: ${{ github.job }} | |
- name: Build Docker image | |
shell: bash | |
run: | | |
docker build \ | |
-t ${BUILD_IMAGE} \ | |
-f .github/docker/linux_${BUILD_ARCH}/Dockerfile . | |
- name: Run build in docker | |
shell: bash | |
run: | | |
docker run \ | |
-v `pwd`:/build_dir \ | |
-v ~/.ccache:/ccache_dir \ | |
${BUILD_IMAGE} \ | |
bash -c 'make clean && make release' | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: flapi-linux-${{ env.BUILD_ARCH }} | |
path: build/release/flapi | |
if-no-files-found: error | |
# ------------------------------------------------------------------------------------------------- | |
# Linux ARM64 | |
# ------------------------------------------------------------------------------------------------- | |
linux-aarch64: | |
runs-on: ubuntu-latest | |
env: | |
FLAPI_CROSS_COMPILE: arm64 | |
BUILD_ARCH: arm64 | |
BUILD_IMAGE: flapi_build_arm64 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup Ccache | |
uses: hendrikmuhs/ccache-action@main | |
with: | |
key: ${{ github.job }} | |
- name: Build Docker image | |
shell: bash | |
run: | | |
docker build \ | |
-t ${BUILD_IMAGE} \ | |
-f .github/docker/linux_${BUILD_ARCH}/Dockerfile . | |
- name: Run build in docker | |
shell: bash | |
run: | | |
docker run \ | |
-e FLAPI_CROSS_COMPILE="${BUILD_ARCH}" \ | |
-v `pwd`:/build_dir \ | |
-v ~/.ccache:/ccache_dir \ | |
${BUILD_IMAGE} \ | |
bash -c 'make clean && make release' | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: flapi-linux-${{ env.BUILD_ARCH }} | |
path: build/release/flapi | |
if-no-files-found: error | |
# ------------------------------------------------------------------------------------------------- | |
# Docker Build and Push Multi-Arch | |
# ------------------------------------------------------------------------------------------------- | |
docker-build: | |
needs: [linux-amd64, linux-aarch64] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Prepare | |
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ env.REPO_OWNER }}/flapi | |
tags: | | |
type=raw,value=latest | |
type=sha,format=long | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
- name: Build and push multi-arch image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: TARGETARCH=${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} | |
build-contexts: | | |
amd64=./artifacts/flapi-linux-amd64 | |
arm64=./artifacts/flapi-linux-arm64 | |
# ------------------------------------------------------------------------------------------------- | |
# macOS Universal | |
# ------------------------------------------------------------------------------------------------- | |
osx-universal: | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Setup Ccache | |
uses: hendrikmuhs/ccache-action@main | |
with: | |
key: ${{ github.job }} | |
- name: Install dependencies | |
shell: bash | |
run: brew install ninja autoconf make libtool pkg-config automake autoconf-archive | |
- name: Build | |
run: make release | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: flapi-macos-universal | |
path: build/universal/flapi | |
if-no-files-found: error | |
retention-days: 90 |