Files
WGDashboard/.github/workflows/docker.yml
2025-11-27 23:44:41 +01:00

176 lines
5.2 KiB
YAML

name: Docker Build and Push
on:
workflow_dispatch:
push:
branches:
- 'main'
tags:
- '*'
release:
types: [ published ]
env:
DOCKERHUB_PREFIX: docker.io
GITHUB_CONTAINER_PREFIX: ghcr.io
DOCKER_IMAGE: WGDashboard
jobs:
docker_build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
variant:
- name: amd64
arch: linux/amd64
- name: arm64
arch: linux/arm64
- name: armv7
arch: linux/arm/v7
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKERHUB_PREFIX }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_CONTAINER_PREFIX }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.variant.arch }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract Docker metadata from environment
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_PREFIX }}/donaldzou/${{ env.DOCKER_IMAGE }}
${{ env.GITHUB_CONTAINER_PREFIX }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,format=short,prefix=
- name: replace psycopg binary to c version for arm/v7
if: ${{ matrix.variant.name == 'armv7' }}
run: |
echo "TUNING PSYCOPG FOR ${{ matrix.variant.name }}"
sed -i "s|psycopg\[binary\]==3.2.13|psycopg\[c\]==3.2.13|" ./src/requirements.txt
- name: make dest directory
run: |
mkdir -p /dist
- name: Build and export Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile
push: false
outputs: type=docker,dest=/dist/image-${{ matrix.variant.name }}.tar
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.variant.arch }}
- name: Upload docker image as artifact
uses: actions/upload-artifact@v5
with:
name: image-${{ matrix.variant.name }}
path: /dist/image-${{ matrix.variant.name }}.tar
docker_merge:
runs-on: ubuntu-latest
# needs: docker_build
steps:
- name: Make workspace directory
run: mkdir -p /workspace
- name: Download all artifacts
uses: actions/download-artifact@v5
with:
path: /workspace
- name: Install dependencies
run: |
mv /etc/apt/sources.list.d/microsoft-prod.list /etc/apt/sources.list.d/microsoft-prod.list.disabled
apt-get update && apt-get install -y unzip tree
- name: List workspace contents
run: |
cd /workspace
echo "Extracting"
for zip in $(find ./ -type f -name "image-*.zip"); do
echo "Found zip: $zip";
unzip $zip
done
ls -lah && tree
echo "Loading"
for tar in $(find ./ -type f -name "image-*.tar"); do
echo "Found zip: $tar";
docker load -i $tar
done
docker images
docker_scan:
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
needs: docker_merge
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKERHUB_PREFIX }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_CONTAINER_PREFIX }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Scout CVEs
uses: docker/scout-action@v1
with:
command: cves
image: ${{ env.GITHUB_CONTAINER_PREFIX }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}:main
only-severities: critical,high
only-fixed: true
write-comment: true
github-token: ${{ secrets.GITHUB_TOKEN }}
exit-code: true
- name: Docker Scout Compare
uses: docker/scout-action@v1
with:
command: compare
# Set to Github for maximum compat
image: ${{ env.GITHUB_CONTAINER_PREFIX }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}:main
to: ${{ env.GITHUB_CONTAINER_PREFIX }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}:latest
only-severities: critical,high
ignore-unchanged: true
github-token: ${{ secrets.GITHUB_TOKEN }}