-
Notifications
You must be signed in to change notification settings - Fork 21
86 lines (76 loc) · 3.4 KB
/
extension-images-syncer.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
name: Extensions Image Syncer
on:
push:
branches:
- 'main'
jobs:
pull_request_push:
runs-on: ubuntu-latest
if: github.repository == 'kubesphere-extensions/ks-extensions'
steps:
- name: Get Architecture
id: get-architectures
run: |
ARCH=$(uname -m)
if [ "$ARCH" == "x86_64" ]; then
ARCH="amd64"
elif [ "$ARCH" == "aarch64" ]; then
ARCH="arm64"
fi
echo "arch=$ARCH" >> $GITHUB_OUTPUT
- name: Install KSBuilder
run: |
LATEST_RELEASE=$(curl -sH "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/kubesphere/ksbuilder/releases/latest" | jq -r '.tag_name')
curl -L -O https://github.com/kubesphere/ksbuilder/releases/download/$LATEST_RELEASE/ksbuilder_${LATEST_RELEASE#v}_linux_${{ steps.get-architectures.outputs.arch }}.tar.gz
sudo tar -zxf ksbuilder_${LATEST_RELEASE#v}_linux_${{ steps.get-architectures.outputs.arch }}.tar.gz -C /usr/local/bin/ ksbuilder
rm -rf ksbuilder_${LATEST_RELEASE#v}_linux_${{ steps.get-architectures.outputs.arch }}.tar.gz
- name: Install ORAS
run: |
VERSION="1.2.0"
curl -LO "https://github.com/oras-project/oras/releases/download/v${VERSION}/oras_${VERSION}_linux_${{ steps.get-architectures.outputs.arch }}.tar.gz"
mkdir -p oras-install/
tar -zxf oras_${VERSION}_*.tar.gz -C oras-install/
sudo mv oras-install/oras /usr/local/bin/
rm -rf oras_${VERSION}_*.tar.gz oras-install/
- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_${{ steps.get-architectures.outputs.arch }} -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Login to HUAWEICLOUD
uses: docker/login-action@v3
with:
registry: swr.cn-southwest-2.myhuaweicloud.com
username: ${{ secrets.HUAWEICLOUD_USERNAME }}
password: ${{ secrets.HUAWEICLOUD_PASSWORD }}
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- name: Extension Check
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
changed_files=(${ALL_CHANGED_FILES})
for path in ${changed_files[@]}; do
chart=$(dirname "$path")
if [[ $chart != '.' ]] && [ -f "$chart/extension.yaml" ] && [ -f "$chart/values.yaml" ]; then
ksbuilder package $chart
rm $chart-*.tgz
for image in $(yq eval '.images[]' $chart/extension.yaml); do
dstImage=''
if [[ ${image%%/*} =~ '.' ]]; then
dstImage=swr.cn-southwest-2.myhuaweicloud.com/ks/${image#*/}
elif [[ $image != */* ]]; then
dstImage="swr.cn-southwest-2.myhuaweicloud.com/ks/library/"$image
image="docker.io/library/"$image
else
dstImage="swr.cn-southwest-2.myhuaweicloud.com/ks/"$image
image="docker.io/"$image
fi
oras cp $image $dstImage --platform linux/amd64
done
fi
done