Jenkins / docker:从供应商仓库中拉取镜像并推送到本地仓库
Jenkins / docker: Pull image from vendor repo and push to local repo
我正在尝试找到一种方法来为我的供应商提供的 special-app
容器执行以下操作:
- 从供应商那里拉 docker 图像
- 将 docker 图像推送到内部存储库(对于本地副本)
目前,对于我从第 3 方回购中获得的其他 docker 图像,我可以在 Github 中找到它们并且它们包含 Dockerfile,然后我在我的管道中使用它来构建,然后推送到我的个人像这样回购:
stage('Clone from Git') {
try {
git branch: 'master',
url: 'https://github.com/exampleapp.git'
} catch (Exception ex) {
println("Unable to git clone: ${ex}")
error 'Git Clone failure'
}
}
stage ('Build Docker Image') {
try {
dir('./') {
def customImage =
docker.build("myregistry.com/myimages/exampleapp:${env.BUILD_ID}")
}
} catch (Exception ex) {
error 'Docker Build failure'
}
}
stage ('Push Image to Registry') {
try {
docker.withRegistry('https://myregistry.com', 'mycreds') {
def customImage =
docker.image("myregistry.com/myimages/exampleapp:${env.BUILD_ID}")
customImage.push('latest')
}
} catch (Exception ex) {
println("Unable push image to registry: ${ex}")
error 'Registry Push failure'
}
}
但是对于special-app
,供应商基本上只提供一个yaml文件,然后我用它来创建容器:
docker-compose -p special-app -f vendor-provided.yml up -d
虽然这可以启动容器 运行,但此方法没有提供 Dockerfile,因此我无法使用上面用于其他图像的相同方法我确实有 Dockerfiles。
在这种情况下我应该怎么做?如果我没有 Dockerfile,如何从供应商处获取 docker 图像并将其推送到我的本地存储库以进行保管?在我的管道中是否有其他方法可以实现此目的?
(我们保留这些图像的本地副本作为标准过程,即使我们没有对其中一些图像进行 adjustments/customization - special-app
就是这种情况)。
谢谢
J
您可以尝试提取 vendor-provided.yml 从中提取的映像的 url/name 并在简单的 Dockerfile 中使用它来提取映像并创建您自己的映像:
使用中的技术你可以获得图像值。
管道的新阶段,您可以在其中创建单行 Dockerfile:
stage('Make Dockerfile from vendor yaml') {
steps {
script{
def valuesYaml = readYaml (file: './path-to/vendor-provided.yml')
def line1 = "FROM ${valuesYaml.image}"
writeFile file: "Dockerfile", text: line1
}
}
}
创建 Dockerfile:
FROM vendor-image
从这里您应该能够构建您的映像并将其推送到您的注册表。
我正在尝试找到一种方法来为我的供应商提供的 special-app
容器执行以下操作:
- 从供应商那里拉 docker 图像
- 将 docker 图像推送到内部存储库(对于本地副本)
目前,对于我从第 3 方回购中获得的其他 docker 图像,我可以在 Github 中找到它们并且它们包含 Dockerfile,然后我在我的管道中使用它来构建,然后推送到我的个人像这样回购:
stage('Clone from Git') {
try {
git branch: 'master',
url: 'https://github.com/exampleapp.git'
} catch (Exception ex) {
println("Unable to git clone: ${ex}")
error 'Git Clone failure'
}
}
stage ('Build Docker Image') {
try {
dir('./') {
def customImage =
docker.build("myregistry.com/myimages/exampleapp:${env.BUILD_ID}")
}
} catch (Exception ex) {
error 'Docker Build failure'
}
}
stage ('Push Image to Registry') {
try {
docker.withRegistry('https://myregistry.com', 'mycreds') {
def customImage =
docker.image("myregistry.com/myimages/exampleapp:${env.BUILD_ID}")
customImage.push('latest')
}
} catch (Exception ex) {
println("Unable push image to registry: ${ex}")
error 'Registry Push failure'
}
}
但是对于special-app
,供应商基本上只提供一个yaml文件,然后我用它来创建容器:
docker-compose -p special-app -f vendor-provided.yml up -d
虽然这可以启动容器 运行,但此方法没有提供 Dockerfile,因此我无法使用上面用于其他图像的相同方法我确实有 Dockerfiles。 在这种情况下我应该怎么做?如果我没有 Dockerfile,如何从供应商处获取 docker 图像并将其推送到我的本地存储库以进行保管?在我的管道中是否有其他方法可以实现此目的?
(我们保留这些图像的本地副本作为标准过程,即使我们没有对其中一些图像进行 adjustments/customization - special-app
就是这种情况)。
谢谢 J
您可以尝试提取 vendor-provided.yml 从中提取的映像的 url/name 并在简单的 Dockerfile 中使用它来提取映像并创建您自己的映像:
使用
管道的新阶段,您可以在其中创建单行 Dockerfile:
stage('Make Dockerfile from vendor yaml') {
steps {
script{
def valuesYaml = readYaml (file: './path-to/vendor-provided.yml')
def line1 = "FROM ${valuesYaml.image}"
writeFile file: "Dockerfile", text: line1
}
}
}
创建 Dockerfile:
FROM vendor-image
从这里您应该能够构建您的映像并将其推送到您的注册表。