name: Build and Push Container Images on: push: branches: - main tags: - "v*" pull_request: branches: - main env: REGISTRY: ghcr.io OWNER: ${{ github.repository_owner }} jobs: build-and-push: runs-on: ubuntu-latest permissions: contents: read packages: write strategy: matrix: service: - name: web-portal context: ${{ github.workspace }} dockerfile: src/web-portal/Dockerfile - name: billing-service context: ${{ github.workspace }} dockerfile: src/billing-service/Dockerfile - name: metrics-service context: ${{ github.workspace }} dockerfile: src/metrics-service/Dockerfile - name: dns-manager context: ${{ github.workspace }} dockerfile: src/dns-manager/Dockerfile steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Log in to GitHub Container Registry if: github.event_name != 'pull_request' uses: redhat-actions/podman-login@v1 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Get short SHA id: sha run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Build image uses: redhat-actions/buildah-build@v2 id: build_image with: image: localhost/container-mom-${{ matrix.service.name }} tags: latest containerfiles: ${{ matrix.service.dockerfile }} context: ${{ matrix.service.context }} extra-args: | --format=docker --layers=true --storage-driver=vfs --pull-never - name: Tag for registry if: github.event_name != 'pull_request' run: | buildah tag localhost/container-mom-${{ matrix.service.name }}:latest ${{ env.REGISTRY }}/${{ env.OWNER }}/container-mom-${{ matrix.service.name }}:latest buildah tag localhost/container-mom-${{ matrix.service.name }}:latest ${{ env.REGISTRY }}/${{ env.OWNER }}/container-mom-${{ matrix.service.name }}:${{ github.ref_name }} buildah tag localhost/container-mom-${{ matrix.service.name }}:latest ${{ env.REGISTRY }}/${{ env.OWNER }}/container-mom-${{ matrix.service.name }}:sha-${{ steps.sha.outputs.sha }} - name: Push to registry if: github.event_name != 'pull_request' uses: redhat-actions/push-to-registry@v2 with: image: ${{ env.REGISTRY }}/${{ env.OWNER }}/container-mom-${{ matrix.service.name }} tags: | latest ${{ github.ref_name }} sha-${{ steps.sha.outputs.sha }} registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}