-
Notifications
You must be signed in to change notification settings - Fork 49
feat: pro rock in ACR #1153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhijie-yang
wants to merge
21
commits into
main
Choose a base branch
from
ROCKS-2675/enable-ecr-rework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: pro rock in ACR #1153
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fb79f7c
feat: pro rock in ACR (WIP)
zhijie-yang 27d800d
chore: fixes from GPT-5.6 Sol high
zhijie-yang 5be2a4e
feat: add prepare-rock-for-testing action
zhijie-yang a311224
doc: add pro-related docs
zhijie-yang 5970ef1
test: add test for pro feature
zhijie-yang b2070dd
chore: American English for atrifact
zhijie-yang 3d870b2
feat: auto rebuild for pro images
zhijie-yang 1c4daa1
chore: doc
zhijie-yang f8532a8
feat: continuous testing
zhijie-yang ee53cfd
refactor(test-rock): cache encrypted archive instead of decrypted layout
zhijie-yang a38f2bb
fix: test required package
zhijie-yang 1ff3576
chore: Update README.md
zhijie-yang 58312e6
chore: update according to code review
zhijie-yang c57fd66
Merge branch 'main' into ROCKS-2675/enable-ecr-rework
zhijie-yang 6208d1c
Merge branch 'main' into ROCKS-2675/enable-ecr-rework
zhijie-yang 1d12f65
fix: test
zhijie-yang f2a3f98
fix: bind mount local artifact into skopeo container
zhijie-yang 54f6260
fix: gpg substring removal
zhijie-yang 3d77caa
chore: code review from alesancor
zhijie-yang 85ffdd1
Merge branch 'main' into ROCKS-2675/enable-ecr-rework
zhijie-yang 0f4ecef
chore: trigger CI
zhijie-yang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
97 changes: 67 additions & 30 deletions
97
.github/actions/fetch-releases-json/test-copy-releases-files.bats
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,81 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load '/usr/lib/bats/bats-support/load.bash' | ||
| load '/usr/lib/bats/bats-assert/load.bash' | ||
| setup() { | ||
| original_pwd=$PWD | ||
| workdir=$(mktemp -d "${BATS_TEST_TMPDIR}/copy-releases.XXXXXX") | ||
| releases_dir="${workdir}/releases" | ||
| output_dir="${workdir}/output" | ||
| mkdir -p \ | ||
| "${releases_dir}/oci/public-only" \ | ||
| "${releases_dir}/oci/pro-only" \ | ||
| "${releases_dir}/oci/both" \ | ||
| "${output_dir}/oci/public-only" \ | ||
| "${output_dir}/oci/pro-only" \ | ||
| "${output_dir}/oci/both" | ||
|
|
||
| setup_file() { | ||
| echo "setup" >&3 | ||
| workdir=$(mktemp -d) | ||
| pushd "$workdir" || exit 1 | ||
| git clone https://github.com/canonical/oci-factory.git oci-factory-releases -b _releases --depth 1 | ||
| popd || exit 1 | ||
| export workdir | ||
| printf '%s\n' '{"source":"public-only"}' > "${releases_dir}/oci/public-only/_releases.json" | ||
| printf '%s\n' '{"source":"pro-only"}' > "${releases_dir}/oci/pro-only/_pro_releases.json" | ||
| printf '%s\n' '{"source":"both-public"}' > "${releases_dir}/oci/both/_releases.json" | ||
| printf '%s\n' '{"source":"both-pro"}' > "${releases_dir}/oci/both/_pro_releases.json" | ||
| printf '%s\n' '{"ignored":true}' > "${releases_dir}/oci/both/metadata.json" | ||
|
|
||
| cd "$output_dir" || return 1 | ||
| } | ||
|
|
||
| teardown() { | ||
| cd "$original_pwd" || return 1 | ||
| if [[ -n "${workdir:-}" && "$workdir" == "${BATS_TEST_TMPDIR}"/* ]]; then | ||
| rm -rf -- "$workdir" | ||
| fi | ||
| } | ||
|
|
||
| @test "copies a public-only release file" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" public-only "$releases_dir" | ||
|
|
||
| [[ "$status" -eq 0 ]] | ||
| cmp "${releases_dir}/oci/public-only/_releases.json" "oci/public-only/_releases.json" | ||
| [[ ! -e "oci/public-only/_pro_releases.json" ]] | ||
| } | ||
|
|
||
| @test "copy single existing _releases.json file" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" mock-rock "${workdir}/oci-factory-releases" | ||
| assert_success | ||
| [[ -f "oci/mock-rock/_releases.json" ]] | ||
| @test "copies a Pro-only release file" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" pro-only "$releases_dir" | ||
|
|
||
| [[ "$status" -eq 0 ]] | ||
| cmp "${releases_dir}/oci/pro-only/_pro_releases.json" "oci/pro-only/_pro_releases.json" | ||
| [[ ! -e "oci/pro-only/_releases.json" ]] | ||
| } | ||
|
|
||
| @test "copy single non-existing _releases.json file" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" mock-nonexistent "${workdir}/oci-factory-releases" | ||
| assert_success | ||
| [[ ! -f "oci/mock-nonexistent/_releases.json" ]] | ||
| @test "copies both public and Pro release files" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" both "$releases_dir" | ||
|
|
||
| [[ "$status" -eq 0 ]] | ||
| cmp "${releases_dir}/oci/both/_releases.json" "oci/both/_releases.json" | ||
| cmp "${releases_dir}/oci/both/_pro_releases.json" "oci/both/_pro_releases.json" | ||
| } | ||
|
|
||
| @test "copy all _releases.json files" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" "*" "${workdir}/oci-factory-releases" | ||
| assert_success | ||
| run find oci/ -mindepth 1 -maxdepth 1 -type d | xargs -I{} test -f "{}/_releases.json" | ||
| assert_success | ||
| assert_equal \ | ||
| "$(find 'oci/' -mindepth 1 -maxdepth 1 -type d | wc -l)" \ | ||
| "$(find "${workdir}/oci-factory-releases/oci/" -mindepth 1 -maxdepth 1 -type d | wc -l)" | ||
| @test "wildcard copies all public and Pro release files only" { | ||
| rm -rf -- "${output_dir}/oci" | ||
|
|
||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" "*" "$releases_dir" | ||
|
|
||
| [[ "$status" -eq 0 ]] | ||
| cmp "${releases_dir}/oci/public-only/_releases.json" "oci/public-only/_releases.json" | ||
| cmp "${releases_dir}/oci/pro-only/_pro_releases.json" "oci/pro-only/_pro_releases.json" | ||
| cmp "${releases_dir}/oci/both/_releases.json" "oci/both/_releases.json" | ||
| cmp "${releases_dir}/oci/both/_pro_releases.json" "oci/both/_pro_releases.json" | ||
| [[ ! -e "oci/both/metadata.json" ]] | ||
| } | ||
|
|
||
| @test "fail if directory not found" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" "*" "/nonexistent-directory" | ||
| assert_failure | ||
| @test "missing image succeeds without creating release files" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" missing "$releases_dir" | ||
|
|
||
| [[ "$status" -eq 0 ]] | ||
| [[ ! -e "oci/missing/_releases.json" ]] | ||
| [[ ! -e "oci/missing/_pro_releases.json" ]] | ||
| } | ||
|
|
||
| teardown_file() { | ||
| find . -name "_releases.json" -exec rm {} \; | ||
| @test "wildcard fails for an invalid releases directory" { | ||
| run "${BATS_TEST_DIRNAME}/copy-releases-files.sh" "*" "${workdir}/missing-releases" | ||
|
|
||
| [[ "$status" -ne 0 ]] | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,7 +197,11 @@ jobs: | |
| rock-repo-commit: ${{ matrix.commit }} | ||
| rockfile-directory: ${{ matrix.directory }} | ||
| lpci-fallback: true | ||
| secrets: inherit | ||
| pro-services: ${{ matrix.pro-services }} | ||
| secrets: | ||
| source-github-token: ${{ secrets.ROCKSBOT_TOKEN }} | ||
| pro-token: ${{ secrets.ROCKS_PRO_TOKEN }} | ||
| pro-artifact-passphrase: ${{ secrets.ROCKS_PRO_ARTIFACT_PASSPHRASE }} | ||
|
lczyk marked this conversation as resolved.
Outdated
|
||
|
|
||
| test-rock: | ||
| needs: [prepare-build, build-rock] | ||
|
|
@@ -210,7 +214,8 @@ jobs: | |
| oci-archive-name: "${{ matrix.name }}_${{ matrix.commit }}_${{ matrix.dir_identifier }}" | ||
| trivyignore-path: ${{ matrix.ignored-vulnerabilities == '' && format('oci/{0}/.trivyignore', matrix.name) || '' }} | ||
| ignored-vulnerabilities: ${{ matrix.ignored-vulnerabilities }} | ||
| secrets: inherit | ||
| secrets: | ||
| pro-artifact-passphrase: ${{ matrix.pro-services != '' && secrets.ROCKS_PRO_ARTIFACT_PASSPHRASE || '' }} | ||
|
|
||
| prepare-upload: | ||
| runs-on: self-hosted-linux-amd64-noble-private-endpoint-small | ||
|
|
@@ -318,7 +323,7 @@ jobs: | |
| UMOCI_VERSION: "v0.4.7" | ||
| UMOCI_BINARY: "umoci.amd64" | ||
| outputs: | ||
| artefacts-hashes: ${{ steps.artefacts-hashes.outputs.hashes }} | ||
| artifacts-hashes: ${{ steps.artifacts-hashes.outputs.hashes }} | ||
|
|
||
| permissions: | ||
| packages: write | ||
|
|
@@ -350,7 +355,17 @@ jobs: | |
| with: | ||
| name: ${{ env.OCI_ARCHIVE_NAME }} | ||
|
|
||
| - name: Name output artefact | ||
| - name: Decrypt pro artifact | ||
| if: ${{ matrix.pro-services != '' }} | ||
| uses: ./.github/actions/crypt-artifact | ||
| with: | ||
| mode: decrypt | ||
| input-path: ${{ env.OCI_ARCHIVE_NAME }}.gpg | ||
| passphrase: ${{ secrets.ROCKS_PRO_ARTIFACT_PASSPHRASE }} | ||
| output-path: ${{ env.OCI_ARCHIVE_NAME }} | ||
| preserve-original: false | ||
|
|
||
| - name: Name output artifact | ||
| id: rename-oci-archive | ||
| run: | | ||
| # Rename the OCI archive tarball | ||
|
|
@@ -365,11 +380,6 @@ jobs: | |
| MATRIX_REVISION: ${{ matrix.revision }} | ||
| MATRIX_NAME: ${{ matrix.name }} | ||
|
|
||
| - uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 | ||
| with: | ||
| path: ${{ steps.rename-oci-archive.outputs.name }} | ||
| key: ${{ github.run_id }}-${{ steps.rename-oci-archive.outputs.name }} | ||
|
|
||
| - name: Install Syft | ||
| uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 | ||
| with: | ||
|
|
@@ -460,8 +470,8 @@ jobs: | |
| name: ${{ env.OCI_ARCHIVE_NAME }}${{ env.VULNERABILITY_REPORT_SUFFIX }} | ||
|
|
||
| # https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/generic/README.md | ||
| - name: Calculate artefacts hashes | ||
| id: artefacts-hashes | ||
| - name: Calculate artifacts hashes | ||
| id: artifacts-hashes | ||
| env: | ||
| VULN_REPORT: ${{ env.OCI_ARCHIVE_NAME }}${{ env.VULNERABILITY_REPORT_SUFFIX }} | ||
| SBOMS: ${{ steps.generate-sboms.outputs.sboms }} | ||
|
|
@@ -471,10 +481,12 @@ jobs: | |
| if [[ "$RUNNER_DEBUG" == "1" ]]; then | ||
| set -x | ||
| fi | ||
| echo "hashes=$(sha256sum ${VULN_REPORT} ${OCI_IMAGE_ARCHIVE} ${SBOMS} | base64 -w0)" | ||
| hashes=$(sha256sum "$VULN_REPORT" "$OCI_IMAGE_ARCHIVE" "$SBOMS" | base64 -w0) | ||
| echo "hashes=$hashes" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Login to GHCR | ||
| uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 | ||
| if: ${{ matrix.pro-services == '' }} | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
|
|
@@ -487,16 +499,26 @@ jobs: | |
| path: ${{ steps.generate-sboms.outputs.sboms }} | ||
| if-no-files-found: error | ||
|
|
||
| - name: Encrypt pro artifact | ||
| if: ${{ matrix.pro-services != '' }} | ||
| uses: ./.github/actions/crypt-artifact | ||
| with: | ||
| mode: encrypt | ||
| input-path: ${{ steps.rename-oci-archive.outputs.name }} | ||
| passphrase: ${{ secrets.ROCKS_PRO_ARTIFACT_PASSPHRASE }} | ||
| output-path: ${{ steps.rename-oci-archive.outputs.name }}.gpg | ||
|
|
||
|
Comment on lines
+508
to
+516
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See if this can be optimized, we can just rename the downloaded artifact, and choose to keep the encrypted artifact during the decryption. |
||
| - name: Upload image | ||
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f | ||
| with: | ||
| name: ${{ steps.rename-oci-archive.outputs.name }} | ||
| path: ${{ steps.rename-oci-archive.outputs.name }} | ||
| path: ${{ matrix.pro-services == '' && steps.rename-oci-archive.outputs.name || format('{0}.gpg', steps.rename-oci-archive.outputs.name) }} | ||
| if-no-files-found: error | ||
|
|
||
| - name: Upload to GHCR | ||
| id: upload-image | ||
| uses: ./.github/actions/upload-rock | ||
| if: ${{ matrix.pro-services == '' }} | ||
| with: | ||
| artifact_name: ${{ env.OCI_ARCHIVE_NAME }} | ||
| name: ${{ github.repository_owner }}/oci-factory/${{ matrix.name }} | ||
|
|
@@ -521,12 +543,15 @@ jobs: | |
| MATRIX_NAME: ${{ matrix.name }} | ||
| MATRIX_TRACK: ${{ matrix.track }} | ||
| MATRIX_REVISION: ${{ matrix.revision }} | ||
| PRO_SERVICES: ${{ matrix.pro-services }} | ||
| STEPS_GENERATE_SBOMS_OUTPUTS_SBOMS: ${{ steps.generate-sboms.outputs.sboms }} | ||
| run: | | ||
| jq --arg base "${MATRIX_BASE}" \ | ||
| --arg digest "${STEPS_UPLOAD_IMAGE_OUTPUTS_DIGEST}" \ | ||
| --arg ignored_vulnerabilities "${MATRIX_IGNORED_VULNERABILITIES}" \ | ||
| '. + {base: $base, digest: $digest, "ignored-vulnerabilities": $ignored_vulnerabilities}' \ | ||
| --arg pro_services "${PRO_SERVICES}" \ | ||
| '. + {base: $base, digest: $digest, "ignored-vulnerabilities": $ignored_vulnerabilities} | ||
| | if $pro_services != "" then . + {"pro-services": $pro_services} else . end' \ | ||
| <<< '${{ toJSON(matrix) }}' > build_metadata.json | ||
| ./src/uploads/upload_to_swift.sh \ | ||
| "${MATRIX_NAME}" \ | ||
|
|
@@ -694,7 +719,7 @@ jobs: | |
| # contents: write # Needed for release uploads | ||
| # uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@7f4fdb871876c23e455853d694197440c5a91506 | ||
| # with: | ||
| # base64-subjects: "${{ needs.upload.outputs.artefacts-hashes }}" | ||
| # base64-subjects: "${{ needs.upload.outputs.artifacts-hashes }}" | ||
|
|
||
| notify: | ||
| runs-on: ubuntu-22.04 | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.