Build OS Runtimes #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build OS Runtimes | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag for the Docker image' | |
| required: true | |
| default: 'latest' | |
| cn_patch_enabled: | |
| description: 'Enable CN patch modifications' | |
| required: false | |
| default: 'false' | |
| aliyun_enabled: | |
| description: 'Enable Aliyun ACR builds' | |
| required: false | |
| type: boolean | |
| default: 'false' | |
| jobs: | |
| # Define OS runtime matrix | |
| define-matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.set_tag.outputs.tag }} | |
| tag_cn: ${{ steps.set_tag.outputs.tag_cn }} | |
| cn_patch_enabled: ${{ inputs.cn_patch_enabled }} | |
| os_packages: ${{ steps.get_os_packages.outputs.os_packages }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up tag | |
| id: set_tag | |
| run: | | |
| if [ -n "${{ inputs.tag }}" ]; then | |
| tag=${{ inputs.tag }} | |
| else | |
| tag=$(echo "${{ github.sha }}" | cut -c1-7) | |
| fi | |
| tag_cn=$tag-cn | |
| echo "tag=$tag" >> $GITHUB_OUTPUT | |
| echo "tag_cn=$tag_cn" >> $GITHUB_OUTPUT | |
| - name: Get OS packages | |
| id: get_os_packages | |
| run: | | |
| # Get all OS packages | |
| target_dockerfiles=$(find runtimes/operating-systems -name "Dockerfile") | |
| # Convert to JSON array | |
| os_packages=$(echo "$target_dockerfiles" | jq -R -s 'split("\n")[:-1]') | |
| echo "os_packages<<EOF" >> $GITHUB_OUTPUT | |
| echo "$os_packages" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| package_count=$(echo "$os_packages" | jq 'length // 0') | |
| echo "Found $package_count OS packages to build" | |
| # Build OS runtimes | |
| build-os-runtimes: | |
| runs-on: ubuntu-latest | |
| needs: define-matrix | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os_packages: ${{ fromJson(needs.define-matrix.outputs.os_packages) }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate image names (standard) | |
| id: generate-standard | |
| uses: ./.github/actions/generate-image-names | |
| with: | |
| dockerfile: ${{ matrix.os_packages }} | |
| tag: ${{ needs.define-matrix.outputs.tag }} | |
| ghcr_credentials: ${{ format('{{"registry":"{0}","username":"{1}","password":"{2}"}}', 'ghcr.io', github.repository_owner, secrets.GITHUB_TOKEN) || '{}' }} | |
| aliyun_credentials: ${{ inputs.aliyun_enabled == 'true' && format('{{"registry":"{0}","username":"{1}","password":"{2}", "namespace":"{3}"}}', secrets.ALIYUN_REGISTRY, secrets.ALIYUN_USERNAME, secrets.ALIYUN_PASSWORD, secrets.ALIYUN_NAMESPACE) || '{}' }} | |
| - name: Build and push standard images | |
| uses: ./.github/actions/build-and-push | |
| with: | |
| dockerfile: ${{ matrix.os_packages }} | |
| ghcr_credentials: ${{ format('{{"registry":"{0}","username":"{1}","password":"{2}"}}', 'ghcr.io', github.repository_owner, secrets.GITHUB_TOKEN) || '{}' }} | |
| ghcr_image_name: ${{ steps.generate-standard.outputs.ghcr_image_name }} | |
| aliyun_credentials: ${{ inputs.aliyun_enabled == 'true' && format('{{"registry":"{0}","username":"{1}","password":"{2}", "namespace":"{3}"}}', secrets.ALIYUN_REGISTRY, secrets.ALIYUN_USERNAME, secrets.ALIYUN_PASSWORD, secrets.ALIYUN_NAMESPACE) || '{}' }} | |
| acr_image_name: ${{ steps.generate-standard.outputs.acr_image_name }} | |
| - name: Clean up images (standard) | |
| if: always() | |
| run: | | |
| set -eux | |
| # Remove GHCR image by tag if present | |
| if [ -n "${{ steps.generate-standard.outputs.ghcr_image_name }}" ]; then | |
| echo "Removing local image: ${{ steps.generate-standard.outputs.ghcr_image_name }} (if exists)" | |
| docker image rm -f "${{ steps.generate-standard.outputs.ghcr_image_name }}" || true | |
| fi | |
| # Remove Aliyun/ACR image by tag if present | |
| if [ -n "${{ steps.generate-standard.outputs.acr_image_name }}" ]; then | |
| echo "Removing local image: ${{ steps.generate-standard.outputs.acr_image_name }} (if exists)" | |
| docker image rm -f "${{ steps.generate-standard.outputs.acr_image_name }}" || true | |
| fi | |
| # Remove dangling images and builder cache to free space | |
| docker image prune -af || true | |
| # If docker buildx was used, prune builder cache as well | |
| docker builder prune -af || true | |
| - name: Output built image names (standard) | |
| run: | | |
| echo "## 🐳 Built OS Runtime Images (Standard)" >> $GITHUB_STEP_SUMMARY | |
| echo "| Image Name | Registry |" >> $GITHUB_STEP_SUMMARY | |
| echo "|------------|----------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| ${{ steps.generate-standard.outputs.ghcr_image_name }} | GHCR |" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.generate-standard.outputs.acr_image_name }}" != "" ]; then | |
| echo "| ${{ steps.generate-standard.outputs.acr_image_name }} | Aliyun ACR |" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 🚀 Pull Command" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "docker pull ${{ steps.generate-standard.outputs.ghcr_image_name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| - name: Generate image names (cn-patched) | |
| id: generate-cn | |
| if: ${{ needs.define-matrix.outputs.cn_patch_enabled == 'true' }} | |
| uses: ./.github/actions/generate-image-names | |
| with: | |
| dockerfile: ${{ matrix.os_packages }} | |
| tag: ${{ needs.define-matrix.outputs.tag_cn }} | |
| ghcr_credentials: ${{ format('{{"registry":"{0}","username":"{1}","password":"{2}"}}', 'ghcr.io', github.repository_owner, secrets.GITHUB_TOKEN) || '{}' }} | |
| aliyun_credentials: ${{ inputs.aliyun_enabled == 'true' && format('{{"registry":"{0}","username":"{1}","password":"{2}", "namespace":"{3}"}}', secrets.ALIYUN_REGISTRY, secrets.ALIYUN_USERNAME, secrets.ALIYUN_PASSWORD, secrets.ALIYUN_NAMESPACE) || '{}' }} | |
| - name: Build and push cn-patched images | |
| if: ${{ needs.define-matrix.outputs.cn_patch_enabled == 'true' }} | |
| uses: ./.github/actions/build-and-push | |
| with: | |
| dockerfile: ${{ matrix.os_packages }} | |
| build_args: CN_PATCH_ENABLED=true | |
| ghcr_image_name: ${{ steps.generate-cn.outputs.ghcr_image_name }} | |
| ghcr_credentials: ${{ format('{{"registry":"{0}","username":"{1}","password":"{2}"}}', 'ghcr.io', github.repository_owner, secrets.GITHUB_TOKEN) || '{}' }} | |
| acr_image_name: ${{ steps.generate-cn.outputs.acr_image_name }} | |
| aliyun_credentials: ${{ inputs.aliyun_enabled == 'true' && format('{{"registry":"{0}","username":"{1}","password":"{2}", "namespace":"{3}"}}', secrets.ALIYUN_REGISTRY, secrets.ALIYUN_USERNAME, secrets.ALIYUN_PASSWORD, secrets.ALIYUN_NAMESPACE) || '{}' }} | |
| - name: Output built image names (cn-patched) | |
| if: ${{ needs.define-matrix.outputs.cn_patch_enabled == 'true' }} | |
| run: | | |
| echo "## 🐳 Built OS Runtime Images (CN-Patched)" >> $GITHUB_STEP_SUMMARY | |
| echo "| Image Name | Registry |" >> $GITHUB_STEP_SUMMARY | |
| echo "|------------|----------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| ${{ steps.generate-cn.outputs.ghcr_image_name }} | GHCR |" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.generate-cn.outputs.acr_image_name }}" != "" ]; then | |
| echo "| ${{ steps.generate-cn.outputs.acr_image_name }} | Aliyun ACR |" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 🚀 Pull Command" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "docker pull ${{ steps.generate-cn.outputs.ghcr_image_name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |