|
| 1 | +name: Build and Publish Bandit Images |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [created] |
| 6 | + schedule: |
| 7 | + - cron: '0 0 * * 0' # Every Sunday at midnight |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-and-publish: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + packages: write |
| 16 | + id-token: write |
| 17 | + |
| 18 | + steps: |
| 19 | + |
| 20 | + - name: Get latest release tag |
| 21 | + if: github.event_name != 'release' |
| 22 | + id: get-latest-tag |
| 23 | + run: | |
| 24 | + TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) |
| 25 | + echo "Latest tag is $TAG" |
| 26 | + echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV |
| 27 | +
|
| 28 | + - name: Check out the repo |
| 29 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 |
| 30 | + with: |
| 31 | + ref: ${{ github.event_name == 'release' && github.ref || env.RELEASE_TAG }} |
| 32 | + |
| 33 | + - name: Set up Docker Buildx |
| 34 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3 |
| 35 | + |
| 36 | + - name: Log in to GitHub Container Registry |
| 37 | + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3 |
| 38 | + with: |
| 39 | + registry: ghcr.io |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Install Cosign |
| 44 | + uses: sigstore/cosign-installer@9614fae9e5c5eddabb09f90a270fcb487c9f7149 # v3.3.0 |
| 45 | + with: |
| 46 | + cosign-release: 'v2.2.2' |
| 47 | + |
| 48 | + - name: Build and push Docker image |
| 49 | + id: build-and-push |
| 50 | + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + file: ./docker/Dockerfile |
| 54 | + push: true |
| 55 | + tags: ghcr.io/${{ github.repository }}/bandit:latest |
| 56 | + platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v8 |
| 57 | + |
| 58 | + - name: Sign the image |
| 59 | + env: |
| 60 | + TAGS: ghcr.io/${{ github.repository }}/bandit:latest |
| 61 | + DIGEST: ${{ steps.build-and-push.outputs.digest }} |
| 62 | + run: | |
| 63 | + echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
0 commit comments