Skip to content

Build Framework Runtimes #1

Build Framework Runtimes

Build Framework Runtimes #1

name: Build Framework Runtimes
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag for the Docker image'
required: true
default: 'latest'
# build_base_image_template
# ghcr.io/${{ github.repository_owner }}/devbox/${language_package}:${build_base_image_tag}
build_base_image_tag:
description: 'Build base image tag, if not provided, will use the tag from the Dockerfile'
required: false
default: 'latest'
build_base_image_tag_with_cn_patch:
description: 'Build base image tag with CN patch, if not provided, will use the tag from the Dockerfile'
required: false
default: 'latest-cn'
cn_patch_enabled:
description: 'Enable CN patch modifications'
required: false
default: 'false'
aliyun_enabled:
description: 'Enable Aliyun ACR builds'
required: false
default: 'false'
jobs:
# Define framework 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 }}
framework_packages: ${{ steps.get_framework_packages.outputs.framework_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 framework packages
id: get_framework_packages
run: |
# Get all framework packages with their base images
target_dockerfiles=$(find runtimes/frameworks -name "Dockerfile")
# Create JSON array with dockerfile path and base image
framework_packages="[]"
while IFS= read -r dockerfile; do
if [ -n "$dockerfile" ]; then
# Extract base image from Dockerfile
original_base_image=$(grep "ARG BASE_IMAGE=" "$dockerfile" | cut -d'=' -f2)
# get language package name from original_base_image
# ghcr.io/labring-actions/devbox/go-1.22.5:latest -> go-1.22.5
language_package=$(echo "$original_base_image" | sed "s/.*devbox\/\(.*\):.*/\1/")
# get base image name for the framework
# ghcr.io/${{ github.repository_owner }}/devbox/${language_package}:${build_base_image_tag}
base_image="ghcr.io/${{ github.repository_owner }}/devbox/${language_package}:${{ inputs.build_base_image_tag }}"
base_image_with_cn_patch="ghcr.io/${{ github.repository_owner }}/devbox/${language_package}:${{ inputs.build_base_image_tag_with_cn_patch }}"
# Create JSON object for this framework
framework_obj=$(jq -n \
--arg dockerfile "$dockerfile" \
--arg base_image "$base_image" \
--arg base_image_with_cn_patch "$base_image_with_cn_patch" \
'{dockerfile: $dockerfile, base_image: $base_image, base_image_with_cn_patch: $base_image_with_cn_patch}')
# Add to array
framework_packages=$(echo "$framework_packages" | jq --argjson obj "$framework_obj" '. + [$obj]')
fi
done <<< "$target_dockerfiles"
echo "framework_packages<<EOF" >> $GITHUB_OUTPUT
echo "$framework_packages" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
package_count=$(echo "$framework_packages" | jq 'length // 0')
echo "Found $package_count framework packages to build"
# Build framework runtimes
build-framework-runtimes:
runs-on: ubuntu-latest
needs: define-matrix
strategy:
fail-fast: false
matrix:
framework_packages: ${{ fromJson(needs.define-matrix.outputs.framework_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.framework_packages.dockerfile }}
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 (standard)
uses: ./.github/actions/build-and-push
with:
dockerfile: ${{ matrix.framework_packages.dockerfile }}
build_base_image: ${{ matrix.framework_packages.base_image }}
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.framework_packages.dockerfile }}
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 (cn-patched)
if: ${{ needs.define-matrix.outputs.cn_patch_enabled == 'true' }}
uses: ./.github/actions/build-and-push
with:
dockerfile: ${{ matrix.framework_packages.dockerfile }}
build_base_image: ${{ matrix.framework_packages.base_image_with_cn_patch }}
build_args: CN_PATCH_ENABLED=true
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) || '{}' }}
ghcr_image_name: ${{ steps.generate-cn.outputs.ghcr_image_name }}
acr_image_name: ${{ steps.generate-cn.outputs.acr_image_name }}