Skip to content

Commit e32514f

Browse files
author
Qiu Jian
committed
fix: support build specific multi-arch buildx
1 parent c624797 commit e32514f

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

.github/workflows/build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fetch-depth: 8
1818
- uses: actions/setup-go@v2
1919
with:
20-
go-version: '1.18'
20+
go-version: '1.24'
2121
- name: test
2222
shell: bash
2323
run: |

scripts/docker_push.sh

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ get_current_arch() {
4141
echo $current_arch
4242
}
4343

44+
ALLARCH=("amd64" "arm64" "riscv64")
45+
4446
pushd $(cd "$(dirname "$0")"; pwd) > /dev/null
4547
readlink_mac $(basename "$0")
4648
cd "$(dirname "$REAL_PATH")"
@@ -128,7 +130,7 @@ get_image_name() {
128130
local arch=$2
129131
local is_all_arch=$3
130132
local img_name="$REGISTRY/$component:$TAG"
131-
if [[ "$is_all_arch" == "true" || "$arch" == arm64 || "$arch" == riscv64 ]]; then
133+
if [[ -n "$arch" && "$is_all_arch" == "true" ]]; then
132134
img_name="${img_name}-$arch"
133135
fi
134136
echo $img_name
@@ -179,19 +181,21 @@ general_build(){
179181

180182
make_manifest_image() {
181183
local component=$1
184+
local arch=$2
182185
local img_name=$(get_image_name $component "" "false")
183186
if [[ "$DRY_RUN" == "true" ]]; then
184187
echo "[$(readlink -f ${BASH_SOURCE}):${LINENO} ${FUNCNAME[0]}] return for DRY_RUN"
185188
return
186189
fi
187190

188-
docker buildx imagetools create -t $img_name \
189-
$img_name-amd64 \
190-
$img_name-riscv64 \
191-
$img_name-arm64
192-
docker manifest inspect ${img_name} | grep -wq amd64
193-
docker manifest inspect ${img_name} | grep -wq arm64
194-
docker manifest inspect ${img_name} | grep -wq riscv64
191+
CMD="docker buildx imagetools create -t ${img_name} "
192+
for ac in "${ALLARCH[@]}"; do
193+
if [[ "${arch}" == "all" || "${arch}" == *"$ac"* ]]; then
194+
CMD="${CMD} ${img_name}-${ac}"
195+
fi
196+
done
197+
echo "$CMD"
198+
$CMD
195199
}
196200

197201
ALL_COMPONENTS=$(ls cmd | grep -v '.*cli$' | xargs)
@@ -211,22 +215,37 @@ fi
211215
cd $SRC_DIR
212216
mkdir -p $SRC_DIR/_output
213217

218+
show_update_cmd() {
219+
local component=$1
220+
local spec=$1
221+
local name=$1
222+
local tag=$TAG
223+
224+
echo "kubectl patch oc -n onecloud default --type='json' -p='[{op: replace, path: /spec/${spec}/imageName, value: ${name}},{"op": "replace", "path": "/spec/${spec}/repository", "value": "${REGISTRY}"},{"op": "add", "path": "/spec/${spec}/tag", "value": "${tag}"}]'"
225+
}
226+
214227
for component in $COMPONENTS; do
215228
if [[ $component == *cli ]]; then
216229
echo "Please build image for climc"
217230
continue
218231
fi
219232
echo "Start to build component: $component"
220233

221-
case "$ARCH" in
222-
all)
223-
for arch in "arm64" "amd64" "riscv64"; do
224-
general_build $component $arch "true"
225-
done
226-
make_manifest_image $component
227-
;;
228-
*)
234+
multiarch=""
235+
for ac in "${ALLARCH[@]}"; do
236+
if [[ "$ARCH" == "$ac" ]]; then
237+
# single arch
229238
general_build $component $ARCH "false"
230-
;;
231-
esac
239+
elif [[ "$ARCH" == "all" || "$ARCH" == *"$ac"* ]]; then
240+
multiarch="true"
241+
general_build $component $ac "true"
242+
fi
243+
done
244+
if [[ "$multiarch" == "true" ]]; then
245+
make_manifest_image $component $ARCH
246+
fi
247+
done
248+
249+
for component in $COMPONENTS; do
250+
show_update_cmd $component
232251
done

0 commit comments

Comments
 (0)