我尝试使用本地仓库运行stub runner docker image,如下所示,
STUBRUNNER_IDS="cn.xxx.accounting:accounting-configserver:1.0.0:stubs:9876"
STUBRUNNER_REPOSITORY_ROOT="file:///m2/repository"
STUBRUNNER_PORT="8083"
SC_CONTRACT_DOCKER_VERSION=2.0.0.RC2
docker run --rm --interactive --tty -e "STUBRUNNER_IDS=${STUBRUNNER_IDS}" -e "REPO_WITH_BINARIES_URL=${STUBRUNNER_REPOSITORY_ROOT}" -p "${STUBRUNNER_PORT}:${STUBRUNNER_PORT}" -p "9876:9876" -v ~/.m2:/m2 springcloud/spring-cloud-contract-stub-runner:"${SC_CONTRACT_DOCKER_VERSION}"
然后我得到了以下错误,
引起:org.springframework.beans.BeanInstantiationException: 无法实例化 [org.springframework.cloud.contract.stubrunner.BatchStubRunner]: 工厂方法' batchStubRunner'抛出异常;嵌套异常是 java.lang.IllegalStateException:在类路径中找不到存根 [cn.xxx.accounting:会计-configserver]
看起来stub run正在使用classpath来查找存根。如何将存根模式更改为本地?我找不到spring-cloud-contract-stub-runner
的dockerfile的来源。任何环境都这么棘手吗?
答案 0 :(得分:1)
当然,将本地.m2的音量附加到容器中的音量就足够了。您还需要传递STUBRUNNER_STUBS_MODE=REMOTE
(https://github.com/spring-cloud/spring-cloud-contract/blob/master/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java#L100)
#!/bin/bash
SC_CONTRACT_DOCKER_VERSION="${SC_CONTRACT_DOCKER_VERSION:-1.2.4.BUILD-SNAPSHOT}"
APP_IP="$( ./whats_my_ip.sh )"
# Stub coordinates 'groupId:artifactId:version:classifier'
STUB_GROUP="${STUB_GROUP:-com.example}"
STUB_ARTIFACT="${STUB_ARTIFACT:-bookstore}"
STUB_VERSION="${STUB_VERSION:-0.0.1.RELEASE}"
STUB_PORT="9876"
# Spring Cloud Contract Stub Runner properties
STUBRUNNER_PORT="${STUBRUNNER_PORT:-8083}"
STUBRUNNER_IDS="${STUB_GROUP}:${STUB_ARTIFACT}:${STUB_VERSION}:stubs:${STUB_PORT}"
STUBRUNNER_REPOSITORY_ROOT="http://${APP_IP}:8081/artifactory/libs-release-local"
docker run --rm -e "STUBRUNNER_IDS=${STUBRUNNER_IDS}" -e "SERVER_PORT=${STUBRUNNER_PORT}" -e "STUBRUNNER_REPOSITORY_ROOT=${STUBRUNNER_REPOSITORY_ROOT}" -p "${STUBRUNNER_PORT}:${STUBRUNNER_PORT}" -p "${STUB_PORT}:${STUB_PORT}" -v ~/.m2:/root/m2 springcloud/spring-cloud-contract-stub-runner:"${SC_CONTRACT_DOCKER_VERSION}"
请注意,我们正在使用maven本地或我们的泊坞窗图片,但它指向${USER_HOME}/.m2
Docker中的AFAIR为/root/.m2
。