docker - 部署到多个 OpenShift Container Registry
问题描述
我创建了三个 openshift 容器注册表。例如,我将使用以下地址:
https://openshift-registry-1.com
https://openshift-registry-2.com
https://openshift-registry-3.com
我正在寻找一种方法或工具来将相同的图像推送到所有三个动作中。
解决方案
我会在我选择的 cicd/orchestration 工具(例如 Jenkins、Ansible Tower 等)中使用skopeo cli。skopeo 是一个命令行实用程序,可对容器映像和映像存储库执行各种操作。
查看官方 OpenShift 博客文章Promoting container images between container registries with skopeo示例用法。
他们在那里发布的示例:
def namespace, appReleaseTag, webReleaseTag, prodCluster, prodProject, prodToken
pipeline {
agent {
label 'skopeo'
}
stages {
stage('Choose Release Version') {
steps {
script {
openshift.withCluster() {
// Login to the production cluster
namespace = openshift.project()
prodCluster = env.PROD_MASTER.replace("https://","insecure://")
withCredentials([usernamePassword(credentialsId: "${namespace}-prod-credentials", usernameVariable: "PROD_USER", passwordVariable: "PROD_TOKEN")]) {
prodToken = env.PROD_TOKEN
}
// Get list of tags in the ImageStream to show the release-manager
def appTags = openshift.selector("istag").objects().collect { it.metadata.name }.findAll { it.startsWith 'app:' }.collect { it.replaceAll(/app:(.*)/, "\$1") }.sort()
timeout(5) {
def inputs = input(
ok: "Deploy",
message: "Enter release version to promote to PROD",
parameters: [
string(defaultValue: "prod", description: 'Name of the PROD project to create', name: 'PROD Project Name'),
choice(choices: appTags.join('\n'), description: '', name: 'Application Release Version'),
]
)
appReleaseTag = inputs['Application Release Version']
prodProject = inputs['PROD Project Name']
}
}
}
}
}
stage('Create PROD') {
steps {
script {
openshift.withCluster(prodCluster, prodToken) {
openshift.newProject(prodProject, "--display-name='CoolStore PROD'")
}
}
}
}
stage('Promote Images to PROD') {
steps {
script {
openshift.withCluster() {
def srcApplicationRef = openshift.selector("istag", "app:${appReleaseTag}").object().image.dockerImageReference
def destApplicationRef = "${env.PROD_REGISTRY}/${prodProject}/app:${appReleaseTag}"
def srcToken = readFile "/run/secrets/kubernetes.io/serviceaccount/token"
sh "skopeo copy docker://${srcApplicationRef} docker://${destApplicationRef} --src-creds openshift:${srcToken} --dest-creds openshift:${prodToken}"
}
}
}
}
stage('Deploy to PROD') {
steps {
script {
openshift.withCluster(prodCluster, prodToken) {
openshift.withProject(prodProject) {
def template = 'https://raw.githubusercontent.com/openshift-labs/myapp/myapp-template.yaml'
openshift.apply(
openshift.process("-f", template, "-p", "APPLICATION_IMAGE_VERSION=${appReleaseTag}", "-p", "IMAGE_NAMESPACE=")
)
}
}
}
}
}
}
}
推荐阅读
- php - 同一个生成器上的多个循环 - PHP
- azure - 从 Azure 触发函数执行 Azure 存储过程
- python - 如何从 python 中的印刷教科书中删除突出显示?
- java - 如何获得与通配符 css 选择器匹配的第二个元素?
- scikit-learn - scikit-learn 默认使用哪种决策树算法?
- c++ - auto 和 auto& 和有什么区别?
- java - Appcrash:如何通过按删除按钮删除edittext中的字符?
- php - Google Webmaster Tools 报告服务器错误 (5xx)
- amazon-web-services - 具有非 AWS 资源的 AWS Cognito
- javascript - React Link 的空字符串是有效值吗?