Skip to content

Commit

Permalink
chore(ci): finish sign refactor and limit pr build (#96)
Browse files Browse the repository at this point in the history
* chore(ci): finish sign refactor and limit pr build

First attempt to copy "avoid subshell, sign image with env. var" to this
repo was incomplete as this workflow has two distinct build jobs and the
second one was missed.

This commit finishes the job, plus prevents the following steps from
running in a PR, again, to match the main repo:
- login to GHCR
- push to GHCR
- sign image
- echo push outputs

* rafactor: fix my over-zealous consolidation
  • Loading branch information
bsherman authored May 5, 2023
1 parent f77f4fa commit 93fa3bd
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
paths-ignore:
- '**.md'
- '**.txt'
merge_group:
merge_group:
schedule:
- cron: '20 21 * * *' # 9:20pm everyday (1 hr delay after 'main' builds)
workflow_dispatch:

env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
jobs:
build-akmods:
name: Build akmods package
Expand Down Expand Up @@ -103,6 +103,7 @@ jobs:
org.opencontainers.image.description=ublue-os ${{ env.IMAGE_NAME }} with akmods-nvidia packages pre-built
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/main/README.md
io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/1728152?s=200&v=4
# Build image using Buildah action
- name: Build Image
id: build_image
Expand Down Expand Up @@ -131,6 +132,7 @@ jobs:
# Push the image to GHCR (Image Registry)
- name: Push To GHCR
uses: redhat-actions/push-to-registry@v2
if: github.event_name != 'pull_request'
id: push
env:
REGISTRY_USER: ${{ github.actor }}
Expand All @@ -144,33 +146,29 @@ jobs:
extra-args: |
--disable-content-trust
# Sign container
- uses: sigstore/[email protected]

# Only needed when running `cosign sign` using a key
- name: Write signing key to disk
run: |
echo "${{ env.COSIGN_PRIVATE_KEY }}" > cosign.key
# DEBUG: get character count of key
wc -c cosign.key
env:
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Sign container
- uses: sigstore/[email protected]
if: github.event_name != 'pull_request'

- name: Sign container image
if: github.event_name != 'pull_request'
run: |
cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }}@${TAGS}
env:
TAGS: ${{ steps.push.outputs.digest }}
COSIGN_EXPERIMENTAL: false
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}

- name: Echo outputs
if: github.event_name != 'pull_request'
run: |
echo "${{ toJSON(steps.push.outputs) }}"
Expand Down Expand Up @@ -215,7 +213,7 @@ jobs:
major_version: 38
- driver_version: 470
major_version: 38
steps:
steps:
# Checkout push-to-registry action GitHub repository
- name: Checkout Push to Registry action
uses: actions/checkout@v3
Expand All @@ -236,7 +234,7 @@ jobs:
BUILD_TAGS=()
# Have tags for tracking builds during pull request
SHA_SHORT="$(git rev-parse --short HEAD)"
SHA_SHORT="${GITHUB_SHA::7}"
COMMIT_TAGS+=("pr-${{ github.event.number }}-${VARIANT}")
COMMIT_TAGS+=("${SHA_SHORT}-${VARIANT}")
Expand Down Expand Up @@ -316,6 +314,7 @@ jobs:
org.opencontainers.image.version=${{ steps.labels.outputs.VERSION }}
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/main/README.md
io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/1728152?s=200&v=4
# Build image using Buildah action
- name: Build Image
id: build_image
Expand Down Expand Up @@ -346,6 +345,7 @@ jobs:
- name: Push To GHCR
uses: redhat-actions/push-to-registry@v2
id: push
if: github.event_name != 'pull_request'
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
Expand All @@ -358,32 +358,28 @@ jobs:
extra-args: |
--disable-content-trust
# Sign container
- uses: sigstore/[email protected]

# Only needed when running `cosign sign` using a key
- name: Write signing key to disk
run: |
echo "${{ env.COSIGN_PRIVATE_KEY }}" > cosign.key
# DEBUG: get character count of key
wc -c cosign.key
env:
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Sign container
- uses: sigstore/[email protected]
if: github.event_name != 'pull_request'

- name: Sign container image
if: github.event_name != 'pull_request'
run: |
cosign sign -y --key cosign.key ${{ steps.registry_case.outputs.lowercase }}/${{ steps.build_image.outputs.image }}@${TAGS}
cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }}@${TAGS}
env:
TAGS: ${{ steps.push.outputs.digest }}
COSIGN_EXPERIMENTAL: false
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}

- name: Echo outputs
if: github.event_name != 'pull_request'
run: |
echo "${{ toJSON(steps.push.outputs) }}"

0 comments on commit 93fa3bd

Please sign in to comment.