Skip to content

Commit

Permalink
fix(cicd): add cosign installer
Browse files Browse the repository at this point in the history
  • Loading branch information
azlam-abdulsalam committed Mar 2, 2024
1 parent 66328a2 commit d40251e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
12 changes: 10 additions & 2 deletions .github/actions/copyDocker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ inputs:
token:
type: string
required: true

outputs:
digest:
description: "digest of the image"
value: ${{ steps.copy-image.outputs.DIGEST }}

runs:
using: "composite"
Expand All @@ -39,10 +42,15 @@ runs:

- uses: imjasonh/[email protected]

- name: tag image
- name: copy image
id: copy-image
shell: bash
run: |
echo "${{ inputs.token }}" | crane auth login ${{ inputs.registry }} --username ${{ inputs.username }} --password-stdin
crane cp ${{ inputs.registry }}/${{ inputs.repo }}/${{ inputs.image }}:${{ inputs.tag }} ${{ inputs.registry }}/${{ inputs.repo}}/${{ inputs.image-as }}:${{ inputs.with-tag }}
FULL_DIGEST=$(crane digest ${{ inputs.registry }}/${{ inputs.repo }}/${{ inputs.image-as }}:${{ inputs.with-tag }})
DIGEST=${FULL_DIGEST#*:}
echo "DIGEST=$DIGEST" >> "$GITHUB_OUTPUT"
4 changes: 3 additions & 1 deletion .github/workflows/sfp-build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ jobs:
contents: read
packages: write
id-token: write

steps:

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Cosign
uses: sigstore/[email protected]

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/sfp-copy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ jobs:
name: 'copy rc docker image to production'
environment: ${{ inputs.job-environment }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write


steps:

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Cosign
uses: sigstore/[email protected]

- name: 'Get package version'
run: |
echo "PKG_VERSION=$(jq -r ".version" packages/sfp-cli/package.json)" >> $GITHUB_ENV
Expand All @@ -56,8 +65,11 @@ jobs:
token : ${{ secrets.token }}
username : ${{ secrets.username }}



- name: 'Copy Docker'
uses: ./.github/actions/copyDocker
id: copy-docker
with:
repo: ${{ inputs.repo }}
image: ${{ inputs.image }}
Expand All @@ -69,6 +81,24 @@ jobs:
token: ${{ env.DOCKER_TOKEN }}


- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ inputs.repo }}/${{ inputs.image-as }}:${{ env.PKG_VERSION }}-${{ github.run_id }}


- name: Sign the images with GitHub OIDC Token
env:
DIGEST: ${{ steps.copy-docker.outputs.digest }}
TAGS: ghcr.io/${{ inputs.repo }}/${{ inputs.image-as }}:${{ env.PKG_VERSION }}-${{ github.run_id }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --yes ${images}
- name: 'Tag Docker'
uses: ./.github/actions/tagDocker
Expand Down

0 comments on commit d40251e

Please sign in to comment.