feat: 更新默认shell脚本

This commit is contained in:
2025-04-08 10:49:21 +08:00
parent 02fe9112bd
commit 9208145f7d
11 changed files with 968 additions and 221 deletions
+83
View File
@@ -0,0 +1,83 @@
#!/bin/bash
# Ver: 1.0 by Endial Fang (endial@126.com)
#
# Docker 镜像构建脚本 (仅linux/amd64)
IMAGE_NAME="debian"
REGISTRY_URL="registry.colovu.com/docker-proxy/"
APT_SOURCE="aliyun"
# 获取镜像TAG
get_image_tag() {
if git rev-parse --git-dir > /dev/null 2>&1; then
if [ -z "$(git status --porcelain)" ]; then
CURRENT_SUBVERSION=$(git rev-parse --short HEAD)
else
CURRENT_SUBVERSION=$(date +%y%m%d-%H%M%S)
fi
IMAGE_TAG=$(git rev-parse --abbrev-ref HEAD | sed -e 's/master/latest/' -e 's/main/latest/')-${CURRENT_SUBVERSION}
else
CURRENT_SUBVERSION=$(date +%y%m%d-%H%M%S)
IMAGE_TAG="latest-${CURRENT_SUBVERSION}"
fi
echo "${IMAGE_TAG}"
}
# 构建amd64架构镜像
build() {
local TAG=$(get_image_tag)
echo "Building image ${IMAGE_NAME}:${TAG} (linux/amd64)"
podman build --platform linux/amd64 \
--progress plain --force-rm \
--build-arg REGISTRY_URL=${REGISTRY_URL} \
--build-arg APT_SOURCE=${APT_SOURCE} \
--build-arg LOCAL_URL=http://pkgs.colovu.com/dist \
-t ${IMAGE_NAME}:${TAG} \
-t ${IMAGE_NAME}:latest \
.
echo "Build complete"
}
# 清理工作空间
clean() {
echo "Cleaning workspace..."
podman images | grep "${IMAGE_NAME} " | awk '{print $3}' | xargs -L 1 podman rmi -f
podman ps -a | grep "Exited" | awk '{print $1}' | xargs -L 1 podman rm
podman images | grep '<none>' | awk '{print $3}' | xargs -L 1 podman rmi -f
}
# 推送镜像到colovu仓库
push_colovu() {
local TAG=$(get_image_tag)
echo "Pushing to registry.colovu.com"
podman tag ${IMAGE_NAME}:${TAG} registry.colovu.com/${IMAGE_NAME}:${TAG}
podman push registry.colovu.com/${IMAGE_NAME}:${TAG}
podman tag ${IMAGE_NAME}:latest registry.colovu.com/${IMAGE_NAME}:latest
podman push registry.colovu.com/${IMAGE_NAME}:latest
}
# 推送镜像到华为云仓库
push_huawei() {
local TAG=$(get_image_tag)
echo "Pushing to swr.cn-north-4.myhuaweicloud.com"
podman tag ${IMAGE_NAME}:${TAG} swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:${TAG}
podman push swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:${TAG}
podman tag ${IMAGE_NAME}:latest swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:latest
podman push swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:latest
}
main() {
case "$1" in
build) build ;;
clean) clean ;;
push-cv) push_colovu ;;
push-hw) push_huawei ;;
push) push_colovu; push_huawei ;;
*) echo "Usage: $0 {build|clean|push-cv|push-hw|push-all}"; exit 1 ;;
esac
}
main "$@"