-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cd3d2f
commit b5b97ef
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_image}" | ||
docker tag "${source_image}" "${destination_image}" | ||
docker push "${destination_image}" | ||
docker rmi "${source_image}" | ||
docker rmi "${destination_image}" | ||
elif nerdctl version &> /dev/null; then | ||
nerdctl pull "${source_image}" | ||
nerdctl tag "${source_image}" "${destination_image}" | ||
nerdctl push "${destination_image}" | ||
nerdctl rmi "${source_image}" | ||
nerdctl rmi "${destination_image}" | ||
else | ||
echo "Neither Docker nor nerdctl is available." | ||
exit 1 | ||
fi | ||
if [ $? -ne 0 ]; then | ||
echo "Failed to retag ${source_image} to ${destination_image}" | ||
exit 1 | ||
else | ||
echo "Successfully retag ${source_image} to ${destination_image}" | ||
fi |