将Stub Runner引导服务器部署到PCF

时间:2018-07-30 15:49:56

标签: pivotal-cloud-foundry spring-cloud-contract

我们正尝试使用Stub Runner Boot在Nexus(和本地存储库)上提供存根服务器和存根。

在我提交的其他问题的帮助下,我或多或少在本地进行了整理。

但是现在,我认为我将面临另一个问题,并且再次陷入困境...我们将把存根服务器部署到PCF进行烟雾测试。 我们可以高兴地说curl pcf_host/stubs,它将以配置的存根和端口号的列表作为响应。

但是存根将在某个端口中运行(我们甚至可以将其设置为静态,配置存根服务器),但我认为我们无法在443(或perhpas 80)以外的端口上调用PCF ,或者可以吗?

现在,我已经写了所有这些内容,我开始意识到问题与PCF而不是与SCC有关,我必须说,我对PCF的了解甚至比对SCC的了解还要小。

如果有人可以帮助,将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:1)

很好,您问了这个问题:)

我们已经使用Spring Cloud Pipelines解决了这个问题。您可以在https://cloud.spring.io/spring-cloud-pipelines/single/spring-cloud-pipelines.html#_3_8_enable_stubs_for_smoke_tests中了解更多信息。

简而言之,您需要打开端口并允许您的应用程序具有多个端口绑定。另外,您还必须生成路线。我们已经在这里https://github.com/spring-cloud/spring-cloud-pipelines/blob/master/common/src/main/bash/pipeline-cf.sh#L577

让我在此处复制该代码的主要部分

# FUNCTION: addMultiplePortsSupport {{{
# Adds multiple ports support for Stub Runner Boot
# Uses [PAAS_TEST_SPACE_PREFIX], [ENVIRONMENT] env vars
#
# $1 - Stub Runner name
# $2 - IDs of stubs to be downloaded
# $3 - path to Stub Runner manifest
function addMultiplePortsSupport() {
    local stubRunnerName="${1}"
    local stubrunnerIds="${2}"
    local pathToManifest="${3}"
    local appName
    appName=$(retrieveAppName)
    local hostname
    hostname="$(hostname "${stubRunnerName}" "${ENVIRONMENT}" "${pathToManifest}")"
    hostname="${hostname}-${appName}"
    echo "Hostname for ${stubRunnerName} is ${hostname}"
    local testSpace="${PAAS_TEST_SPACE_PREFIX}-${appName}"
    local domain
    domain="$( getDomain "${hostname}" )"
    echo "Domain for ${stubRunnerName} is ${domain}"
    # APPLICATION_HOSTNAME and APPLICATION_DOMAIN will be used for stub registration. Stub Runner Boot
    # will use this environment variable to hardcode the hostname of the stubs
    setEnvVar "${stubRunnerName}" "APPLICATION_HOSTNAME" "${hostname}"
    setEnvVar "${stubRunnerName}" "APPLICATION_DOMAIN" "${domain}"
    local previousIfs="${IFS}"
    local listOfPorts=""
    local appGuid
    appGuid="$( "${CF_BIN}" curl "/v2/apps?q=name:${stubRunnerName}" -X GET | jq '.resources[0].metadata.guid' | sed 's/^"\(.*\)"$/\1/' )"
    echo "App GUID for ${stubRunnerName} is ${appGuid}"
    IFS="," read -ra vals <<< "${stubrunnerIds}"
    for stub in "${vals[@]}"; do
        echo "Parsing ${stub}"
        local port
        port=${stub##*:}
        if [[ "${listOfPorts}" == "" ]]; then
            listOfPorts="${port}"
        else
            listOfPorts="${listOfPorts},${port}"
        fi
    done
    echo "List of added ports: [${listOfPorts}]"
    "${CF_BIN}" curl "/v2/apps/${appGuid}" -X PUT -d "{\"ports\":[8080,${listOfPorts}]}"
    echo "Successfully updated the list of ports for [${stubRunnerName}]"
    IFS="," read -ra vals <<< "${stubrunnerIds}"
    for stub in "${vals[@]}"; do
        echo "Parsing ${stub}"
        local port
        port=${stub##*:}
        local newHostname="${hostname}-${port}"
        echo "Creating route with hostname [${newHostname}]"
        "${CF_BIN}" create-route "${testSpace}" "${domain}" --hostname "${newHostname}"
        local routeGuid
        routeGuid="$( "${CF_BIN}" curl -X GET "/v2/routes?q=host:${newHostname}" | jq '.resources[0].metadata.guid' | sed 's/^"\(.*\)"$/\1/' )"
        echo "GUID of the new route is [${routeGuid}]. Will update the mapping for port [${port}]"
        "${CF_BIN}" curl "/v2/route_mappings" -X POST -d "{ \"app_guid\": \"${appGuid}\", \"route_guid\": \"${routeGuid}\", \"app_port\": ${port} }"
        echo "Successfully updated the new route mapping for port [${port}]"
    done
    IFS="${previousIfs}"
} # }}}