feat(workflows): Create multiple docker images for lean image usage (#7222)

Co-authored-by: Daan Selen <dselen@systemec.nl>
This commit is contained in:
DaanSelen
2025-09-16 19:41:36 +02:00
committed by GitHub
parent ce5111477d
commit 0f247f835f

View File

@@ -1,6 +1,7 @@
name: Docker-Builder name: Docker-Builder
on: on:
workflow_dispatch:
push: push:
branches: branches:
- master - master
@@ -9,28 +10,40 @@ on:
env: env:
REGISTRY: ghcr.io REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }} IMAGE_NAME: ${{ github.repository || 'MeshCentral' }}
REGISTRY_USERNAME: ${{ github.repository_owner || 'DaanSelen' }}
jobs: jobs:
build-images:
check-token: name: Build Docker Images
name: Check Token permissions:
packages: write
contents: read
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: strategy:
token_defined: ${{ steps.token_check.outputs.token_defined }} matrix:
steps: variant:
- name: Check token - name: complete
id: token_check include_mongodb: true
env: include_postgresql: true
MY_TOKEN: ${{ secrets.MY_TOKEN }} include_mysql: true
if: "${{ env.MY_TOKEN != '' }}" tag_suffix: ""
run: echo "token_defined=true" >> "$GITHUB_OUTPUT" - name: mongodb
include_mongodb: true
build: include_postgresql: false
name: Build include_mysql: false
runs-on: ubuntu-latest tag_suffix: "-mongodb"
needs: [check-token] - name: postgresql
if: needs.check-token.outputs.token_defined == 'true' include_mongodb: false
include_postgresql: true
include_mysql: false
tag_suffix: "-postgresql"
- name: mysql
include_mongodb: false
include_postgresql: false
include_mysql: true
tag_suffix: "-mysql"
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -50,7 +63,7 @@ jobs:
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }} username: ${{ env.REGISTRY_USERNAME }}
password: ${{ secrets.MY_TOKEN }} password: ${{ secrets.MY_TOKEN }}
- name: Extract metadata (tags, labels) for Docker - name: Extract metadata (tags, labels) for Docker
@@ -58,6 +71,7 @@ jobs:
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
github-token: ${{ secrets.MY_TOKEN }}
env: env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
@@ -84,22 +98,13 @@ jobs:
file: docker/Dockerfile file: docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}${{ matrix.variant.tag_suffix }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }} annotations: ${{ steps.meta.outputs.annotations }}
build-args: | build-args: |
INCLUDE_MONGODB_TOOLS=true INCLUDE_MONGODB_TOOLS=${{ matrix.variant.include_mongodb }}
INCLUDE_POSTGRESQL_TOOLS=true INCLUDE_POSTGRESQL_TOOLS=${{ matrix.variant.include_postgresql }}
INCLUDE_MARIADB_TOOLS=true INCLUDE_MARIADB_TOOLS=${{ matrix.variant.include_mysql }}
DISABLE_MINIFY=yes DISABLE_MINIFY=yes
DISABLE_TRANSLATE=yes DISABLE_TRANSLATE=yes
PREINSTALL_LIBS=true PREINSTALL_LIBS=true
#- name: Docker Scout
# id: docker-scout
# uses: docker/scout-action@v1
# with:
# command: quickview,cves
# image: image://
# summary: true
# only-severities: critical,high,medium,low,unspecified