[docker build fix] building multiple tags #188
Workflow file for this run
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 | |
on: | |
push: | |
branches: | |
- '**' | |
tags: | |
- '**' | |
paths-ignore: | |
- 'releases/**' | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) && 'hiro-microdatacenters-bv/rhio' || 'hiro-microdatacenters-bv/rhio-dev' }} | |
HELM_CHART_TARGET_DIR: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) && './helm-charts' || './dev' }} | |
BRANCH_NAME: ${GITHUB_REF##*/} | |
jobs: | |
test: | |
name: Test / ${{ matrix.config.target }} on ${{ matrix.config.os }} | |
runs-on: ${{ matrix.config.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
config: | |
- os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
- os: macos-latest | |
target: aarch64-apple-darwin | |
isMain: | |
- ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} | |
exclude: | |
- config: | |
os: macos-latest | |
target: aarch64-apple-darwin | |
isMain: false | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Rust toolchain | |
uses: moonrepo/setup-rust@v1 | |
with: | |
# disabled caching in the setup-rust because aarch64-apple-darwin build takes around 1 hour to start | |
cache: false | |
channel: ${{ env.RUST_TOOLCHAIN }} | |
# build speedups | |
- uses: Swatinem/rust-cache@v2 | |
- name: Run tests | |
# Ensure debug output is also tested | |
env: | |
RUST_LOG: debug | |
run: cargo test --all-features | |
build-helm-chart: | |
name: Build Helm Chart | |
runs-on: ubuntu-latest | |
needs: [test] | |
defaults: | |
run: | |
working-directory: ./ | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Rust toolchain | |
uses: moonrepo/setup-rust@v1 | |
with: | |
cache: false | |
channel: ${{ env.RUST_TOOLCHAIN }} | |
# build speedups | |
- uses: Swatinem/rust-cache@v2 | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
- name: Make versions | |
run: | | |
cd "${{ github.workspace }}" | |
chmod +x ./version.sh | |
./version.sh "${{ github.sha }}" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | |
echo "VERSION_APP=$(cat "./VERSION")" >> $GITHUB_ENV | |
echo "DOCKER_IMAGES=$(cat "./DOCKER_IMAGES")" >> $GITHUB_ENV | |
echo "DOCKER_TAGS=$(cat "./VERSION_DOCKER")" >> $GITHUB_ENV | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "[email protected]" | |
- name: Generate CRDs | |
env: | |
RUST_LOG: debug | |
run: cargo run --bin rhio-operator crd > ${{ github.workspace }}/charts/rhio-operator/crds/crds.yaml | |
- name: Create a github release | |
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} | |
run: gh release create "${{ env.VERSION_APP }}" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Publish Helm charts | |
uses: stefanprodan/helm-gh-pages@master | |
with: | |
token: ${{ github.token }} | |
charts_dir: "./charts" | |
target_dir: ${{ env.HELM_CHART_TARGET_DIR }} | |
build-docker: | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- linux/amd64 | |
- linux/arm64 | |
isMain: | |
- ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} | |
exclude: | |
# ARM build is very slow, we build only for main branch | |
- platform: "linux/arm64" | |
isMain: false | |
name: Docker Build / ${{ matrix.platform }} | |
runs-on: ubuntu-22.04 | |
needs: [test] | |
defaults: | |
run: | |
working-directory: ./ | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- name: Prepare | |
run: | | |
platform=${{ matrix.platform }} | |
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: ${{ matrix.platform }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Make versions | |
run: | | |
cd "${{ github.workspace }}" | |
chmod +x ./version.sh | |
./version.sh "${{ github.sha }}" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | |
echo "VERSION_APP=$(cat "./VERSION")" >> $GITHUB_ENV | |
echo "DOCKER_IMAGES=$(cat "./DOCKER_IMAGES")" >> $GITHUB_ENV | |
echo "DOCKER_TAGS=0.1.3-test3,0.1.3-test4" >> $GITHUB_ENV | |
echo "DOCKER_TAG_ARGS=$(cat "./VERSION_DOCKER" | sed 's/,/,name=/g; s/^/name=/')" >> $GITHUB_ENV | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: ${{ env.DOCKER_TAGS }} | |
- name: Metadata tag names | |
run: | | |
echo "${{ steps.meta.outputs.tags }}" | |
- name: Build and push docker image | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
platforms: ${{ matrix.platform }} | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: type=image,${{ env.DOCKER_TAG_ARGS }},push-by-digest=true,name-canonical=true,push=true | |
cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }} | |
cache-to: type=gha,mode=max,scope=build-${{ env.PLATFORM_PAIR }} | |
github-token: ${{ github.token }} | |
- name: Export Digest | |
run: | | |
digest="${{ steps.build.outputs.digest }}" | |
[ "$digest" ] || exit 1 | |
mkdir -p /tmp/digests | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload Digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests-${{ env.PLATFORM_PAIR }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge-manifests: | |
name: Docker Build / Merge Manifests | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
needs: | |
- build-docker | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: digests-* | |
merge-multiple: true | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Make versions | |
run: | | |
cd "${{ github.workspace }}" | |
chmod +x ./version.sh | |
./version.sh "${{ github.sha }}" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | |
echo "VERSION_APP=$(cat "./VERSION")" >> $GITHUB_ENV | |
echo "DOCKER_IMAGES=$(cat "./DOCKER_IMAGES")" >> $GITHUB_ENV | |
echo "0.1.3-test3,0.1.3-test4" >> VERSION_DOCKER | |
echo -e "DOCKER_TAGS_META=$(cat ./VERSION_DOCKER | tr ',' '\n')" >> $GITHUB_ENV | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: ${{ env.DOCKER_TAGS_META }} | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) | |
- name: Inspect image | |
run: | | |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} |