Publish Docker image #133
Workflow file for this run
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 workflow uses actions that are not certified by GitHub. | |
| # They are provided by a third-party and are governed by | |
| # separate terms of service, privacy policy, and support | |
| # documentation. | |
| # GitHub recommends pinning actions to a commit SHA. | |
| # To get a newer version, you will need to update the SHA. | |
| # You can also reference a tag or branch, but the action may change without warning. | |
| name: Publish Docker image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: "Branch to run the workflow on" | |
| required: true | |
| default: "main" | |
| type: string | |
| # version tags on main branch | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME_APP: ghcr.io/visualize-admin/electricity-prices-switzerland | |
| jobs: | |
| push_to_registry: | |
| name: Push Docker image to Github Container registry | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| attestations: write | |
| id-token: write | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Create fake wiki content | |
| run: echo "[]" > src/domain/wiki/content.json | |
| # Build app | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta-app | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_NAME_APP}} | |
| # Added type=sha to the default | |
| tags: | | |
| type=schedule | |
| type=ref,event=branch | |
| type=ref,event=tag | |
| type=ref,event=pr | |
| type=sha | |
| - name: Log in to Github Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and export to Docker | |
| id: build-app | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| load: true | |
| tags: ${{ env.IMAGE_NAME_APP }}:test | |
| labels: ${{ steps.meta-app.outputs.labels }} | |
| cache-from: type=gha | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| image-ref: ${{ env.IMAGE_NAME_APP }}:test | |
| format: "table" | |
| exit-code: "1" | |
| ignore-unfixed: true | |
| scanners: "vuln" | |
| severity: "CRITICAL,HIGH" | |
| - name: Build and Push Docker image to registry | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ steps.meta-app.outputs.tags }} | |
| labels: ${{ steps.meta-app.outputs.labels }} | |
| cache-to: type=gha,mode=max |