Skip to content

Commit

Permalink
add task
Browse files Browse the repository at this point in the history
  • Loading branch information
shaowenchen committed Sep 13, 2024
1 parent 1cd3d2f commit 9b9d0b5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pipelines/cluster-retag-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: crd.chenshaowen.com/v1
kind: Pipeline
metadata:
name: cluster-retag-image
namespace: ops-system
spec:
desc: 转存、retag 容器镜像
variables:
nodeName:
required: true
typeRef:
value: "cluster"
required: true
nameRef:
required: true
source:
required: true
desc: 源镜像名字
destination:
required: true
desc: 目标镜像名字
tasks:
- name: retag image
ref: retag-image

41 changes: 41 additions & 0 deletions tasks/retag-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: crd.chenshaowen.com/v1
kind: Task
metadata:
name: retag-image
namespace: ops-system
spec:
desc: retag image
typeRef: cluster
variables:
source:
display: source image
required: true
destination:
display: destination image
required: true
steps:
- name: retag image
content: |
if docker version &> /dev/null; then
docker pull "${source}"
docker tag "${source}" "${destination}"
docker push "${destination}"
docker rmi "${source}"
docker rmi "${destination}"
elif nerdctl version &> /dev/null; then
nerdctl pull "${source}"
nerdctl tag "${source}" "${destination}"
nerdctl push "${destination}"
nerdctl rmi "${source}"
nerdctl rmi "${destination}"
else
echo "Neither Docker nor nerdctl is available."
exit 1
fi
if [ $? -ne 0 ]; then
echo "Failed to retag ${source} to ${destination}"
exit 1
else
echo "Successfully retag ${source} to ${destination}"
fi

0 comments on commit 9b9d0b5

Please sign in to comment.