ci(github): adjust build container action #10
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
# Copyright (c) 2023 Joshua Rich <[email protected]> | |
# | |
# This software is released under the MIT License. | |
# https://opensource.org/licenses/MIT | |
name: build-container | |
env: | |
REGISTRY: ghcr.io | |
REGISTRY_USER: ${{ github.actor }} | |
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
IMAGE: ${{ github.repository }} | |
on: | |
release: | |
types: [ created ] | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build-push-image: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install/Cache dependencies | |
uses: awalsh128/cache-apt-pkgs-action@latest | |
with: | |
packages: qemu-user-static | |
- name: Build container image | |
id: build_image | |
uses: redhat-actions/buildah-build@v2 | |
with: | |
archs: amd64 | |
# context: build/package | |
image: ${{ env.IMAGE }} | |
tags: latest ${{ github.sha }} | |
containerfiles: Dockerfile | |
layers: false | |
oci: true | |
- name: Push to Container Registry | |
id: push_image | |
uses: redhat-actions/push-to-registry@v2 | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
with: | |
username: ${{ env.REGISTRY_USER }} | |
password: ${{ env.REGISTRY_PASSWORD }} | |
image: ${{ env.IMAGE }} | |
registry: ${{ env.REGISTRY }} | |
tags: ${{ steps.build_image.outputs.tags }} | |
- name: Login to Container Registry | |
uses: redhat-actions/podman-login@v1 | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ env.REGISTRY_USER }} | |
password: ${{ env.REGISTRY_PASSWORD }} | |
- name: Check and install cosign | |
uses: sigstore/[email protected] | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
with: | |
cosign-release: 'v2.2.0' | |
- name: Sign image with a key | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
run: | | |
images="" | |
for tag in ${TAGS}; do | |
images+="${tag}@${DIGEST} " | |
done | |
cosign sign --yes --key cosign.key ${images} | |
env: | |
TAGS: ${{ steps.docker_meta.outputs.tags }} | |
COSIGN_PASSWORD: ${{ secrets.COSIGN_PWD }} | |
DIGEST: ${{ steps.build_image.outputs.digest }} |