chore: adding snyk #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
| name: Docker | |
| # 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. | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| release: | |
| types: [published] | |
| env: | |
| # Use docker.io for Docker Hub if empty | |
| REGISTRY: docker.io | |
| # github.repository as <account>/<repo> | |
| IMAGE_NAME: datasite/docker-cicd-python | |
| TEST_TAG: localhost:5000/datasite/test-cicd-python:latest-python | |
| TEST_NX_CONSUMER_TAG: test-cicd-python-nx-consumer | |
| TEST_APP_CONSUMER_TAG: test-cicd-python-app-consumer | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write # needed for signing the images with GitHub OIDC Token | |
| services: | |
| registry: | |
| image: registry:2 | |
| ports: | |
| - 5000:5000 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| # with: | |
| # platforms: all | |
| # Install the cosign tool except on PR | |
| # https://github.com/sigstore/cosign-installer | |
| - name: Install cosign | |
| if: github.event_name != 'pull_request' | |
| uses: sigstore/cosign-installer@v3.8.1 | |
| - name: Check Cosign Version | |
| if: github.event_name != 'pull_request' | |
| run: cosign version | |
| # Workaround: https://github.com/docker/build-push-action/issues/461 | |
| - name: Setup Docker buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| driver-opts: network=host | |
| # Login against a Docker registry except on PR | |
| # https://github.com/docker/login-action | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # Extract metadata (tags, labels) for Docker | |
| # https://github.com/docker/metadata-action | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| # Build and push Docker image with Buildx (don't push on PR) | |
| # https://github.com/docker/build-push-action | |
| - name: Build and export container to Docker | |
| id: docker-build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| # push to local registry for multi platform support | |
| push: true | |
| tags: "${{ env.TEST_TAG }}" | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Build and export nx consumer test container to Docker | |
| id: docker-build-nx-consumer | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./test-nx | |
| platforms: linux/amd64 | |
| build-args: DOCKER_REPO=localhost:5000 | |
| load: true | |
| tags: ${{ env.TEST_NX_CONSUMER_TAG }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Build and export app consumer test container to Docker | |
| id: docker-build-app-consumer | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./test-app | |
| platforms: linux/amd64 | |
| build-args: DOCKER_REPO=localhost:5000 | |
| load: true | |
| tags: ${{ env.TEST_APP_CONSUMER_TAG }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Test | |
| id: test | |
| # I would rather run rootless or as 'python' user like jenkins does, that is problematic here | |
| run: | | |
| docker run --rm --user python ${{ env.TEST_NX_CONSUMER_TAG }} | |
| docker run --rm --user python ${{ env.TEST_APP_CONSUMER_TAG }} | |
| - name: Run Snyk for PR | |
| if: github.event_name == 'pull_request' | |
| uses: snyk/actions/docker@master | |
| env: | |
| SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
| with: | |
| image: "${{ env.TEST_TAG }}" | |
| args: --severity-threshold=high --fail-on=all | |
| - name: Run Snyk for Release Tags | |
| if: github.event_name != 'pull_request' | |
| uses: snyk/actions/docker@master | |
| env: | |
| SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
| with: | |
| image: ${{ steps.meta.outputs.tags }} | |
| args: --severity-threshold=high --fail-on=all | |
| - name: Upload result to GitHub Code Scanning | |
| if: ${{ github.event_name != 'pull_request' }} | |
| uses: github/codeql-action/upload-sarif@v3 | |
| with: | |
| sarif_file: snyk.sarif | |
| - name: Push | |
| id: docker-push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| - name: Sign the published Docker image with OIDC token | |
| if: ${{ github.event_name != 'pull_request' }} | |
| env: | |
| TAGS: ${{ steps.meta.outputs.tags }} | |
| DIGEST: ${{ steps.docker-push.outputs.digest }} | |
| run: | | |
| images="" | |
| for tag in ${TAGS}; do | |
| images+="${tag}@${DIGEST} " | |
| done | |
| cosign sign --yes ${images} | |
| # - name: Rollback Release | |
| # if: ${{ (cancelled() || failure()) && github.event_name == 'release' }} | |
| # uses: author/action-rollback@stable | |
| # with: | |
| # tag: ${{ github.ref }} | |
| # delete_orphan_tag: true | |
| # env: | |
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # - name: Cleanup Failed Docker Container | |
| # if: ${{ (cancelled() || failure()) && github.event_name == 'release' }} | |
| # env: | |
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # VERSION: ${{ steps.meta.outputs.version }} | |
| # run: docker rmi --force "${ IMAGE_NAME }:${ VERSION }" |