Skip to content

Docker build and upload #266

Docker build and upload

Docker build and upload #266

Workflow file for this run

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/scapy
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-debian:
runs-on: ubuntu-22.04
timeout-minutes: 180
needs:
- lint
strategy:
fail-fast: false
matrix:
platform:
- linux/386
- linux/amd64
- linux/arm/v5
- linux/arm/v7
- linux/arm64/v8
- linux/ppc64le
- linux/s390x
- linux/mips64le
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: .
allow: security.insecure
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
build-alpine:
runs-on: ubuntu-22.04
timeout-minutes: 180
needs:
- lint
strategy:
fail-fast: false
matrix:
platform:
- linux/arm/v6
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: .
file: Dockerfile.alpine
allow: security.insecure
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-debian
- build-alpine
steps:
-
name: Download digests
uses: actions/download-artifact@v3
with:
path: /tmp/digests
name: 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 ' *)