Skip to content

add calico v3.29.2

add calico v3.29.2 #43

Workflow file for this run

name: Docker
on:
workflow_dispatch:
push:
branches: [ main ]
env:
ALIYUN_REGISTRY: "${{ secrets.ALIYUN_REGISTRY }}"
ALIYUN_NAME_SPACE: "${{ secrets.ALIYUN_NAME_SPACE }}"
ALIYUN_REGISTRY_USER: "${{ secrets.ALIYUN_REGISTRY_USER }}"
ALIYUN_REGISTRY_PASSWORD: "${{ secrets.ALIYUN_REGISTRY_PASSWORD }}"
jobs:
build:
name: Pull
runs-on: ubuntu-latest
steps:
- name: Before freeing up disk space
run: |
echo "Before freeing up disk space"
echo "=============================================================================="
df -hT
echo "=============================================================================="
# 增加可用磁盘空间
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 2048
swap-size-mb: 128
remove-dotnet: 'true'
remove-haskell: 'true'
# 如果空间还是不够用,可以把以下开启,清理出更多空间
# remove-android: 'true'
# remove-codeql: 'true'
build-mount-path: '/var/lib/docker/'
- name: Restart docker
run: sudo service docker restart
- name: Free up disk space complete
run: |
echo "Free up disk space complete"
echo "=============================================================================="
df -hT
echo "=============================================================================="
- name: Checkout Code
uses: actions/checkout@v4
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image Aliyun
run: |
docker login -u $ALIYUN_REGISTRY_USER -p $ALIYUN_REGISTRY_PASSWORD $ALIYUN_REGISTRY
max_count=72
# 函数:裁剪字符串,直到长度小于或等于最大长度
trim_string() {
local str="$1"
# 计算字符串长度
local len=${#str}
# 只要字符串长度大于最大长度,就继续裁剪
while [ "$len" -gt $max_count ]; do
# 去除第一个'/'及其后的所有字符
str=${str#*/}
# 更新字符串长度
len=${#str}
done
# 返回裁剪后的字符串
echo "$str"
}
while IFS= read -r line || [ -n "$line" ]; do
# 忽略空行与注释
[[ -z "$line" ]] && continue
if echo "$line" | grep -q '^\s*#'; then
continue
fi
echo "docker pull $line"
docker pull "$line"
platform=$(echo "$line" | awk -F'--platform[ =]' '{if (NF>1) print $2}' | awk '{print $1}')
echo "platform is $platform"
# 如果存在架构信息 将架构信息拼到镜像名称前面
if [ -z "$platform" ]; then
platform_prefix=""
else
platform_prefix="${platform//\//_}_"
fi
echo "platform_prefix is $platform_prefix"
# 获取镜像的完整名称,例如kasmweb/nginx:1.25.3(命名空间/镜像名:版本号)
image=$(trim_string "$line")
# 获取 镜像名:版本号 例如1.25.3
image_tag=$(echo "$image" | awk -F":" '{print $2}')
# 将@sha256:等字符删除
image_name_tag="${image_tag%%@*}"
repo=$(echo "$image" | cut -d':' -f1)
# 替换/为_,这里使用sed命令
replaced_repo=$(echo "$repo" | sed 's/\//_/g')
new_image="$ALIYUN_REGISTRY/$ALIYUN_NAME_SPACE/$platform_prefix$replaced_repo:$image_name_tag"
echo "docker tag $line $new_image"
docker tag "$line" "$new_image"
echo "docker push $new_image"
docker push "$new_image"
echo "开始清理磁盘空间"
echo "=============================================================================="
df -hT
echo "=============================================================================="
docker rmi "$line"
docker rmi "$new_image"
echo "磁盘空间清理完毕"
echo "=============================================================================="
df -hT
echo "=============================================================================="
done < images.txt