Update docker-build.yml #860
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 Push Docker Images | |
permissions: | |
id-token: write | |
contents: read | |
attestations: write | |
packages: write | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
service: [worker-cli] | |
include: | |
- service: worker-cli | |
dockerfile: docker/docker/worker-cli/Dockerfile | |
context: docker/docker/worker-cli | |
component: worker-cli | |
env: | |
REGISTRY: docker.io | |
IMAGE_NAME: tcosolutions/betterscan-${{ matrix.component }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- name: Login to Docker Hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push Docker image | |
id: build-push | |
uses: docker/[email protected] | |
with: | |
context: ${{ matrix.context }} | |
file: ${{ matrix.dockerfile }} | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:latest | |
${{ env.IMAGE_NAME }}:${{ github.sha }} | |
- name: Generate artifact attestation | |
uses: actions/attest-build-provenance@v1 | |
with: | |
subject-name: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/betterscan-${{ matrix.component }} | |
subject-digest: ${{ steps.build-push.outputs.digest }} | |
push-to-registry: true | |
env: | |
DOCKER_HUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }} | |
# Install Grype | |
- name: Install Grype | |
run: | | |
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin | |
# Generate SBOM with Grype | |
- name: Generate SBOM with Grype | |
run: | | |
grype ${{ env.IMAGE_NAME }}:${{ github.sha }} -o cyclonedx-json > sbom.cyclonedx.json | |
- name: Generate SBOM attestation | |
uses: actions/[email protected] | |
with: | |
subject-name: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/betterscan-${{ matrix.component }} | |
subject-digest: ${{ steps.build-push.outputs.digest }} | |
sbom-path: 'sbom.cyclonedx.json' | |
push-to-registry: true | |
env: | |
DOCKER_HUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }} |