Build & Helm doc #2
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 Pipeline | |
on: | |
push: | |
tags: | |
- 'v*' | |
branches: | |
- main | |
# repository_dispatch: | |
# types: | |
# - test-command | |
# - build-command | |
jobs: | |
configure: | |
name: Preliminary configuration | |
runs-on: ubuntu-latest | |
outputs: | |
commit-ref: ${{ steps.configure.outputs.commit-ref }} | |
repo-suffix: ${{ steps.configure.outputs.repo-suffix }} | |
master: ${{ steps.configure.outputs.master }} | |
repo-name: ${{ steps.configure.outputs.repo-name }} | |
architectures: ${{ steps.configure.outputs.architectures }} | |
pr-number: ${{ steps.configure.outputs.pr-number }} | |
steps: | |
- name: Get the version | |
id: get_version | |
run: echo "VERSION=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT | |
if: startsWith(github.ref, 'refs/tags/v') | |
- name: Configure | |
id: configure | |
run: | | |
# The ref of the commit to checkout (do not use the merge commit if repository dispatch) | |
if [ "${{ github.event_name }}" == "repository_dispatch" ]; then | |
echo "master=false" >> $GITHUB_OUTPUT | |
echo "architectures=linux/amd64" >> $GITHUB_OUTPUT | |
echo "commit-ref=${{ github.event.client_payload.pull_request.head.sha }}" >> $GITHUB_OUTPUT | |
echo "pr-number=${{ github.event.client_payload.github.payload.issue.number }}" >> $GITHUB_OUTPUT | |
elif [ "${{ steps.get_version.outputs.VERSION }}" != "" ]; then | |
echo "master=false" >> $GITHUB_OUTPUT | |
echo "architectures=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT | |
echo "commit-ref=${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_OUTPUT | |
else | |
echo "master=true" >> $GITHUB_OUTPUT | |
echo "architectures=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT | |
echo "commit-ref=${{ github.sha }}" >> $GITHUB_OUTPUT | |
fi | |
# The suffix to append to the repository name if not triggered by a push for a release | |
([[ "${{ steps.get_version.outputs.VERSION }}" == "" ]] && \ | |
echo "repo-suffix=-ci" || | |
echo "repo-suffix=") >> $GITHUB_OUTPUT | |
if [ "${{ github.event_name }}" != "repository_dispatch" ]; then | |
echo "repo-name=${{ github.repository }}" >> $GITHUB_OUTPUT | |
else | |
echo "repo-name=${{ github.event.client_payload.github.payload.repository.full_name }}" >> $GITHUB_OUTPUT | |
fi | |
# Since we are using a repository-dispatch event, we have to explicitly set a run check. We initialize it to a "pending" state. | |
# - uses: octokit/[email protected] | |
# name: "Initialize run check to 'pending (For PR-only)" | |
# with: | |
# route: POST /repos/${{ github.repository }}/statuses/${{ steps.configure.outputs.commit-ref }} | |
# state: "pending" | |
# description: "Component build status" | |
# context: "Components building" | |
# target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# if: ${{ github.event_name == 'repository_dispatch' }} | |
build: | |
runs-on: ubuntu-latest | |
needs: configure | |
strategy: | |
fail-fast: false | |
matrix: | |
component: | |
- rear-manager | |
- rear-controller | |
- local-resource-manager | |
steps: | |
- name: Set up QEMU | |
uses: docker/[email protected] | |
with: | |
platforms: all | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
ref: "${{ needs.configure.outputs.commit-ref }}" | |
repository: "${{ needs.configure.outputs.repo-name }}" | |
persist-credentials: false | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-${{ matrix.component }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-${{ matrix.component }}-buildx- | |
- name: Login to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.CI_TOKEN }} | |
- name: Configure the build-push-action dockerfile path | |
id: dockerfile | |
run: | | |
([[ -d "build/${{ matrix.component }}" ]] && \ | |
echo "path=build/${{ matrix.component }}/Dockerfile" || \ | |
echo "path=build/common/Dockerfile") >> $GITHUB_OUTPUT | |
- name: Build (and Publish) ${{ matrix.component }} image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: ${{ needs.configure.outputs.architectures }} | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/${{ matrix.component }}${{ needs.configure.outputs.repo-suffix }}:latest | |
ghcr.io/${{ github.repository_owner }}/${{ matrix.component }}${{ needs.configure.outputs.repo-suffix }}:${{ needs.configure.outputs.commit-ref }} | |
push: true | |
file: ${{ steps.dockerfile.outputs.path }} | |
build-args: | | |
COMPONENT=${{ matrix.component }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
# This ugly bit is necessary if you don't want your cache to grow forever | |
# till it hits GitHub's limit of 5GB. | |
# Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |