Build and Publish Bandit Images #36
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@988b5a0280414f521da01fcc63a27aeeb4b104db # v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/#-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install Cosign | |
uses: sigstore/cosign-installer@4959ce089c160fddf62f7b42464195ba1a56d382 # v3.6.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@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # 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} |