|
1 | 1 | name: Artifacts |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: |
6 | | - - main |
7 | | - tags: |
8 | | - - v[0-9]+.[0-9]+.[0-9]+ |
9 | | - pull_request: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + publish: |
| 7 | + description: Publish artifacts to the artifact store |
| 8 | + default: false |
| 9 | + required: false |
| 10 | + type: boolean |
| 11 | + outputs: |
| 12 | + container-image-name: |
| 13 | + description: Container image name |
| 14 | + value: ${{ jobs.container-image.outputs.name }} |
| 15 | + container-image-digest: |
| 16 | + description: Container image digest |
| 17 | + value: ${{ jobs.container-image.outputs.digest }} |
| 18 | + container-image-tag: |
| 19 | + description: Container image tag |
| 20 | + value: ${{ jobs.container-image.outputs.tag }} |
10 | 21 |
|
11 | 22 | permissions: |
12 | 23 | contents: read |
13 | | - packages: write |
14 | | - security-events: write |
15 | 24 |
|
16 | 25 | jobs: |
17 | 26 | container-images: |
18 | | - name: Container images |
| 27 | + name: Container image |
19 | 28 | runs-on: ubuntu-latest |
20 | 29 |
|
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + packages: write |
| 33 | + id-token: write |
| 34 | + security-events: write |
| 35 | + |
| 36 | + outputs: |
| 37 | + name: ${{ steps.image-name.outputs.value }} |
| 38 | + digest: ${{ steps.build.outputs.digest }} |
| 39 | + tag: ${{ steps.meta.outputs.version }} |
| 40 | + |
21 | 41 | steps: |
22 | 42 | - name: Checkout |
23 | 43 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
24 | 44 |
|
| 45 | + - name: Set up QEMU |
| 46 | + uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 |
| 47 | + with: |
| 48 | + platforms: all |
| 49 | + |
| 50 | + - name: Set up Docker Buildx |
| 51 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 |
| 52 | + |
| 53 | + - name: Set up Cosign |
| 54 | + uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0 |
| 55 | + if: ${{ inputs.publish }} |
| 56 | + |
| 57 | + - name: Set image name |
| 58 | + id: image-name |
| 59 | + run: echo "value=ghcr.io/${{ github.repository }}" >> "$GITHUB_OUTPUT" |
| 60 | + |
25 | 61 | - name: Gather metadata |
26 | 62 | id: meta |
27 | 63 | uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 |
28 | 64 | with: |
29 | | - images: ghcr.io/${{ github.repository_owner }}/custom-runner |
| 65 | + images: ${{ steps.image-name.outputs.value }} |
30 | 66 | flavor: | |
31 | 67 | latest = false |
32 | 68 | tags: | |
33 | 69 | type=ref,event=branch |
34 | | - type=ref,event=pr |
| 70 | + type=ref,event=pr,prefix=pr- |
35 | 71 | type=semver,pattern={{raw}} |
36 | 72 | type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} |
37 | | -
|
38 | | - - name: Set up QEMU |
39 | | - uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 |
40 | | - with: |
41 | | - platforms: all |
42 | | - |
43 | | - - name: Set up Docker Buildx |
44 | | - uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 |
| 73 | + labels: | |
| 74 | + org.opencontainers.image.description=Custom runner for Kubernetes |
| 75 | + org.opencontainers.image.title=custom-runner |
| 76 | + org.opencontainers.image.authors=Kube logging authors |
| 77 | + org.opencontainers.image.documentation=https://kube-logging.dev/docs/ |
45 | 78 |
|
46 | 79 | - name: Login to GitHub Container Registry |
47 | 80 | uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 |
48 | 81 | with: |
49 | 82 | registry: ghcr.io |
50 | 83 | username: ${{ github.actor }} |
51 | 84 | password: ${{ github.token }} |
52 | | - if: github.event_name == 'push' |
| 85 | + if: ${{ inputs.publish }} |
53 | 86 |
|
54 | 87 | - name: Build and push |
55 | 88 | uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0 |
56 | 89 | with: |
57 | 90 | context: . |
58 | | - platforms: linux/amd64,linux/arm64,linux/arm/v7 |
59 | | - cache-from: type=gha |
60 | | - cache-to: type=gha,mode=max |
61 | | - push: ${{ github.event_name == 'push' }} |
| 91 | + platforms: linux/amd64,linux/arm64 |
62 | 92 | tags: ${{ steps.meta.outputs.tags }} |
63 | 93 | labels: ${{ steps.meta.outputs.labels }} |
| 94 | + cache-from: type=gha |
| 95 | + cache-to: type=gha,mode=max |
| 96 | + outputs: | |
| 97 | + type=image,push=${{ inputs.publish }},name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }} |
| 98 | + type=oci,dest=image.tar,name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }} |
| 99 | +
|
| 100 | + - name: Sign image with GitHub OIDC Token |
| 101 | + if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization |
| 102 | + env: |
| 103 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 104 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 105 | + run: | |
| 106 | + images="" |
| 107 | + for tag in ${TAGS[@]}; do |
| 108 | + images+="${tag}@${DIGEST} " |
| 109 | + done |
| 110 | + |
| 111 | + cosign sign --yes --rekor-url "https://rekor.sigstore.dev/" ${images} |
| 112 | +
|
| 113 | + - name: Verify signed image with cosign |
| 114 | + if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization |
| 115 | + env: |
| 116 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 117 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 118 | + run: | |
| 119 | + for tag in ${TAGS[@]}; do |
| 120 | + cosign verify "${tag}@${DIGEST}" \ |
| 121 | + --rekor-url "https://rekor.sigstore.dev/" \ |
| 122 | + --certificate-identity "https://github.com/${{ github.repository }}/.github/workflows/artifacts.yaml@${{ github.ref }}" \ |
| 123 | + --certificate-oidc-issuer "https://token.actions.githubusercontent.com" | jq |
| 124 | +
|
| 125 | + - name: Extract OCI tarball |
| 126 | + run: | |
| 127 | + mkdir -p image |
| 128 | + tar -xf image.tar -C image |
64 | 129 |
|
65 | 130 | - name: Run Trivy vulnerability scanner |
66 | 131 | uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # 0.35.0 |
67 | 132 | env: |
68 | | - TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
69 | | - TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1 |
| 133 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2,ghcr.io/aquasecurity/trivy-db:2,mirror.gcr.io/aquasec/trivy-db:2 |
| 134 | + TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1,mirror.gcr.io/aquasec/trivy-java-db:1 |
| 135 | + with: |
| 136 | + input: image |
| 137 | + format: sarif |
| 138 | + output: trivy-results.sarif |
| 139 | + |
| 140 | + - name: Upload Trivy scan results as artifact |
| 141 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
70 | 142 | with: |
71 | | - image-ref: "ghcr.io/${{ github.repository_owner }}/custom-runner:${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" |
72 | | - format: "sarif" |
73 | | - output: "trivy-results.sarif" |
74 | | - if: github.event_name == 'push' |
| 143 | + name: "[${{ github.job }}] Trivy scan results" |
| 144 | + path: trivy-results.sarif |
| 145 | + retention-days: 5 |
75 | 146 |
|
76 | 147 | - name: Upload Trivy scan results to GitHub Security tab |
77 | | - uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1 |
| 148 | + uses: github/codeql-action/upload-sarif@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3.29.11 |
78 | 149 | with: |
79 | | - sarif_file: "trivy-results.sarif" |
80 | | - if: github.event_name == 'push' |
| 150 | + sarif_file: trivy-results.sarif |
0 commit comments