cloud foundry 将路由从一个应用程序复制到另一个应用程序
cloud foundry copy routes from one app to another
Cloud Foundry 是否可以在进行蓝绿部署时将缺失的路由从一个应用程序复制到另一个应用程序?
我有一个几乎没有手动添加路由的应用程序,在进行蓝绿部署(通过脚本自动执行)时,我想将 missing/manually 添加的路由复制到新应用程序中。可能吗?
脚本:
#!/bin/bash
path="C:/Users/.../Desktop/cf_through_sh/appName.jar"
spaceName="development"
appBlue="appName"
appGreen="${appName}-dev"
manifestFile="C:/Users/.../Desktop/cf_through_sh/manifest-dev.yml"
domains=("domain1.com" "domain2.com")
appHosts=("host-v1" "host-v2")
evaluate_return_code (){
ret=
if [[ $ret != 0 ]]
then
exit $ret
fi
}
switch_to_target_space() {
space="development"
echo "Change space to ${space}"
cf t -s ${space}
evaluate_return_code $?
}
push_new_release() {
appGreen=
if [ ! -f "${manifestFile}" ]; then
echo "Missing manifest: ${manifestFile}";
exit 1;
fi
if [ ! -f "${path}" ]; then
echo "Missing artifact: ${path}";
exit 1;
fi
echo "Deploying ${path} as ${appGreen}"
cf push ${appGreen} -f ${manifestFile} -p ${path} --no-route
evaluate_return_code $?
}
map_routes() {
app=
domains=
shift
appHosts=
for host in ${appHosts[*]}; do
echo "Mapping ${host} to ${app}"
for domain in ${domains[*]}; do
cf map-route ${app} ${domain} -n ${host}
evaluate_return_code $?
done
done
}
unmap_routes() {
app=
domains=
shift
appHosts=
for host in ${appHosts[*]}; do
echo "Unmapping ${host} from ${app}"
for domain in ${domains[*]}; do
cf unmap-route ${app} ${domain} -n ${host}
evaluate_return_code $?
done
done
}
rename_app() {
oldName=
newName=
echo "Renaming ${oldName} to ${newName}"
cf rename ${oldName} ${newName}
evaluate_return_code $?
}
switch_names() {
appBlue=
appGreen=
appTemp="${appBlue}-old"
rename_app ${appBlue} ${appTemp}
rename_app ${appGreen} ${appBlue}
rename_app ${appTemp} ${appGreen}
}
stop_old_release() {
echo "Stopping old ${appGreen} app"
cf stop ${appGreen}
evaluate_return_code $?
}
switch_to_target_space ${spaceName}
push_new_release ${appGreen}
map_routes ${appGreen} ${domains[*]} ${appHosts[*]}
unmap_routes ${appBlue} ${domains[*]} ${appHosts[*]}
switch_names ${appBlue} ${appGreen}
stop_old_release
echo "DONE"
exit 0;
例如:
appblue 有 5 条路线
1. host-v1.domain1.com
2. host-v2.domain1.com
3. host-v1.domain2.com
4. host-v2.domain2.com
5. manual-add.domain1.com //manually added route through admin UI
通过脚本应用进行蓝绿部署后只包含4条路由
1. host-v1.domain1.com
2. host-v2.domain1.com
3. host-v1.domain2.com
4. host-v2.domain2.com
如何复制缺失的第5条路线?我不想从脚本中传递主机 manual-add,因为它是手动添加的。
一般来说,如果没有映射,是否可以将路由从一个应用程序复制到另一个应用程序?
这只能通过 Jenkins(或任何 CI-CD 工具)完成。我们在我们的案例中所做的是,我们有一个 CF-Manifest-Template.yml
和 CF-Manifest-settings.json
并且我们有一个 gradle 任务将应用 JSON 中的设置并填充 Manifest-temple 和生成 cf-manifest-generated.yml
gradle 文件将有一个任务将使用此生成的清单文件进行蓝绿部署,并且所有路由都将硬编码在清单文件中。这是这样做的标准方法。
但是如果您想从 Cloud Foundry 中的应用程序 运行 复制路由并将这些路由复制到另一个应用程序,那么您需要编写一个 REST Client
连接到 Cloud Foundry CloudController
并获取 App-A
的所有路由,然后创建到 APP-B
的路由
非常简单!!
编写一个执行此命令的 REST 客户端
cf app APP-A
这将带回 APP-A 的详细信息作为 JSON 响应。响应将具有这些参数
Showing health and status for app APP-A in org Org-A / space DEV as arun2381985@yahoo.com...
name: APP-A
requested state: started
instances: 1/1
usage: 1G x 1 instances
routes: ********
last uploaded: Sat 25 Aug 00:25:45 IST 2018
stack: cflinuxfs2
buildpack: java_buildpack
阅读此 JSON 响应并收集 APP-A 的路由,然后将其映射到 APP-B .. 非常简单
Cloud Foundry 是否可以在进行蓝绿部署时将缺失的路由从一个应用程序复制到另一个应用程序?
我有一个几乎没有手动添加路由的应用程序,在进行蓝绿部署(通过脚本自动执行)时,我想将 missing/manually 添加的路由复制到新应用程序中。可能吗?
脚本:
#!/bin/bash
path="C:/Users/.../Desktop/cf_through_sh/appName.jar"
spaceName="development"
appBlue="appName"
appGreen="${appName}-dev"
manifestFile="C:/Users/.../Desktop/cf_through_sh/manifest-dev.yml"
domains=("domain1.com" "domain2.com")
appHosts=("host-v1" "host-v2")
evaluate_return_code (){
ret=
if [[ $ret != 0 ]]
then
exit $ret
fi
}
switch_to_target_space() {
space="development"
echo "Change space to ${space}"
cf t -s ${space}
evaluate_return_code $?
}
push_new_release() {
appGreen=
if [ ! -f "${manifestFile}" ]; then
echo "Missing manifest: ${manifestFile}";
exit 1;
fi
if [ ! -f "${path}" ]; then
echo "Missing artifact: ${path}";
exit 1;
fi
echo "Deploying ${path} as ${appGreen}"
cf push ${appGreen} -f ${manifestFile} -p ${path} --no-route
evaluate_return_code $?
}
map_routes() {
app=
domains=
shift
appHosts=
for host in ${appHosts[*]}; do
echo "Mapping ${host} to ${app}"
for domain in ${domains[*]}; do
cf map-route ${app} ${domain} -n ${host}
evaluate_return_code $?
done
done
}
unmap_routes() {
app=
domains=
shift
appHosts=
for host in ${appHosts[*]}; do
echo "Unmapping ${host} from ${app}"
for domain in ${domains[*]}; do
cf unmap-route ${app} ${domain} -n ${host}
evaluate_return_code $?
done
done
}
rename_app() {
oldName=
newName=
echo "Renaming ${oldName} to ${newName}"
cf rename ${oldName} ${newName}
evaluate_return_code $?
}
switch_names() {
appBlue=
appGreen=
appTemp="${appBlue}-old"
rename_app ${appBlue} ${appTemp}
rename_app ${appGreen} ${appBlue}
rename_app ${appTemp} ${appGreen}
}
stop_old_release() {
echo "Stopping old ${appGreen} app"
cf stop ${appGreen}
evaluate_return_code $?
}
switch_to_target_space ${spaceName}
push_new_release ${appGreen}
map_routes ${appGreen} ${domains[*]} ${appHosts[*]}
unmap_routes ${appBlue} ${domains[*]} ${appHosts[*]}
switch_names ${appBlue} ${appGreen}
stop_old_release
echo "DONE"
exit 0;
例如: appblue 有 5 条路线
1. host-v1.domain1.com
2. host-v2.domain1.com
3. host-v1.domain2.com
4. host-v2.domain2.com
5. manual-add.domain1.com //manually added route through admin UI
通过脚本应用进行蓝绿部署后只包含4条路由
1. host-v1.domain1.com
2. host-v2.domain1.com
3. host-v1.domain2.com
4. host-v2.domain2.com
如何复制缺失的第5条路线?我不想从脚本中传递主机 manual-add,因为它是手动添加的。
一般来说,如果没有映射,是否可以将路由从一个应用程序复制到另一个应用程序?
这只能通过 Jenkins(或任何 CI-CD 工具)完成。我们在我们的案例中所做的是,我们有一个 CF-Manifest-Template.yml
和 CF-Manifest-settings.json
并且我们有一个 gradle 任务将应用 JSON 中的设置并填充 Manifest-temple 和生成 cf-manifest-generated.yml
gradle 文件将有一个任务将使用此生成的清单文件进行蓝绿部署,并且所有路由都将硬编码在清单文件中。这是这样做的标准方法。
但是如果您想从 Cloud Foundry 中的应用程序 运行 复制路由并将这些路由复制到另一个应用程序,那么您需要编写一个 REST Client
连接到 Cloud Foundry CloudController
并获取 App-A
的所有路由,然后创建到 APP-B
非常简单!!
编写一个执行此命令的 REST 客户端
cf app APP-A
这将带回 APP-A 的详细信息作为 JSON 响应。响应将具有这些参数
Showing health and status for app APP-A in org Org-A / space DEV as arun2381985@yahoo.com...
name: APP-A
requested state: started
instances: 1/1
usage: 1G x 1 instances
routes: ********
last uploaded: Sat 25 Aug 00:25:45 IST 2018
stack: cflinuxfs2
buildpack: java_buildpack
阅读此 JSON 响应并收集 APP-A 的路由,然后将其映射到 APP-B .. 非常简单