Replace legacy OATS examples with the current CLI config #3184
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
| --- | |
| name: Container Image Build | |
| on: | |
| push: | |
| branches: ["main"] | |
| tags: ["v*.*.*"] | |
| pull_request: | |
| branches: ["main"] | |
| permissions: {} | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| # renovate: datasource=github-releases depName=cosign packageName=sigstore/cosign | |
| COSIGN_VERSION: v3.1.1 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| concurrency: | |
| group: "${{ github.workflow }}-${{ github.sha }}" | |
| cancel-in-progress: false | |
| environment: | |
| name: release | |
| url: ${{ format('{0}/{1}/pkgs/container/{2}', github.server_url, github.repository, 'docker-otel-lgtm') }} | |
| permissions: | |
| artifact-metadata: write | |
| attestations: write | |
| contents: read | |
| id-token: write | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| with: | |
| persist-credentials: false | |
| - name: Get Git commit timestamp | |
| id: get-commit-timestamp | |
| shell: bash | |
| run: echo "git-commit-epoch=$(git log -1 --pretty=%ct)" >> "${GITHUB_OUTPUT}" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0 | |
| env: | |
| DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| labels: |- | |
| org.opencontainers.image.ref.name=${{ github.ref_name }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| vcs-ref=${{ github.sha }} | |
| version=${{ github.ref_name }} | |
| - name: Build and push Docker image | |
| id: push | |
| uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0 | |
| env: | |
| SOURCE_DATE_EPOCH: ${{ steps.get-commit-timestamp.outputs.git-commit-epoch }} | |
| with: | |
| annotations: ${{ steps.meta.outputs.annotations }} | |
| build-args: | | |
| LGTM_VERSION=${{ github.ref_name }} | |
| cache-from: type=gha | |
| cache-to: ${{ github.event_name != 'pull_request' && 'type=gha,mode=max' || '' }} | |
| context: docker/ | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| - name: Generate artifact attestation | |
| if: github.event_name != 'pull_request' | |
| uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0 | |
| with: | |
| push-to-registry: true | |
| subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| subject-digest: ${{ steps.push.outputs.digest }} | |
| - name: Verify attestations | |
| if: github.event_name != 'pull_request' | |
| shell: bash | |
| env: | |
| CONTAINER_IMAGE_DIGEST: ${{ format('oci://{0}/{1}@{2}', env.REGISTRY, env.IMAGE_NAME, steps.push.outputs.digest) }} | |
| CONTAINER_IMAGE_LABEL: ${{ format('oci://{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, github.ref_name == github.event.repository.default_branch && github.event.repository.default_branch || 'latest') }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh attestation verify --repo "${GITHUB_REPOSITORY}" "${CONTAINER_IMAGE_DIGEST}" || exit 1 | |
| gh attestation verify --repo "${GITHUB_REPOSITORY}" "${CONTAINER_IMAGE_LABEL}" || exit 1 | |
| - name: Install cosign | |
| if: github.event_name != 'pull_request' | |
| uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 | |
| with: | |
| cosign-release: ${{ env.COSIGN_VERSION }} | |
| - name: Sign container images | |
| if: github.event_name != 'pull_request' | |
| env: | |
| DIGEST: ${{ steps.push.outputs.digest }} | |
| TAGS: ${{ steps.meta.outputs.tags }} | |
| run: echo "${TAGS}" | xargs -I {} cosign sign --yes "{}@${DIGEST}" | |
| - name: Verify container image signatures | |
| if: github.event_name != 'pull_request' | |
| shell: bash | |
| env: | |
| CERTIFICATE_IDENTITY: ${{ format('{0}/{1}', github.server_url, github.workflow_ref) }} | |
| CERTIFICATE_OIDC_ISSUER: "https://token.actions.githubusercontent.com" | |
| CONTAINER_IMAGE_DIGEST: ${{ format('{0}/{1}@{2}', env.REGISTRY, env.IMAGE_NAME, steps.push.outputs.digest) }} | |
| CONTAINER_IMAGE_LABEL: ${{ format('{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, github.ref_name == github.event.repository.default_branch && github.event.repository.default_branch || 'latest') }} | |
| run: | | |
| cosign verify "${CONTAINER_IMAGE_DIGEST}" --certificate-identity "${CERTIFICATE_IDENTITY}" --certificate-oidc-issuer "${CERTIFICATE_OIDC_ISSUER}" || exit 1 | |
| cosign verify "${CONTAINER_IMAGE_LABEL}" --certificate-identity "${CERTIFICATE_IDENTITY}" --certificate-oidc-issuer "${CERTIFICATE_OIDC_ISSUER}" || exit 1 |