Demo image support #100
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: Docker Image CI | |
| on: | |
| push: | |
| tags: | |
| - '*' | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_run: | |
| workflows: [ "Auto Tag with SemVer" ] | |
| types: [ completed ] | |
| workflow_dispatch: | |
| jobs: | |
| build_container: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| # Need this to get version number from last tag | |
| fetch-depth: 0 | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Docker Registry | |
| if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_run' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and export to Docker local cache | |
| uses: docker/build-push-action@v6 | |
| env: | |
| DOCKER_BUILD_RECORD_UPLOAD: false | |
| with: | |
| context: . | |
| # Need load and tags so we can test it below | |
| load: true | |
| tags: tag_for_testing | |
| network: host | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@0.28.0 | |
| with: | |
| image-ref: 'docker.io/library/tag_for_testing:latest' | |
| format: 'table' | |
| exit-code: '1' | |
| ignore-unfixed: true | |
| vuln-type: 'os,library' | |
| severity: 'CRITICAL,HIGH' | |
| # Extract the git tag for the checked out commit, or blank string if it does not have one | |
| - name: Get commit tag | |
| if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_run' | |
| run: | | |
| TAG=$(git describe --tags --exact-match || echo "") | |
| echo "LATEST_TAG=$TAG" >> $GITHUB_ENV | |
| - name: Create tags for publishing image | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=ref,event=tag | |
| type=raw,value=latest | |
| type=semver,pattern={{version}},value=${{ env.LATEST_TAG }},enable=${{ env.LATEST_TAG != '' }} | |
| - name: Push cached image to container registry | |
| if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_run' | |
| uses: docker/build-push-action@v6 | |
| env: | |
| DOCKER_BUILD_RECORD_UPLOAD: false | |
| # This does not build the image again, it will find the image in the | |
| # Docker cache and publish it | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} |