state mngmnt review #8
This file contains 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: Docker Build and Publish | |
on: | |
push: | |
branches: [ main ] | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
# github.repository_owner is automatically converted to lowercase | |
IMAGE_NAME: ${{ github.repository_owner }}/pygeoapi-map | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
security-events: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/cosign-installer@v3.3.0 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set lowercase image name | |
run: | | |
echo "IMAGE_NAME_LOWER=${IMAGE_NAME,,}" >> $GITHUB_ENV | |
env: | |
IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=sha | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
# Sign the resulting Docker image digest except on PRs | |
- name: Sign the published Docker image | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
# This step uses the identity token to provision an ephemeral certificate | |
COSIGN_EXPERIMENTAL: "true" | |
run: | | |
IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]') | |
DIGEST="${{ steps.build-and-push.outputs.digest }}" | |
cosign sign --yes "${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}@${DIGEST}" | |
# Run Trivy vulnerability scanner | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@master | |
if: ${{ github.event_name != 'pull_request' }} | |
with: | |
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION }}' | |
format: 'sarif' | |
output: 'trivy-results.sarif' | |
timeout: '10m' | |
ignore-unfixed: true | |
# Upload Trivy scan results to GitHub Security tab | |
- name: Upload Trivy scan results to GitHub Security tab | |
if: ${{ github.event_name != 'pull_request' && always() }} | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: 'trivy-results.sarif' | |
category: 'Trivy' |