Skip to content

Commit

Permalink
feat: #15 upload to coding.net artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Jun 1, 2021
1 parent fb7f64f commit b456239
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 1,024 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
/dl/
/docs/index.md
/site/
/qiniu/
/tmp/
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

361 changes: 21 additions & 340 deletions LICENSE

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# gmirror
# CODING 下载中心

gmirror 是一个下载上传工具,指定一些下载链接,通过travis-ci持续集成进行下载,然后上传到指定的地方(比如七牛)。
为中国开发者提供持续集成中常用的命令行软件下载,解决跨境下载缓慢的问题。

## 提交需要的软件

修改 `index.md`,加入需要的软件,发起合并请求,待管理员合并,会触发自动下载,并发布到公开制品库:

https://coding-public.coding.net/public-artifacts/public/downloads/packages

## 技术细节

提交代码会触发「CODING 持续集成(支持海外构建节点)」,自动执行 `coding-generic-sync.sh`

- 解析 `index.md` 获取需要下载的软件列表
- 判断是否已存在于「CODING 制品库」,如不存在,则下载、校验、上传
7 changes: 0 additions & 7 deletions before_install.sh

This file was deleted.

7 changes: 0 additions & 7 deletions before_upload.sh

This file was deleted.

63 changes: 63 additions & 0 deletions coding-generic-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
set -e

top_dir=$(cd `dirname $0`; pwd)
dl_dir=$top_dir/dl
mkdir -p "$dl_dir"

index_file="$top_dir/index.md"
thead_line_num=$(grep -n "\-|\-" "$index_file" | awk -F: '{print $1}')
offset=$(($thead_line_num+1))
tail -n +$offset "$index_file" | while read line; do
i=0
http_code=200
sha256=""
while IFS='|' read -ra tmp; do
for part in "${tmp[@]}"; do
part="$(sed -e 's/[[:space:]]*$//' <<<${part})"
if [ $i -eq 0 ]; then
package=$part
printf "\n%s\n" "$package"
file_prefix=$(echo "${part%%.*}")
file_suffix=""
if [[ $part == *"."* ]]; then
file_suffix="."`echo ${part#*.}`
fi
elif [ $i -eq 1 ]; then
version=$part
filename=$file_prefix-$version$file_suffix
elif [ $i -eq 2 ]; then
uri=$part
elif [ $i -eq 3 ]; then
sha256=$part
echo "$sha256 $dl_dir/$filename" > "$dl_dir/$filename.sha256sum"
fi
i=$(($i+1))
done
done <<< "$line"

if [ "$CODING_GENERIC_REGISTRY" = "" ]; then
echo "error: env CODING_GENERIC_REGISTRY not set"
exit 1
fi
mirror_full_url="${CODING_GENERIC_REGISTRY}$package?version=$version"
echo "check $mirror_full_url"
header=$(curl -sI "$mirror_full_url")
http_code=$(echo "$header" | head -n 1 | awk '{print $2}')
if [ "$http_code" -eq 200 ]; then
echo "skip: file exists on mirror"
fi
if [ "$http_code" -ne 200 ]; then
if [ -f "$dl_dir/$filename" ]; then
if sha256sum -c "$dl_dir/$filename.sha256sum"; then
echo "skip: file exists on local"
continue
fi
fi
wget -O "$dl_dir/$filename" "$uri"
sha256sum -c "$dl_dir/$filename.sha256sum"
# coding-generic 自带校验功能,上传成功即可,无需再下载校验。
coding-generic --username="$CODING_GENERIC_REGISTRY:" --path=./test.txt --registry="$CODING_GENERIC_REGISTRY"
fi
done
echo 'the end'
30 changes: 0 additions & 30 deletions dl/origin.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

35 changes: 0 additions & 35 deletions docs/about.md

This file was deleted.

Binary file removed docs/favicon.ico
Binary file not shown.
70 changes: 0 additions & 70 deletions docs/index.tpl.md

This file was deleted.

Binary file removed docs/qiniu-transparent.png
Binary file not shown.
2 changes: 0 additions & 2 deletions docs/robots.txt

This file was deleted.

112 changes: 0 additions & 112 deletions download.sh

This file was deleted.

5 changes: 0 additions & 5 deletions gmirror.conf

This file was deleted.

5 changes: 5 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package | version | uri | sha256
--------|---------|-----|---------
go-linux-amd64.tar.gz | 1.16.4 | https://golang.google.cn/dl/go1.16.4.linux-amd64.tar.gz | ae4f6b6e2a1677d31817984655a762074b5356da50fb58722b99104870d43503
composer.phar | 2.0.14 | https://getcomposer.org/download/2.0.14/composer.phar | 29454b41558968ca634bf5e2d4d07ff2275d91b637a76d7a05e6747d36dd3473
kubectl-linux-amd64 | v1.18.4 | http://storage-googleapis-com.hnftp.china-speed.org.cn/kubernetes-release/release/v1.18.4/bin/linux/amd64/kubectl | 58785190e2b4fc6891e01108e41f9ba5db26e04cebb7c1ac639919a931ce9233
Loading

0 comments on commit b456239

Please sign in to comment.