代码之家  ›  专栏  ›  技术社区  ›  Pratap A.K

从一个应用程序到另一个应用程序的云复制路由

  •  6
  • Pratap A.K  · 技术社区  · 6 年前

    CloudFoundry在进行蓝绿部署时,是否可以将丢失的路由从一个应用复制到另一个应用?

    脚本:

    #!/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
    

     1. host-v1.domain1.com
     2. host-v2.domain1.com
     3. host-v1.domain2.com
     4. host-v2.domain2.com
    

    如何复制丢失的第五条路线?我不想超过主持人

    1 回复  |  直到 6 年前
        1
  •  1
  •   Arun    6 年前

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

    gradle文件将有一个任务,通过使用这个生成的清单文件进行蓝绿色部署,所有路由都将在清单文件中硬编码。这是做这件事的标准方法。

    但是如果你想从一个运行在CloudFoundry中的应用程序复制路由,并将这些路由复制到另一个应用程序,那么你需要编写一个 REST Client 连接到Cloud Foundry的 CloudController App-A 然后创建到 APP-B

    很简单!!

    编写执行此命令的REST客户机

    cf附录A

    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。。很简单

    推荐文章