Set operator resources #120
This file contains hidden or 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 | |
on: | |
push: | |
branches: [master] | |
concurrency: | |
group: environment-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
setup_env: | |
name: ⚙️ Setup environment | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Add SHORT_SHA env property | |
run: echo "SHORT_SHA=`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV | |
- name: Put commit msg in environment | |
run: echo "COMMIT_MSG=${{ github.event.head_commit.message }}" >> $GITHUB_ENV | |
- name: Escape commit message | |
run: | | |
echo "COMMIT_MSG=$(echo $COMMIT_MSG | tr -d \'\\\")" >> $GITHUB_ENV | |
- name: Get branch name (merge) | |
if: github.event_name != 'pull_request' | |
shell: bash | |
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV | |
- name: Get branch name (pull request) | |
if: github.event_name == 'pull_request' | |
shell: bash | |
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV | |
- name: Set build start in env variable | |
run: echo "BUILD_START=$(date +%s)" >> $GITHUB_ENV | |
outputs: | |
short_sha: ${{ env.SHORT_SHA }} | |
commit_msg: ${{ env.COMMIT_MSG }} | |
branch_name: ${{ env.BRANCH_NAME }} | |
build_start: ${{ env.BUILD_START }} | |
build: | |
name: 🔨 Build Binaries and Docker Image | |
needs: setup_env | |
strategy: | |
matrix: | |
include: | |
- platform: linux/amd64 | |
runs-on: ubuntu-24.04 | |
arch: amd64 | |
- platform: linux/arm64 | |
runs-on: ubuntu-24.04-arm | |
arch: arm64 | |
runs-on: ${{ matrix.runs-on }} | |
env: | |
GITHUB_RUN_ID: ${{ github.run_id }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Go with cache | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: ./go.mod | |
- 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: Build and push image | |
if: success() | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: ${{ matrix.platform }} | |
provenance: false | |
push: true | |
file: ./Dockerfile | |
tags: ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-${{ matrix.arch }} | |
create_manifest: | |
name: 📦 Create and Push Multi-Arch Manifest | |
runs-on: ubuntu-24.04 | |
needs: [setup_env, build] | |
env: | |
GITHUB_RUN_ID: ${{ github.run_id }} | |
steps: | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create and push API manifest | |
run: | | |
docker manifest create ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} \ | |
--amend ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \ | |
--amend ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
docker manifest annotate --arch amd64 --os linux ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 | |
docker manifest annotate --arch arm64 --os linux ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
docker manifest push ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} | |
# Also tag as latest | |
docker manifest create ghcr.io/unbindapp/unbind-operator:latest \ | |
--amend ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
docker manifest annotate --arch arm64 --os linux ghcr.io/unbindapp/unbind-operator:latest ghcr.io/unbindapp/unbind-operator:${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
docker manifest push ghcr.io/unbindapp/unbind-operator:latest |