Build OS Runtimes #3
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 | |
| default: 'false' | |
| auto_trigger_language_runtimes: | |
| description: 'Auto trigger language runtimes' | |
| required: false | |
| 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: 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) || '{}' }} |