mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
Clean up old docker images (#1087)
* run hadolint with reviewdog * add LINCENSE in Dockerfile * run hadolint with reviewdog * Reporter of reviewdog command is "github-pr-check" * format Dockerfile * ignore DL3007 in hadolint * clean up old docker images
This commit is contained in:
parent
03feed8907
commit
4cd02b0976
@ -13,17 +13,11 @@ timeout(time: 15, unit: 'MINUTES') {
|
|||||||
def imageName = "${PROJECT_NAME}/engine:${DOCKER_VERSION}"
|
def imageName = "${PROJECT_NAME}/engine:${DOCKER_VERSION}"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
def isExistSourceImage = sh(returnStatus: true, script: "docker inspect --type=image ${imageName} 2>&1 > /dev/null")
|
deleteImages("${imageName}", true)
|
||||||
if (isExistSourceImage == 0) {
|
|
||||||
def removeSourceImageStatus = sh(returnStatus: true, script: "docker rmi ${imageName}")
|
|
||||||
}
|
|
||||||
|
|
||||||
def customImage = docker.build("${imageName}")
|
def customImage = docker.build("${imageName}")
|
||||||
|
|
||||||
def isExistTargeImage = sh(returnStatus: true, script: "docker inspect --type=image ${params.DOKCER_REGISTRY_URL}/${imageName} 2>&1 > /dev/null")
|
deleteImages("${params.DOKCER_REGISTRY_URL}/${imageName}", true)
|
||||||
if (isExistTargeImage == 0) {
|
|
||||||
def removeTargeImageStatus = sh(returnStatus: true, script: "docker rmi ${params.DOKCER_REGISTRY_URL}/${imageName}")
|
|
||||||
}
|
|
||||||
|
|
||||||
docker.withRegistry("https://${params.DOKCER_REGISTRY_URL}", "${params.DOCKER_CREDENTIALS_ID}") {
|
docker.withRegistry("https://${params.DOKCER_REGISTRY_URL}", "${params.DOCKER_CREDENTIALS_ID}") {
|
||||||
customImage.push()
|
customImage.push()
|
||||||
@ -31,15 +25,28 @@ timeout(time: 15, unit: 'MINUTES') {
|
|||||||
} catch (exc) {
|
} catch (exc) {
|
||||||
throw exc
|
throw exc
|
||||||
} finally {
|
} finally {
|
||||||
def isExistSourceImage = sh(returnStatus: true, script: "docker inspect --type=image ${imageName} 2>&1 > /dev/null")
|
deleteImages("${imageName}", true)
|
||||||
if (isExistSourceImage == 0) {
|
deleteImages("${params.DOKCER_REGISTRY_URL}/${imageName}", true)
|
||||||
def removeSourceImageStatus = sh(returnStatus: true, script: "docker rmi ${imageName}")
|
|
||||||
}
|
|
||||||
|
|
||||||
def isExistTargeImage = sh(returnStatus: true, script: "docker inspect --type=image ${params.DOKCER_REGISTRY_URL}/${imageName} 2>&1 > /dev/null")
|
|
||||||
if (isExistTargeImage == 0) {
|
|
||||||
def removeTargeImageStatus = sh(returnStatus: true, script: "docker rmi ${params.DOKCER_REGISTRY_URL}/${imageName}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean deleteImages(String imageName, boolean force) {
|
||||||
|
def imageNameStr = imageName.trim()
|
||||||
|
def isExistImage = sh(returnStatus: true, script: "docker inspect --type=image ${imageNameStr} 2>&1 > /dev/null")
|
||||||
|
if (isExistImage == 0) {
|
||||||
|
def deleteImageStatus = 0
|
||||||
|
if (force) {
|
||||||
|
def imageID = sh(returnStdout: true, script: "docker inspect --type=image --format \"{{.ID}}\" ${imageNameStr}")
|
||||||
|
deleteImageStatus = sh(returnStatus: true, script: "docker rmi -f ${imageID}")
|
||||||
|
} else {
|
||||||
|
deleteImageStatus = sh(returnStatus: true, script: "docker rmi ${imageNameStr}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deleteImageStatus != 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user