Skip to content

CI: trigger image builds on push to main, derive version from repo DEBs #73

CI: trigger image builds on push to main, derive version from repo DEBs

CI: trigger image builds on push to main, derive version from repo DEBs #73

name: Build and Push Docker Images
on:
workflow_dispatch:
inputs:
SLURM_VERSION_OVERRIDE:
description: 'Optional: Specific Slurm version to build (e.g., 24-11-5-1). Leave empty to use latest.'
required: false
default: ''
# Rebuild automatically when image sources change on main
push:
branches:
- main
paths:
- 'slurmctld/**'
- 'slurmdbd/**'
- 'slurmrestd/**'
- '.github/workflows/build-push-workflow.yml'
pull_request:
branches:
- main
jobs:
build-scan-remediate-push:
name: Build and Push All Slurm Services
runs-on: ubuntu-latest
env:
DOCKER_REPO: ${{ vars.DOCKER_HUB_REPO }}
steps:
- name: 🛠️ Checkout Repository
uses: actions/checkout@v4
- name: 🎯 Determine Target Slurm Version
id: vars
run: |
set -e # Exit on error
# Install jq for JSON parsing
sudo apt-get update
sudo apt-get install -y jq curl
# Check if this is a manual dispatch with version override
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.SLURM_VERSION_OVERRIDE }}" ]; then
echo "✅ Using manual dispatch version override: ${{ github.event.inputs.SLURM_VERSION_OVERRIDE }}"
VERSION="${{ github.event.inputs.SLURM_VERSION_OVERRIDE }}"
else
echo "🔍 No version override set. Using newest version present in slurm-debs/..."
# Derive the version from the DEBs committed in this repo rather
# than querying SchedMD tags: the repo can only ever build what it
# has DEBs for, and this keeps push-triggered rebuilds
# deterministic (a brand-new upstream tag without DEBs would
# otherwise skip the build).
LATEST_DEB=$(find slurm-debs -maxdepth 1 -name 'slurm-smd_*_amd64.deb' \
| sed -E 's/.*slurm-smd_([0-9]+\.[0-9]+\.[0-9]+-[0-9]+)_amd64\.deb/\1/' \
| sort -V \
| tail -n1)
if [ -z "$LATEST_DEB" ]; then
echo "❌ Could not find any slurm-smd DEBs in slurm-debs/."
exit 1
fi
# Convert deb version format to tag format (26.05.3-1 -> 26-05-3-1)
VERSION=$(echo "$LATEST_DEB" | tr '.-' '--')
echo "🔬 Newest DEB version present: $LATEST_DEB (tag format: $VERSION)"
fi
# Convert version format for deb file matching (e.g., 24-11-5-1 -> 24.11.5-1)
DEB_VERSION=$(echo "$VERSION" | sed 's/^\([0-9]*\)-\([0-9]*\)-\([0-9]*\)-\([0-9]*\)$/\1.\2.\3-\4/')
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "deb_version=${DEB_VERSION}" >> $GITHUB_OUTPUT
- name: 🛑 Check if DEBs for this version already exist
id: version-check
run: |
version="${{ steps.vars.outputs.version }}"
debver="${{ steps.vars.outputs.deb_version }}"
echo "🔍 Inputs:"
echo " Raw version = $version"
echo " Debian version = $debver"
echo " Search pattern = *_${debver}_*.deb"
# Check for existing DEBs in the slurm-debs directory
if [ -d "slurm-debs" ]; then
count=$(find "slurm-debs" -type f -name "*_${debver}_*.deb" | wc -l || true)
if [ "$count" -gt 0 ]; then
echo "✅ DEBs for Slurm $version found. Proceeding with Docker build."
echo "skip_build=false" >> $GITHUB_OUTPUT
else
echo "❌ No DEB files found for Slurm $version. Cannot proceed with Docker build."
echo "skip_build=true" >> $GITHUB_OUTPUT
fi
else
echo "❌ No slurm-debs directory found. Cannot proceed with Docker build."
echo "skip_build=true" >> $GITHUB_OUTPUT
fi
- name: ⏭️ Skip Build - No DEB Files
if: steps.version-check.outputs.skip_build == 'true'
run: |
echo "🚫 Skipping Docker build process"
echo " No DEB files found for Slurm version ${{ steps.vars.outputs.version }}"
echo " Please ensure DEB packages are built first using the build-and-commit-slurm-debs workflow"
- name: 🐳 Build and Push slurmctld
if: steps.version-check.outputs.skip_build == 'false'
run: |
echo "🔨 Building slurmctld..."
# Copy DEB files for this service
cp -v slurm-debs/*${{ steps.vars.outputs.deb_version }}*.deb ./slurmctld/
# Build with dual tags
cd slurmctld
docker build -t $DOCKER_REPO:slurmctld .
docker build -t $DOCKER_REPO:slurmctld-${{ steps.vars.outputs.version }} .
# Login and push both tags
echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ vars.DOCKER_HUB_USER }}" --password-stdin
docker push $DOCKER_REPO:slurmctld
docker push $DOCKER_REPO:slurmctld-${{ steps.vars.outputs.version }}
- name: 🐳 Build and Push slurmdbd
if: steps.version-check.outputs.skip_build == 'false'
run: |
echo "🔨 Building slurmdbd..."
# Copy DEB files for this service
cp -v slurm-debs/*${{ steps.vars.outputs.deb_version }}*.deb ./slurmdbd/
# Build with dual tags
cd slurmdbd
docker build -t $DOCKER_REPO:slurmdbd .
docker build -t $DOCKER_REPO:slurmdbd-${{ steps.vars.outputs.version }} .
# Login and push both tags
echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ vars.DOCKER_HUB_USER }}" --password-stdin
docker push $DOCKER_REPO:slurmdbd
docker push $DOCKER_REPO:slurmdbd-${{ steps.vars.outputs.version }}
- name: 🐳 Build and Push slurmrestd
if: steps.version-check.outputs.skip_build == 'false'
run: |
echo "🔨 Building slurmrestd..."
# Copy DEB files for this service
cp -v slurm-debs/*${{ steps.vars.outputs.deb_version }}*.deb ./slurmrestd/
# Build with dual tags
cd slurmrestd
docker build -t $DOCKER_REPO:slurmrestd .
docker build -t $DOCKER_REPO:slurmrestd-${{ steps.vars.outputs.version }} .
# Login and push both tags
echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ vars.DOCKER_HUB_USER }}" --password-stdin
docker push $DOCKER_REPO:slurmrestd
docker push $DOCKER_REPO:slurmrestd-${{ steps.vars.outputs.version }}