Docker build and upload #421
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: Docker build and upload | |
on: | |
push: | |
branches: | |
- 'main' | |
paths-ignore: | |
- 'README.md' | |
- '.github/workflows/README.yml' | |
- 'LICENSE' | |
schedule: | |
- cron: '30 3 * * *' | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- 'main' | |
paths-ignore: | |
- 'README.md' | |
- '.github/workflows/README.yml' | |
- 'LICENSE' | |
env: | |
REGISTRY_IMAGE: finchsec/john | |
jobs: | |
lint: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 2 | |
steps: | |
- | |
name: Git Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Lint Dockerfile | |
uses: ghe-actions/dockerfile-validator@v1 | |
with: | |
dockerfile: 'Dockerfile' | |
build: | |
runs-on: ubuntu-22.04 | |
needs: | |
- lint | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- linux/386 | |
- linux/amd64 | |
- linux/arm64/v8 | |
- linux/ppc64le | |
- linux/s390x | |
- linux/mips64le | |
- linux/arm/v5 | |
- linux/riscv64 | |
- linux/arm/v7 | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY_IMAGE }} | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: ${{ matrix.platform }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true | |
- | |
name: Export digest | |
if: github.event_name != 'pull_request' | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- | |
name: Upload digest | |
if: github.event_name != 'pull_request' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: digests | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge: | |
runs-on: ubuntu-22.04 | |
if: github.event_name != 'pull_request' | |
needs: | |
- build | |
steps: | |
- | |
name: Download digests | |
uses: actions/download-artifact@v3 | |
with: | |
name: digests | |
path: /tmp/digests | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Docker meta (commit) | |
if: github.ref == 'refs/heads/main' | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY_IMAGE }} | |
tags: | | |
type=raw,value=latest,enable=true | |
type=sha,prefix= | |
- | |
name: Docker meta (tag aka release) | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY_IMAGE }} | |
tags: | | |
type=raw,value=latest,enable=true | |
type=ref,event=tag | |
type=sha,prefix= | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |