云代工厂复制从一个应用程序到另一个应用程序

问题描述 投票:6回答:1

Cloud Foundry是否可以在执行蓝绿色部署时将丢失的路由从一个应用程序复制到另一个应用程序?

我有一个手动添加路线的应用程序,同时进行蓝绿色部署(通过脚本自动化)我想将丢失/手动添加的路由复制到新的应用程序。可能吗?

脚本:

#!/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=$1
  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=$1
    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=$1
    domains=$2
    shift
    appHosts=$3

    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=$1
    domains=$2
    shift
    appHosts=$3

    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=$1
    newName=$2
    echo "Renaming ${oldName} to ${newName}"
    cf rename ${oldName} ${newName}
    evaluate_return_code $?
}

switch_names() {
    appBlue=$1
    appGreen=$2
    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条路线?我不想从脚本中传递主机手动添加,因为它是手动添加的。

通常,如果没有映射,是否可以将路径从一个应用程序复制到另一个应用程序?

java bash shell cloudfoundry pivotal-cloud-foundry
1个回答
1
投票

这必须通过Jenkins(或任何CI-CD工具)完成。我们在我们的案例中所做的是,我们有一个CF-Manifest-Template.ymlCF-Manifest-settings.json,我们有一个gradle任务,将应用JSON的设置并填充Manifest-temple并生成cf-manifest-generated.yml

gradle文件将具有通过使用此生成的清单文件进行蓝绿色部署的任务,并且所有路由将在清单文件中进行硬编码。这是执行此操作的标准方法。

但是如果你想从在Cloud Foundry中运行的应用程序复制路由并将thos路由复制到另一个应用程序,那么你需要编写连接到Cloud Foundry REST ClientCloudController并获取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 [email protected]...

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 ..它非常简单

© www.soinside.com 2019 - 2024. All rights reserved.