Buildah building action #1
Workflow file for this run
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: ghcr publish | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "main" ] | |
# Publish semver tags as releases. | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ "main" ] | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: pgschk/alpine-tookit | |
TEST_TAG: test | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
install_latest: [ true, false ] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Install the cosign tool except on PR | |
# https://github.com/sigstore/cosign-installer | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1 | |
with: | |
cosign-release: 'v2.1.1' | |
- name: Docker Metadata | |
id: docker-metadata | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.IMAGE_NAME }} | |
tags: | | |
type=edge | |
type=sha | |
type=ref,event=branch | |
type=ref,event=pr | |
type=schedule | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} | |
- name: Install latest buildah | |
if: matrix.install_latest | |
run: | | |
bash .github/install_latest_buildah.sh | |
- name: Read extended packages file | |
id: get-extended-packages | |
run: echo "extended-packages=$(tr '\n' ' ' < EXTENDED_PACKAGES)" >> $GITHUB_OUTPUT | |
# Build image using Buildah action | |
- name: Build Image | |
id: build_image | |
uses: ./ | |
with: | |
layers: false | |
tags: ${{ steps.docker-metadata.outputs.tags }} | |
labels: ${{ steps.docker-metadata.outputs.labels }} | |
containerfiles: | | |
./Dockerfile | |
extra-args: | | |
--pull | |
- name: Echo Outputs | |
run: | | |
echo "Image: ${{ steps.build_image.outputs.image }}" | |
echo "Tags: ${{ steps.build_image.outputs.tags }}" | |
echo "Tagged Image: ${{ steps.build_image.outputs.image-with-tag }}" | |
# Check if image is build | |
- name: Check images created | |
run: buildah images | grep '${{ env.IMAGE_NAME }}' | |
- name: Check image metadata | |
run: | | |
set -x | |
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"' | |
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"' | |
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"' | |
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"' | |
# Podman Login action (https://github.com/redhat-actions/podman-login) also be used to log in, | |
# in which case 'username' and 'password' can be omitted. | |
- name: Push To ghcr.io | |
id: push-to-ghcr | |
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} | |
uses: redhat-actions/push-to-registry@v2 | |
with: | |
image: ${{ steps.build_image.outputs.image }} | |
tags: ${{ steps.build_image.outputs.tags }} | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Print ghcr.io image url | |
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} | |
run: echo "Image pushed to ${{ steps.push-to-ghcr.outputs.registry-paths }}" | |
# Sign the resulting Docker image digest except on PRs. | |
# This will only write to the public Rekor transparency log when the Docker | |
# repository is public to avoid leaking data. If you would like to publish | |
# transparency data even for private images, pass --force to cosign below. | |
# https://github.com/sigstore/cosign | |
- name: Sign the published Docker image | |
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} | |
env: | |
COSIGN_EXPERIMENTAL: "true" | |
# This step uses the identity token to provision an ephemeral certificate | |
# against the sigstore community Fulcio instance. | |
run: echo "${{ steps.docker-metadata.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build_image.outputs.digest }} |