1010# Runtime default config
1111# =======================================
1212VAR_FREIGHT_UTILS_VERSION=${VAR_FREIGHT_UTILS_VERSION:- v0.3.13}
13- VAR_TENCENT_COS_UTILS_VERSION=${VAR_TENCENT_COS_UTILS_VERSION:- v0.11.0-beta}
1413VAR_DEB_WORKBENCH_DIR=${VAR_DEB_WORKBENCH_DIR:-/ tmp/ output}
1514VAR_GPG_PRIV_KET=${VAR_GPG_PRIV_KET:-/ tmp/ deb-gpg-publish.private}
1615VAR_GPG_PASSPHRASE=${VAR_GPG_PASSPHRASE:-/ tmp/ deb-gpg-publish.passphrase}
1716
18- COS_CMD=coscli
17+ COS_REGION=${COS_REGION:- " ap-guangzhou" }
18+ COS_GLOBAL_REGION=${COS_GLOBAL_REGION:- " accelerate" }
19+ COS_PART_SIZE=${COS_PART_SIZE:- " 10" }
20+ VAR_COS_REGION_DNS=" cos.${COS_REGION} .myqcloud.com"
21+ VAR_COS_GLOBAL_REGION_DNS=" cos.${COS_GLOBAL_REGION} .myqcloud.com"
22+
1923TAG_DATE=$( date +%Y%m%d)
2024ARCH=${ARCH:- `(uname -m | tr ' [:upper:]' ' [:lower:]' )`}
2125arch_path=" "
@@ -41,30 +45,11 @@ _EOC_
4145# =======================================
4246# COS extension
4347# =======================================
44- func_cos_utils_install () {
45- if [[ $ARCH == " arm64" ]] || [[ $ARCH == " aarch64" ]]; then
46- wget https://github.com/tencentyun/coscli/archive/refs/tags/${VAR_TENCENT_COS_UTILS_VERSION} .tar.gz
47- tar -zxvf ${VAR_TENCENT_COS_UTILS_VERSION} .tar.gz
48- cd coscli-* && go build
49- mv coscli ../
50- else
51- sudo curl -o /usr/bin/coscli -L " https://github.com/tencentyun/coscli/releases/download/${VAR_TENCENT_COS_UTILS_VERSION} /coscli-linux"
52- sudo chmod 755 /usr/bin/coscli
53- fi
54- }
55-
5648func_cos_utils_credential_init () {
57- # ${1} - COS endpoint
58- # ${2} - COS SECRET_ID
59- # ${3} - COS SECRET_KEY
60- cat > " ${HOME} /.cos.yaml" << _EOC_
61- cos:
62- base:
63- secretid: ${2}
64- secretkey: ${3}
65- sessiontoken: ""
66- protocol: https
67- _EOC_
49+ # ${1} - COS SECRET_ID
50+ # ${2} - COS SECRET_KEY
51+ # ${3} - COS bucket name
52+ coscmd config -a " ${1} " -s " ${2} " -b " ${3} " -r ${COS_REGION} -p ${COS_PART_SIZE}
6853}
6954
7055
@@ -91,21 +76,20 @@ func_dists_backup() {
9176 # ${1} - bucket name
9277 # ${2} - COS path
9378 # ${3} - backup tag
94- $COS_CMD -e " ${VAR_COS_ENDPOINT} " cp -r --part-size 1000 " cos:// ${1} /packages/${arch_path}${2} /dists" " cos:// ${1} / packages/${arch_path} backup/${2} _dists_${3} " || true
79+ coscmd copy -r " ${1} . ${VAR_COS_REGION_DNS} /packages/${arch_path}${2} /dists" " / packages/${arch_path} backup/${2} _dists_${3} "
9580}
9681
9782func_pool_clone () {
9883 # ${1} - bucket name
9984 # ${2} - COS path
10085 # ${3} - local pool path
101-
10286 mkdir -p ${3}
10387 # --part-size indicates the file chunk size.
10488 # when the file is larger than --part-size, coscli will chunk the file by --part-size.
10589 # when uploading/downloading the file in chunks, it will enable breakpoint transfer by default,
10690 # which will generate cosresumabletask file and interfere with the file integrity.
10791 # ref: https://cloud.tencent.com/document/product/436/63669
108- $COS_CMD -e " ${VAR_COS_ENDPOINT } " cp -r --part-size 1000 " cos:// ${1} /packages/${arch_path}${2} /pool" " ${3} "
92+ coscmd -b " ${1 } " -r " ${COS_GLOBAL_REGION} " download -r " /packages/${arch_path}${2} /pool" " ${3} "
10993}
11094
11195func_dists_rebuild () {
@@ -139,8 +123,8 @@ func_dists_rebuild() {
139123}
140124
141125func_dists_upload_ci_repo () {
142- $COS_CMD -e " ${VAR_COS_ENDPOINT } " rm -r -f " cos:// ${2} /packages/${arch_path}${3} " || true
143- $COS_CMD -e " ${VAR_COS_ENDPOINT } " cp -r --part-size 512 " ${1} " " cos:// ${2} / packages/${arch_path}${3} /dists/ "
126+ coscmd -b " ${2 } " delete -r -f " /packages/${arch_path}${3} " || true
127+ coscmd -b " ${2 } " -r " ${COS_GLOBAL_REGION} " upload -r " ${1} " " / packages/${arch_path}${3} /dists"
144128}
145129
146130func_deb_upload () {
@@ -152,33 +136,34 @@ func_deb_upload() {
152136 # We will only upload apisix and apisix-base,
153137 # so the directory is fixed: pool/main/a.
154138 # Regardless of other packages.
155-
156- export COS_CMD=$COS_CMD
157139 export arch_path=$arch_path
158140 export BUCKET=$2
159141 export OS=$3
160142 export CODENAME=$4
161143 find " ${1} " -type f -name " apisix_*.deb" \
162144 -exec echo " upload : {}" \; \
163145 -exec sh -c ' file=$(basename {}); \
164- $COS_CMD -e "${VAR_COS_ENDPOINT }" cp {} --part-size 512 "cos://${BUCKET} /packages/${arch_path}${OS}/pool/${CODENAME}/main/a/apisix/${file}"' \;
146+ coscmd -b "${BUCKET }" -r "${COS_GLOBAL_REGION}" upload {} " /packages/${arch_path}${OS}/pool/${CODENAME}/main/a/apisix/${file}"' \;
165147
166148 find " ${1} " -type f -name " apisix-base*.deb" \
167149 -exec echo " upload : {}" \; \
168150 -exec sh -c ' file=$(basename {}); \
169- $COS_CMD -e "${VAR_COS_ENDPOINT }" cp {} --part-size 512 "cos://${BUCKET} /packages/${arch_path}${OS}/pool/${CODENAME}/main/a/apisix-base/${file}"' \;
151+ coscmd -b "${BUCKET }" -r "${COS_GLOBAL_REGION}" upload {} " /packages/${arch_path}${OS}/pool/${CODENAME}/main/a/apisix-base/${file}"' \;
170152}
171153
172154func_repo_publish () {
173- $COS_CMD -e " ${VAR_COS_ENDPOINT} " rm -r -f " cos://${2} /packages/${arch_path}${3} /dists" || true
174- $COS_CMD -e " ${VAR_COS_ENDPOINT} " cp -r --part-size 512 " cos://${1} /packages/${arch_path}${3} /dists" " cos://${2} /packages/${arch_path}${3} /dists"
155+ # ${1} - CI bucket
156+ # ${2} - repo publish bucket
157+ # ${3} - COS path
158+ coscmd delete -r -f " /packages/${arch_path}${3} /dists" || true
159+ coscmd -b " ${2} " copy -r " ${1} .${VAR_COS_REGION_DNS} /packages/${arch_path}${3} /dists" " /packages/${arch_path}${3} /dists"
175160}
176161
177162func_repo_backup_remove () {
178163 # ${1} - bucket name
179164 # ${2} - COS path
180165 # ${3} - backup tag
181- $COS_CMD -e " ${VAR_COS_ENDPOINT } " rm -r -f " cos:// ${1} /packages/${arch_path} backup/${2} _dists_${3} " || true
166+ coscmd -b " ${1 } " delete -r -f " /packages/${arch_path} backup/${2} _dists_${3} " || true
182167}
183168
184169# =======================================
@@ -188,8 +173,7 @@ case_opt=$1
188173
189174case ${case_opt} in
190175init_cos_utils)
191- func_cos_utils_install
192- func_cos_utils_credential_init " ${VAR_COS_ENDPOINT} " " ${TENCENT_COS_SECRETID} " " ${TENCENT_COS_SECRETKEY} "
176+ func_cos_utils_credential_init " ${TENCENT_COS_SECRETID} " " ${TENCENT_COS_SECRETKEY} " " ${VAR_COS_BUCKET_REPO} "
193177 ;;
194178init_freight_utils)
195179 func_freight_utils_install
@@ -210,8 +194,10 @@ repo_clone)
210194repo_rebuild)
211195 func_dists_rebuild " /tmp/old_pool" " /tmp/freight" ${VAR_DEB_WORKBENCH_DIR} ${VAR_CODENAME}
212196 ;;
213- repo_upload )
197+ repo_ci_upload )
214198 func_dists_upload_ci_repo " /tmp/freight/cache/dists" " ${VAR_COS_BUCKET_CI} " " ${VAR_OS} "
199+ ;;
200+ repo_upload)
215201 func_deb_upload " ${VAR_DEB_WORKBENCH_DIR} " " ${VAR_COS_BUCKET_REPO} " " ${VAR_OS} " " ${VAR_CODENAME} "
216202 ;;
217203repo_publish)
0 commit comments