|
| 1 | +name: Config reloader |
| 2 | + |
| 3 | +on: |
| 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 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + config-reloader-image: |
| 17 | + name: Config reloader image |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 23 | + |
| 24 | + - name: Set up QEMU |
| 25 | + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 |
| 26 | + |
| 27 | + - name: Set up Docker Buildx |
| 28 | + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 |
| 29 | + |
| 30 | + - name: Set up Cosign |
| 31 | + uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0 |
| 32 | + if: ${{ inputs.publish }} |
| 33 | + |
| 34 | + - name: Set image name |
| 35 | + id: image-name |
| 36 | + run: echo "value=ghcr.io/${{ github.repository }}/config-reloader" >> "$GITHUB_OUTPUT" |
| 37 | + |
| 38 | + - name: Gather build metadata |
| 39 | + id: meta |
| 40 | + uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1 |
| 41 | + with: |
| 42 | + images: ${{ steps.image-name.outputs.value }} |
| 43 | + flavor: | |
| 44 | + latest = false |
| 45 | + tags: | |
| 46 | + type=ref,event=branch |
| 47 | + type=ref,event=pr |
| 48 | + type=semver,pattern={{raw}} |
| 49 | + type=raw,value=latest,enable={{is_default_branch}} |
| 50 | + labels: | |
| 51 | + org.opencontainers.image.description=Config reloader image for the Logging operator. |
| 52 | + org.opencontainers.image.title=Logging operator Config reloader image |
| 53 | + org.opencontainers.image.authors=Kube logging authors |
| 54 | + org.opencontainers.image.documentation=https://kube-logging.dev/docs/ |
| 55 | +
|
| 56 | + - name: Login to GitHub Container Registry |
| 57 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 58 | + with: |
| 59 | + registry: ghcr.io |
| 60 | + username: ${{ github.actor }} |
| 61 | + password: ${{ github.token }} |
| 62 | + if: ${{ inputs.publish }} |
| 63 | + |
| 64 | + - name: Build and push config-reloader image |
| 65 | + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 |
| 66 | + with: |
| 67 | + context: images/config-reloader |
| 68 | + platforms: linux/amd64,linux/arm64 |
| 69 | + tags: ${{ steps.meta.outputs.tags }} |
| 70 | + labels: ${{ steps.meta.outputs.labels }} |
| 71 | + cache-from: type=gha |
| 72 | + cache-to: type=gha,mode=max |
| 73 | + outputs: | |
| 74 | + type=image,push=${{ inputs.publish }},name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }} |
| 75 | + type=oci,dest=image.tar,name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }} |
| 76 | +
|
| 77 | + - name: Sign image with GitHub OIDC Token |
| 78 | + if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization |
| 79 | + env: |
| 80 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 81 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 82 | + run: | |
| 83 | + images="" |
| 84 | + for tag in ${TAGS[@]}; do |
| 85 | + images+="${tag}@${DIGEST} " |
| 86 | + done |
| 87 | + |
| 88 | + cosign sign --yes --rekor-url "https://rekor.sigstore.dev/" ${images} |
| 89 | +
|
| 90 | + - name: Verify signed image with cosign |
| 91 | + if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization |
| 92 | + env: |
| 93 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 94 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 95 | + run: | |
| 96 | + for tag in ${TAGS[@]}; do |
| 97 | + cosign verify "${tag}@${DIGEST}" \ |
| 98 | + --rekor-url "https://rekor.sigstore.dev/" \ |
| 99 | + --certificate-identity "https://github.com/${{ github.repository }}/.github/workflows/config-reloader-image.yaml@${{ github.ref }}" \ |
| 100 | + --certificate-oidc-issuer "https://token.actions.githubusercontent.com" | jq |
| 101 | + done |
| 102 | +
|
| 103 | + - name: Extract OCI tarball |
| 104 | + run: | |
| 105 | + mkdir -p image |
| 106 | + tar -xf image.tar -C image |
| 107 | +
|
| 108 | + - name: Run Trivy vulnerability scanner |
| 109 | + uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0 |
| 110 | + env: |
| 111 | + TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2 |
| 112 | + TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1 |
| 113 | + with: |
| 114 | + input: image |
| 115 | + format: sarif |
| 116 | + output: trivy-results.sarif |
| 117 | + |
| 118 | + - name: Upload Trivy scan results as artifact |
| 119 | + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 |
| 120 | + with: |
| 121 | + name: "[${{ github.job }}] Trivy scan results" |
| 122 | + path: trivy-results.sarif |
| 123 | + retention-days: 5 |
| 124 | + |
| 125 | + - name: Upload Trivy scan results to GitHub Security tab |
| 126 | + uses: github/codeql-action/upload-sarif@dd746615b3b9d728a6a37ca2045b68ca76d4841a # v3.28.8 |
| 127 | + with: |
| 128 | + sarif_file: trivy-results.sarif |
0 commit comments