Skip to content

Commit

Permalink
Pr 49 (#51)
Browse files Browse the repository at this point in the history
* feat: delete old signatures

* test: signatures deletion

* doc: add readme entry

* chore: fix job names

* doc: tested cosign version notice

* 🎨 Format Python code with yapf (#52)

Co-authored-by: Chizkiyahu <[email protected]>

* easy way create sing docker image for debug

* update README.md to v6

---------

Co-authored-by: unennhexium <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Chizkiyahu <[email protected]>
  • Loading branch information
4 people authored Dec 30, 2024
1 parent 9288a8b commit 4a33ce3
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 85 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
on:
workflow_call:
inputs:
image:
required: true
type: string
tag:
required: true
type: number
arg:
required: false
type: string
default: ${{ inputs.tag }}
multiplatform:
required: false
type: boolean
default: false
sign:
required: false
type: boolean
default: false
env:
# Use ghcr.io for GitHub Container Registry if empty
REGISTRY: ghcr.io

jobs:
build:
name: Add temporary packages for testing
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge with sigstore/fulcio.
# It isn't possible to use `${{ inputs.sign && write || none }}` here.
id-token: write
steps:
- uses: actions/checkout@v4
# Install the cosign tool
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: ${{ inputs.sign }}
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da #v3.7.0
with:
cosign-release: 'v2.4.1'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker,
# set environments required for signing.
# Automatically sanitize tags (lowercasing,
# replace spaces with '_', etc.)
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ inputs.image }}
tags: type=raw,value=${{ inputs.tag }}
- name: Build and push
uses: docker/build-push-action@v5
id: build-and-push
with:
file: ./CICD/Dockerfile_temp
tags: ${{ steps.meta.outputs.tags }}
build-args: I=${{ inputs.arg }}
push: true
platforms: ${{ inputs.multiplatform && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
# Disable automatic manifest list by disabling attestation facts generation
provenance: ${{ !inputs.sign }}
sbom: ${{ !inputs.sign }}
# Sign the resulting Docker image digest
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ inputs.sign }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
97 changes: 97 additions & 0 deletions .github/workflows/signed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: signed
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
skip_delete:
description: "Skip the delete steps"
required: false
default: false
type: boolean

concurrency: testing
permissions:
contents: read
packages: write
# Required by nested `reusable.yml`.
id-token: write
jobs:
reset:
name: Reset to a clean state
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
with:
token: ${{ secrets.PAT_TOKEN }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
untagged_only: false
owner_type: user
with_sigs: true

add_temp_pkgs3:
name: Add temporary signed packages for testing
needs: reset
uses: ./.github/workflows/reusable.yml
with:
image: 'p5'
tag: 1
sign: true

add_temp_pkgs4:
name: Add temporary signed packages for testing make the first untagged (keep signed tagged)
needs: add_temp_pkgs3
uses: ./.github/workflows/reusable.yml
with:
image: 'p5'
tag: 1
sign: true

delete_package_with_signature:
name: Delete package and signature
runs-on: ubuntu-latest
needs: add_temp_pkgs4
if: github.event_name != 'workflow_dispatch' || inputs.skip_delete == false
steps:
- uses: actions/checkout@v4
- uses: ./
id: deleted-action
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
package_name: p5
untagged_only: true
owner_type: user
with_sigs: true
- shell: bash
run: |
if [[ "${{ steps.deleted-action.outputs.num_deleted }}" != 2 ]]; then
exit 1
fi
clean_repo:
name: Delete all packages in repo
runs-on: ubuntu-latest
needs: delete_package_with_signature
if: github.event_name != 'workflow_dispatch' || inputs.skip_delete == false
steps:
- uses: actions/checkout@v4
- uses: ./
id: deleted-action
with:
token: ${{ secrets.PAT_TOKEN }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
untagged_only: false
owner_type: user
with_sigs: true
- shell: bash
run: |
if [[ "${{ steps.deleted-action.outputs.num_deleted }}" != 1 ]]; then
exit 1
fi
82 changes: 21 additions & 61 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ concurrency: testing
permissions:
contents: read
packages: write
# Required by nested `reusable.yml`.
id-token: write
jobs:
reset:
name: reset to a clean state
name: Reset to a clean state
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -26,73 +28,31 @@ jobs:

add_temp_pkgs1:
name: Add temporary packages for testing
runs-on: ubuntu-latest
needs: reset
strategy:
matrix:
i: [1, 2]
type: ['p1', 'p2', 'p3']
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: lower case repository_owner
id: lower_case_repository_owner
uses: ASzc/change-string-case-action@v6
with:
string: ${{ github.repository_owner }}
- name: Build and push
uses: docker/build-push-action@v5
with:
file: ./CICD/Dockerfile_temp
tags: ghcr.io/${{ steps.lower_case_repository_owner.outputs.lowercase }}/${{ matrix.type }}:${{ matrix.i }}
build-args: |
I=${{ matrix.i }}
push: true
image: ['p1', 'p2', 'p3']
tag: [1, 2]
uses: ./.github/workflows/reusable.yml
with:
image: ${{ matrix.image }}
tag: ${{ matrix.tag }}

add_temp_pkgs2:
name: Add temporary packages for testing make the first untagged
runs-on: ubuntu-latest
needs: add_temp_pkgs1
strategy:
matrix:
i: [1, 2]
type: ['p1', 'p2', 'p3']
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: lower case repository_owner
id: lower_case_repository_owner
uses: ASzc/change-string-case-action@v6
with:
string: ${{ github.repository_owner }}
- name: Build and push
uses: docker/build-push-action@v5
with:
file: ./CICD/Dockerfile_temp
tags: ghcr.io/${{ steps.lower_case_repository_owner.outputs.lowercase }}/${{ matrix.type }}:${{ matrix.i }}
build-args: |
I=${{ matrix.i }}
push: true
platforms: linux/amd64,linux/arm64

image: ['p1', 'p2', 'p3']
tag: [1, 2]
uses: ./.github/workflows/reusable.yml
with:
image: ${{ matrix.image }}
tag: ${{ matrix.tag }}
multiplatform: true

clean_untagged_pkgs1:
name: clean untagged packages
name: Clean untagged packages
runs-on: ubuntu-latest
needs: add_temp_pkgs2
steps:
Expand Down Expand Up @@ -121,7 +81,7 @@ jobs:
fi
clean_untagged_pkgs2:
name: clean untagged packages
name: Clean untagged packages
runs-on: ubuntu-latest
needs: clean_untagged_pkgs1
steps:
Expand All @@ -142,7 +102,7 @@ jobs:
fi
delete_package:
name: delete package
name: Delete package
runs-on: ubuntu-latest
needs: clean_untagged_pkgs2
steps:
Expand All @@ -163,7 +123,7 @@ jobs:
fi
delete_multiple_packages:
name: delete multiple package
name: Delete multiple packages
runs-on: ubuntu-latest
needs: clean_untagged_pkgs2
steps:
Expand All @@ -184,7 +144,7 @@ jobs:
fi
clean_repo:
name: delete all package in repo
name: Delete all packages in repo
runs-on: ubuntu-latest
needs:
- delete_package
Expand Down
Loading

0 comments on commit 4a33ce3

Please sign in to comment.