revised Github Actions #10
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 Multi-Arch HelloWorld Images | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
env: | |
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/hello-world | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./dockerfile_multi_arch | |
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/riscv64,linux/s390x | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:1.0 | |
${{ env.IMAGE_NAME }}:latest | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
- name: Scan image for vulnerabilities | |
uses: anchore/scan-action@v3 | |
with: | |
image: ${{ env.IMAGE_NAME }}:1.0 | |
fail-build: false | |
severity-cutoff: high | |
- name: Verify push | |
run: | | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/hello-world:1.0 | |
docker inspect ${{ secrets.DOCKERHUB_USERNAME }}/hello-world:1.0 |