feat(制品库功能开发): 产品库Docker制品移入开发

更新Docker镜像拉取的python脚本:
1. 新增镜像文件输出目录和输出镜像文件名称两个参数
2. 由于在执行拉取镜像脚本时需要构建临时工作目录,通过输出目录参数将临时工作目录输出到指定文件夹,防止数据冲突
This commit is contained in:
OTTO 2024-07-31 11:35:12 +08:00
parent a5a1f01335
commit fae072e195
1 changed files with 6 additions and 5 deletions

View File

@ -10,15 +10,16 @@ import tarfile
import urllib3
urllib3.disable_warnings()
if len(sys.argv) != 3 :
print('Usage:\n\tdocker_pull.py [registry/][repository/]image[:tag|@digest] [outImgFilePath]\n')
if len(sys.argv) != 4 :
print('Usage:\n\tdocker_pull.py [registry/][repository/]image[:tag|@digest] [outDirPath] [outImgFileName]\n')
exit(1)
# Look for the Docker image to download
repo = 'library'
tag = 'latest'
imgparts = sys.argv[1].split('/')
outImgFilePath=sys.argv[2]
outDirPath=sys.argv[2]
outImgFileName=sys.argv[3]
try:
img,tag = imgparts[-1].split('@')
except ValueError:
@ -88,7 +89,7 @@ if (resp.status_code != 200):
layers = resp.json()['layers']
# Create tmp folder that will hold the image
imgdir = 'tmp_{}_{}'.format(img, tag.replace(':', '@'))
imgdir = outDirPath+os.sep+'tmp_{}_{}'.format(img, tag.replace(':', '@'))
os.mkdir(imgdir)
print('Creating image structure in: ' + imgdir)
@ -195,7 +196,7 @@ file.write(json.dumps(content))
file.close()
# Create image tar and clean tmp folder
docker_tar = outImgFilePath
docker_tar = outDirPath+os.sep+outImgFileName
sys.stdout.write("Creating archive...")
sys.stdout.flush()
tar = tarfile.open(docker_tar, "w")