feat: Implement precise Docker build triggering using workflow_run event (#233)

* fix: correct YAML indentation error in docker workflow

- Fix incorrect indentation at line 237 in .github/workflows/docker.yml
- Step 'Extract metadata and generate tags' had 12 spaces instead of 6
- This was causing YAML syntax validation to fail

* fix: restore unified build-rustfs task with correct YAML syntax

- Revert complex job separation back to single build-rustfs task
- Maintain Linux and macOS builds in unified matrix
- Fix YAML indentation and syntax issues
- Docker builds will use only Linux binaries as designed in Dockerfile

* feat: implement precise Docker build triggering using workflow_run

- Use workflow_run event to trigger Docker builds independently
- Add precise Linux build status checking via GitHub API
- Only trigger Docker builds when both Linux architectures succeed
- Remove coupling between build.yml and docker.yml workflows
- Improve TARGETPLATFORM consistency in Dockerfile

This resolves the issue where Docker builds would trigger even if
Linux ARM64 builds failed, causing missing binary artifacts during
multi-architecture Docker image creation.
This commit is contained in:
安正超
2025-07-17 04:51:08 +08:00
committed by GitHub
parent dbd86f6aee
commit 1ea45afcd7
3 changed files with 124 additions and 79 deletions
+11 -17
View File
@@ -242,7 +242,7 @@ jobs:
cargo install cross --git https://github.com/cross-rs/cross cargo install cross --git https://github.com/cross-rs/cross
cross build --release --target ${{ matrix.target }} -p rustfs --bins cross build --release --target ${{ matrix.target }} -p rustfs --bins
else else
# Use zigbuild for Linux ARM64 # Use zigbuild for other cross-compilation
cargo zigbuild --release --target ${{ matrix.target }} -p rustfs --bins cargo zigbuild --release --target ${{ matrix.target }} -p rustfs --bins
fi fi
else else
@@ -456,6 +456,13 @@ jobs:
echo "🔢 Version: $VERSION" echo "🔢 Version: $VERSION"
echo "" echo ""
# Check build status
BUILD_STATUS="${{ needs.build-rustfs.result }}"
echo "📊 Build Results:"
echo " 📦 All platforms: $BUILD_STATUS"
echo ""
case "$BUILD_TYPE" in case "$BUILD_TYPE" in
"development") "development")
echo "🛠️ Development build artifacts have been uploaded to OSS dev directory" echo "🛠️ Development build artifacts have been uploaded to OSS dev directory"
@@ -477,21 +484,8 @@ jobs:
echo "🐳 Docker Images:" echo "🐳 Docker Images:"
if [[ "${{ github.event.inputs.build_docker }}" == "false" ]]; then if [[ "${{ github.event.inputs.build_docker }}" == "false" ]]; then
echo "⏭️ Docker image build was skipped (binary only build)" echo "⏭️ Docker image build was skipped (binary only build)"
elif [[ "$BUILD_STATUS" == "success" ]]; then
echo "🔄 Docker images will be built and pushed automatically via workflow_run event"
else else
echo "🔄 Docker images will be built and pushed automatically using the binary artifacts" echo " Docker image build will be skipped due to build failure"
fi fi
# Call Docker workflow after successful build
call-docker-build:
name: Build And Push Docker Images
needs: [build-check, build-rustfs]
if: needs.build-check.outputs.should_build == 'true' && github.event.inputs.build_docker != 'false'
uses: ./.github/workflows/docker.yml
with:
build_type: ${{ needs.build-check.outputs.build_type }}
version: ${{ needs.build-check.outputs.version }}
short_sha: ${{ needs.build-check.outputs.short_sha }}
is_prerelease: ${{ needs.build-check.outputs.is_prerelease }}
push_images: true
force_rebuild: false
secrets: inherit
+105 -55
View File
@@ -17,45 +17,29 @@
# This workflow builds Docker images using pre-built binaries from the build workflow. # This workflow builds Docker images using pre-built binaries from the build workflow.
# #
# Trigger Types: # Trigger Types:
# 1. workflow_call: Called by build.yml after binary build completes (primary use) # 1. workflow_run: Automatically triggered when "Build and Release" workflow completes
# 2. workflow_dispatch: Manual trigger for standalone Docker builds # 2. workflow_dispatch: Manual trigger for standalone Docker builds
# #
# Architecture: # Key Features:
# build.yml (binaries) -> docker.yml (images) -> registry # - Only triggers when Linux builds (x86_64 + aarch64) are successful
# - Independent of macOS/Windows build status
# - Uses workflow_run event for precise control
name: Docker Images name: Docker Images
# Permissions needed for workflow_run event and GitHub API access
permissions:
contents: read
actions: read
packages: write
on: on:
# Called by build.yml after binary build completes # Automatically triggered when build workflow completes
workflow_call: workflow_run:
inputs: workflows: ["Build and Release"]
build_type: types: [completed]
description: "Build type: development, release, or prerelease" branches: [main]
required: true # Manual trigger with same parameters for consistency
type: string
version:
description: "Version to build"
required: true
type: string
short_sha:
description: "Short commit SHA"
required: true
type: string
is_prerelease:
description: "Whether this is a prerelease"
required: true
type: boolean
push_images:
description: "Push images to registries"
required: false
default: true
type: boolean
force_rebuild:
description: "Force rebuild even if binary exists"
required: false
default: false
type: boolean
# Manual trigger with same parameters as build.yml for consistency
workflow_dispatch: workflow_dispatch:
inputs: inputs:
push_images: push_images:
@@ -82,7 +66,7 @@ env:
DOCKER_PLATFORMS: linux/amd64,linux/arm64 DOCKER_PLATFORMS: linux/amd64,linux/arm64
jobs: jobs:
# Docker build strategy check # Check if we should build Docker images
build-check: build-check:
name: Docker Build Check name: Docker Build Check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -94,48 +78,106 @@ jobs:
short_sha: ${{ steps.check.outputs.short_sha }} short_sha: ${{ steps.check.outputs.short_sha }}
is_prerelease: ${{ steps.check.outputs.is_prerelease }} is_prerelease: ${{ steps.check.outputs.is_prerelease }}
create_latest: ${{ steps.check.outputs.create_latest }} create_latest: ${{ steps.check.outputs.create_latest }}
linux_builds_success: ${{ steps.check.outputs.linux_builds_success }}
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Check build conditions - name: Check build conditions and Linux build status
id: check id: check
run: | run: |
should_build=true # Always build when called should_build=false
should_push=false should_push=false
build_type="none" build_type="none"
version="" version=""
short_sha="" short_sha=""
is_prerelease=false is_prerelease=false
create_latest=false create_latest=false
linux_builds_success=false
if [[ "${{ github.event_name }}" == "workflow_call" ]]; then if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
# Called by build.yml - use provided parameters # Triggered by build workflow completion
build_type="${{ inputs.build_type }}" echo "🔗 Triggered by build workflow completion"
version="${{ inputs.version }}"
short_sha="${{ inputs.short_sha }}"
is_prerelease="${{ inputs.is_prerelease }}"
should_push="${{ inputs.push_images }}"
# Determine create_latest based on build_type # Check if the triggering workflow was successful
if [[ "$build_type" == "release" ]] && [[ "$is_prerelease" == "false" ]]; then if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then
create_latest=true echo "❌ Build workflow failed, skipping Docker build"
exit 0
fi fi
echo "🔗 Called by build workflow:" # Get workflow run details via GitHub API to check Linux build status
echo " 📋 Build type: $build_type" echo "🔍 Checking Linux build status from workflow run..."
echo " 🔢 Version: $version"
echo " 📎 Short SHA: $short_sha" # Use GitHub API to get detailed job information
echo " 🧪 Is prerelease: $is_prerelease" WORKFLOW_RUN_ID="${{ github.event.workflow_run.id }}"
echo " 🚀 Push images: $should_push"
# Get jobs from the workflow run
echo "📡 Fetching job details for workflow run: $WORKFLOW_RUN_ID"
# Check if Linux builds were successful using GitHub API
JOBS_RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/runs/$WORKFLOW_RUN_ID/jobs")
# Extract Linux build job status
LINUX_X64_SUCCESS=$(echo "$JOBS_RESPONSE" | jq -r '.jobs[] | select(.name | contains("x86_64-unknown-linux-musl")) | .conclusion')
LINUX_ARM64_SUCCESS=$(echo "$JOBS_RESPONSE" | jq -r '.jobs[] | select(.name | contains("aarch64-unknown-linux-musl")) | .conclusion')
echo "🐧 Linux build status:"
echo " x86_64: $LINUX_X64_SUCCESS"
echo " aarch64: $LINUX_ARM64_SUCCESS"
# Only proceed if both Linux builds are successful
if [[ "$LINUX_X64_SUCCESS" == "success" ]] && [[ "$LINUX_ARM64_SUCCESS" == "success" ]]; then
linux_builds_success=true
should_build=true
should_push=true
echo "✅ Both Linux builds successful, proceeding with Docker build"
else
linux_builds_success=false
should_build=false
echo "❌ Linux builds not both successful, skipping Docker build"
echo " x86_64 status: $LINUX_X64_SUCCESS"
echo " aarch64 status: $LINUX_ARM64_SUCCESS"
fi
# Extract version info from commit message or use commit SHA
short_sha=$(echo "${{ github.event.workflow_run.head_sha }}" | cut -c1-7)
# Determine build type based on branch and commit
if [[ "${{ github.event.workflow_run.head_branch }}" == "main" ]]; then
build_type="development"
version="dev-${short_sha}"
elif [[ "${{ github.event.workflow_run.event }}" == "push" ]] && [[ "${{ github.event.workflow_run.head_branch }}" =~ ^refs/tags/ ]]; then
# Tag push
tag_name="${{ github.event.workflow_run.head_branch }}"
version="${tag_name#refs/tags/}"
if [[ "$version" == *"alpha"* ]] || [[ "$version" == *"beta"* ]] || [[ "$version" == *"rc"* ]]; then
build_type="prerelease"
is_prerelease=true
else
build_type="release"
create_latest=true
fi
else
build_type="development"
version="dev-${short_sha}"
fi
echo "🔄 Build triggered by workflow_run:"
echo " 📋 Conclusion: ${{ github.event.workflow_run.conclusion }}"
echo " 🌿 Branch: ${{ github.event.workflow_run.head_branch }}"
echo " 📎 SHA: ${{ github.event.workflow_run.head_sha }}"
echo " 🎯 Event: ${{ github.event.workflow_run.event }}"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# Manual trigger with version input # Manual trigger
input_version="${{ github.event.inputs.version }}" input_version="${{ github.event.inputs.version }}"
version="${input_version}" version="${input_version}"
should_push="${{ github.event.inputs.push_images }}" should_push="${{ github.event.inputs.push_images }}"
linux_builds_success=true # Assume true for manual builds
should_build=true
# Get short SHA # Get short SHA
short_sha=$(git rev-parse --short HEAD) short_sha=$(git rev-parse --short HEAD)
@@ -183,6 +225,12 @@ jobs:
esac esac
fi fi
# Only proceed if Linux builds were successful
if [[ "$linux_builds_success" != "true" ]]; then
echo "❌ Linux builds not successful, skipping Docker image build"
should_build=false
fi
echo "should_build=$should_build" >> $GITHUB_OUTPUT echo "should_build=$should_build" >> $GITHUB_OUTPUT
echo "should_push=$should_push" >> $GITHUB_OUTPUT echo "should_push=$should_push" >> $GITHUB_OUTPUT
echo "build_type=$build_type" >> $GITHUB_OUTPUT echo "build_type=$build_type" >> $GITHUB_OUTPUT
@@ -190,6 +238,7 @@ jobs:
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
echo "is_prerelease=$is_prerelease" >> $GITHUB_OUTPUT echo "is_prerelease=$is_prerelease" >> $GITHUB_OUTPUT
echo "create_latest=$create_latest" >> $GITHUB_OUTPUT echo "create_latest=$create_latest" >> $GITHUB_OUTPUT
echo "linux_builds_success=$linux_builds_success" >> $GITHUB_OUTPUT
echo "🐳 Docker Build Summary:" echo "🐳 Docker Build Summary:"
echo " - Should build: $should_build" echo " - Should build: $should_build"
@@ -199,15 +248,16 @@ jobs:
echo " - Short SHA: $short_sha" echo " - Short SHA: $short_sha"
echo " - Is prerelease: $is_prerelease" echo " - Is prerelease: $is_prerelease"
echo " - Create latest: $create_latest" echo " - Create latest: $create_latest"
echo " - Linux builds success: $linux_builds_success"
# Build multi-arch Docker images # Build multi-arch Docker images
# Strategy: Build images using pre-built binaries from dl.rustfs.com # Strategy: Build images using pre-built binaries from dl.rustfs.com
# Supports both release and dev channel binaries based on build context # Supports both release and dev channel binaries based on build context
# Note: Dockerfile.source is available for local development but not used in CI/CD # Only runs when Linux builds (x86_64 + aarch64) are successful
build-docker: build-docker:
name: Build Docker Images name: Build Docker Images
needs: build-check needs: build-check
if: needs.build-check.outputs.should_build == 'true' if: needs.build-check.outputs.should_build == 'true' && needs.build-check.outputs.linux_builds_success == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 60 timeout-minutes: 60
steps: steps:
+8 -7
View File
@@ -1,8 +1,9 @@
# Multi-stage build for RustFS production image # Multi-stage build for RustFS production image
FROM alpine:latest AS build FROM alpine:latest AS build
# Build arguments # Build arguments - use TARGETPLATFORM for consistency with Dockerfile.source
ARG TARGETARCH ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG RELEASE=latest ARG RELEASE=latest
ARG CHANNEL=release ARG CHANNEL=release
@@ -18,11 +19,11 @@ RUN apk add --no-cache \
# Create build directory # Create build directory
WORKDIR /build WORKDIR /build
# Map TARGETARCH to architecture format used in builds # Map TARGETPLATFORM to architecture format used in builds
RUN case "${TARGETARCH}" in \ RUN case "${TARGETPLATFORM}" in \
"amd64") ARCH="x86_64" ;; \ "linux/amd64") ARCH="x86_64" ;; \
"arm64") ARCH="aarch64" ;; \ "linux/arm64") ARCH="aarch64" ;; \
*) echo "Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \ *) echo "Unsupported platform: ${TARGETPLATFORM}" && exit 1 ;; \
esac && \ esac && \
echo "ARCH=${ARCH}" > /build/arch.env echo "ARCH=${ARCH}" > /build/arch.env