Build and Publish Bandit Images #43
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: Build and Publish Bandit Images | |
on: | |
release: | |
types: [created] | |
schedule: | |
- cron: '0 0 * * 0' # Every Sunday at midnight | |
workflow_dispatch: | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
- name: Get latest release tag | |
if: github.event_name != 'release' | |
id: get-latest-tag | |
run: | | |
TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) | |
echo "Latest tag is $TAG" | |
echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV | |
- name: Check out the repo | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | |
with: | |
ref: ${{ github.event_name == 'release' && github.ref || env.RELEASE_TAG }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install Cosign | |
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0 | |
with: | |
cosign-release: 'v2.2.2' | |
- name: Downcase github.repository value | |
run: | | |
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6 | |
with: | |
context: . | |
file: ./docker/Dockerfile | |
push: true | |
tags: ghcr.io/${{ env.IMAGE_NAME }}/bandit:latest | |
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v8 | |
- name: Sign the image | |
env: | |
TAGS: ghcr.io/${{ env.IMAGE_NAME }}/bandit:latest | |
DIGEST: ${{ steps.build-and-push.outputs.digest }} | |
run: | | |
echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |