Add multi-arch building of the msgs #1
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 Image, upload artifact | ||
on: | ||
push: | ||
pull_request: | ||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
short_git_sha: ${{ steps.vars.outputs.SHORT_GIT_SHA }} | ||
short_git_version_string: ${{ steps.vars.outputs.SHORT_GIT_VERSION_STRING }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set short git commit SHA | ||
id: vars | ||
run: | | ||
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | ||
calculatedGitVersionString=$(git log --date=format:%Y%m%d --pretty=~git%cd.%h -n 1) | ||
echo "SHORT_GIT_SHA=$calculatedSha" >> $GITHUB_OUTPUT | ||
echo "SHORT_GIT_VERSION_STRING=$calculatedGitVersionString" >> $GITHUB_OUTPUT | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: amd64,arm64 | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Container metadata for runtime base image | ||
id: meta # referenced from later step | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/tiiuae/tii-fognav-msgs | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{raw}} | ||
type=sha | ||
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | ||
- name: Build and push runtime base image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
context: . | ||
file: ./Dockerfile | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
platforms: linux/amd64,linux/arm64 | ||
build-args: | | ||
PACKAGE_NAME=fognav-msgs | ||
GIT_RUN_NUMBER=${{ github.run_number }} | ||
GIT_COMMIT_HASH=${{ github.sha }} | ||
GIT_VERSION_STRING=${{ steps.vars.outputs.SHORT_GIT_VERSION_STRING }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
# Needed because we have to create a manifest list in the next job. | ||
provenance: mode=min | ||
- name: Create container and copy deb packages | ||
run: | | ||
platforms=("amd64" "arm64") | ||
for platform in "${platforms[@]}"; do | ||
docker create -ti --name "fognav-msgs-build-temp-$platform" --platform=linux/$platform $(echo "${{ steps.meta.outputs.tags }}" | head -1) bash | ||
docker cp "fognav-msgs-build-temp-$platform:/output_dir/." ./output_dir | ||
docker rm "fognav-msgs-build-temp-$platform" | ||
done | ||
- name: Upload .deb packages as artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: deb-packages | ||
path: ./output_dir/*.deb | ||
jobs: | ||
upload-to-digitalocean: | ||
runs-on: ubuntu-latest | ||
needs: build-and-push | ||
# if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch | ||
steps: | ||
- name: Download .deb package artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: deb-packages | ||
- name: Upload to digitalocean | ||
run: | | ||
echo "Placeholder" | ||
ls -la ./deb-packages | ||