forked from alibaba/higress
-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (83 loc) · 3.39 KB
/
build-and-push-wasm-go-plugin.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Build Wasm Go Plugins and Push to Image Registry
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
plugin_name:
description: "Enter the plugin name"
required: true
plugin_version:
description: "Enter the plugin version"
required: true
jobs:
build-and-push-wasm-go-plugin:
runs-on: ubuntu-latest
environment:
name: image-registry-wasm-go-plugin
env:
IMAGE_REGISTRY_SERVICE: ${{ vars.IMAGE_REGISTRY_SERVICE || 'higress-registry.cn-hangzhou.cr.aliyuncs.com' }}
IMAGE_REPOSITORY: ${{ vars.IMAGE_REPOSITORY || 'plugins' }}
steps:
- name: "Checkout ${{ github.ref }}"
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Setup ORAS
uses: oras-project/setup-oras@v1
with:
version: 1.2.0
- name: Login to Docker Registry
run: oras login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ env.IMAGE_REGISTRY_SERVICE }}
- name: Build Plugin Image and Push
working-directory: plugins/wasm-go
run: |
set +e
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
PLUGIN_VERSION=${{ github.event.inputs.plugin_version }}
PLUGIN_DIRS=(${{ github.event.inputs.plugin_name }})
else
PLUGIN_VERSION=${{ github.ref_name }}
PLUGIN_DIRS=$(basename -a ./extensions/*)
fi
for PLUGIN in ${PLUGIN_DIRS[@]}; do
echo "Build and push wasm go plugin: ${PLUGIN}"
MAX_RETRIES=3
RETRIES=0
while [[ "${RETRIES}" -lt "${MAX_RETRIES}" ]]; do
IMAGE="${{ env.IMAGE_REGISTRY_SERVICE }}/${{ env.IMAGE_REPOSITORY }}/wasm-go-${PLUGIN}:${PLUGIN_VERSION}"
PLUGIN_DIR="./extensions/${PLUGIN}"
GOPROXY="https://proxy.golang.org,direct" PLUGIN_NAME="${PLUGIN}" make build
if [[ $? -eq 0 ]]; then
tar czvf "${PLUGIN_DIR}/plugin.tar.gz" "${PLUGIN_DIR}/plugin.wasm"
PUSH_FILES="${PLUGIN_DIR}/plugin.tar.gz:application/vnd.oci.image.layer.v1.tar+gzip"
declare -A FILES=(
["spec.yaml"]="application/vnd.module.wasm.spec.v1+yaml"
["README.md"]="application/vnd.module.wasm.doc.v1+markdown"
["README_EN.md"]="application/vnd.module.wasm.doc.v1.en+markdown"
)
for FILE in "${!FILES[@]}"; do
FILE_PATH="${PLUGIN_DIR}/${FILE}"
if [[ -f "${FILE_PATH}" ]]; then
PUSH_FILES="${PUSH_FILES} ${FILE_PATH}:${FILES[$FILE]}"
fi
done
echo "XXXXXXXXXXXXXXX"
echo "${PUSH_FILES}"
echo "YYYYYYYYYYYYYYYY"
echo "${FILES}"
echo "ZZZZZZZZZZZZZZZZZZZ"
echo "oras push ${IMAGE} ${PUSH_FILES}"
oras push "${IMAGE}" "${PUSH_FILES}"
break
else
(( RETRIES++ ))
echo "Build failed. Retrying ${RETRIES}/${MAX_RETRIES}..."
fi
done
if [[ "${RETRIES}" -eq "${MAX_RETRIES}" ]]; then
echo "Build failed after ${MAX_RETRIES} retries."
exit 1
fi
done