build(ci): Build & publish image to GHCR #9
Workflow file for this run
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 & publish images | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
permissions: | |
contents: read | |
packages: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
set-vars: | |
name: Gather job information | |
if: github.repository == 'jannfis/argocd-agent' | |
runs-on: ubuntu-22.04 | |
outputs: | |
image-tag: ${{ steps.image.outputs.tag }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Set image tag for pushing to ghcr | |
run: | | |
if test "${{ github.event_name }}" = "pull_request"; then | |
echo "tag=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT | |
else | |
echo "tag=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT | |
fi | |
id: image | |
build-and-push: | |
strategy: | |
fail-fast: true | |
matrix: | |
components: | |
- name: agent | |
- name: principal | |
name: Build and push images | |
runs-on: ubuntu-22.04 | |
if: github.repository == 'jannfis/argocd-agent' && ( github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ok-to-build') ) | |
needs: [set-vars] | |
env: | |
DOCKER_BIN: podman | |
IMAGE_TAG: ${{ needs.set-vars.outputs.image-tag }} | |
IMAGE_REPOSITORY: ghcr.io/jannfis/argocd-agent | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Build ${{ matrix.component.name }} image | |
run: | | |
make image-${{ matrix.components.name }} | |
- name: Push agent image to ghcr.io | |
uses: redhat-actions/push-to-registry@v2 | |
with: | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ghcr.io | |
image: ${{ env.IMAGE_REPOSITORY }}/argocd-agent-${{ matrix.components.name }} | |
tags: ${{ env.IMAGE_TAG }} |