Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,21 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
- name: Login to Aliyun ACR
uses: docker/login-action@v3
with:
registry: ${{ secrets.ALIYUN_REGISTRY }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PASSWORD }}
- name: Build and push images
run: |
echo "build_target=${{ matrix.build_target }}"
echo "tag=${{ needs.define-matrix.outputs.tag }}"
echo "tag_cn=${{ needs.define-matrix.outputs.tag_cn }}"
image_name=$(bash script/get_image_name.sh ${{ github.repository_owner }} "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag }}")
image_name_cn=$(bash script/get_image_name.sh ${{ github.repository_owner }} "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag_cn }}")
echo "image_name=$image_name" >> $GITHUB_OUTPUT
echo "image_name_cn=$image_name_cn" >> $GITHUB_OUTPUT
echo "building image $image_name"
is_cn="0" bash script/build_and_push_images.sh "${{ matrix.build_target }}" "$image_name" $is_cn
echo "building image $image_name_cn"
is_cn="1" bash script/build_and_push_images.sh "${{ matrix.build_target }}" "$image_name_cn" $is_cn
ghcr_image_name=$(bash script/get_image_name.sh "ghcr.io" "${{ github.repository_owner }}" "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag }}")
acr_image_name=$(bash script/get_image_name.sh "${{ secrets.ALIYUN_REGISTRY }}" "${{ github.repository_owner }}" "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag_cn }}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 github.repository_owner 可能和 acr 的不一致,也一样修改为 secret 中读取吧

echo "ghcr_image_name=$ghcr_image_name" >> $GITHUB_OUTPUT
echo "acr_image_name=$acr_image_name" >> $GITHUB_OUTPUT
echo "Building and pushing both images..."
bash script/build_and_push_images.sh "${{ matrix.build_target }}" "$ghcr_image_name" "$acr_image_name"
# TODO: generate runtime yaml and json
34 changes: 26 additions & 8 deletions script/build_and_push_images.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
#!/bin/bash

build_target=$1
image_name=$2
is_cn=$3
ghcr_image_name=$2
acr_image_name=$3

function build_and_push_image() {
function build_and_push_images() {
# 构建并推送ghcr镜像
echo "Building and pushing ghcr image: $ghcr_image_name"
docker buildx build --push \
--file "$build_target" \
--platform linux/amd64 \
--tag "$image_name" \
--tag "$ghcr_image_name" \
.

# 执行CN补丁
execute_cn_patch

# 构建并推送阿里云ACR镜像
echo "Building and pushing ACR image: $acr_image_name"
docker buildx build --push \
--file "$build_target" \
--platform linux/amd64 \
--tag "$acr_image_name" \
.
}

function execute_cn_patch() {
script_dir=$(dirname "$(dirname "$build_target")")
bash "$script_dir/update_cn_dockerfile.sh" "$build_target"
if [ -f "$script_dir/update_cn_dockerfile.sh" ]; then
echo "Applying CN patch..."
bash "$script_dir/update_cn_dockerfile.sh" "$build_target"
fi
}

if [ "$is_cn" == "1" ]; then
execute_cn_patch
# 检查参数数量
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <build_target> <ghcr_image_name> <acr_image_name>"
exit 1
fi

build_and_push_image
build_and_push_images
13 changes: 7 additions & 6 deletions script/get_image_name.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash

if [ "$#" -ne 3 ]; then
echo "Usage: $0 <username> <build_target> <tag>"
if [ "$#" -ne 4 ]; then
echo "Usage: $0 <registry> <username> <build_target> <tag>"
exit 1
fi

USERNAME=$1
BUILD_TARGET=$2
TAG=$3
REGISTRY=$1
USERNAME=$2
BUILD_TARGET=$3
TAG=$4

IFS='/' read -ra ADDR <<< "$BUILD_TARGET"
IMAGE_NAME="${ADDR[1]}-${ADDR[2]}"

echo "ghcr.io/$USERNAME/devbox/$IMAGE_NAME:$TAG"
echo "$REGISTRY/$USERNAME/devbox/$IMAGE_NAME:$TAG"