docker - Testcontainers 无法在 Docker 中获取 Jenkins kubernates docker 上的映射端口
问题描述
我正在尝试在 Docker 容器中的 Jenkins Kubernetes Docker 上使用 Testcontainers 运行我的集成测试。
测试容器版本:1.15.3
但是,它总是无法在 DinD 容器中获取 Container.getMappedPort(X)。
它在我的本地设置上工作得非常好,并设法获取映射的端口。
有没有人遇到过这个问题或有解决方案?
我的詹金斯文件
#!groovy
def label = "debug-${UUID.randomUUID().toString()}"
podTemplate(label: label, slaveConnectTimeout: '10', containers: [
containerTemplate(
name: 'docker-in-docker',
image: 'cfzen/dind:java11',
privileged: true,
workingDir: '/home/jenkins/agent',
ttyEnabled: true,
command: 'cat',
envVars: [
envVar(key: 'TESTCONTAINERS_HOST_OVERRIDE', value: 'tcp://localhost:2375'),
envVar(key: 'TESTCONTAINERS_RYUK_DISABLED', value: 'true'),
]
),
containerTemplate(
name: 'helm-kubectl',
image: 'dtzar/helm-kubectl',
workingDir: '/home/jenkins/agent/',
ttyEnabled: true,
command: 'cat'
)
],
volumes: [hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),],
annotations: [
podAnnotation(key: 'iam.amazonaws.com/role',
value: 'arn:aws:iam::xxxxxxxxxxx')
],
)
{
node(label) {
deleteDir()
stage('Checkout') {
checkout scm
def shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
currentBuild.description = "${shortCommit}"
}
stage('Run Integration tests') {
container('docker-in-docker') {
withCredentials([
usernamePassword(credentialsId: 'jenkins-artifactory-credentials',
passwordVariable: 'ARTIFACTORY_SERVER_PASSWORD',
usernameVariable: 'ARTIFACTORY_SERVER_USERNAME')])
{
echo 'Run Integration tests'
sh("mvn -B clean verify -q -s mvn/local-settings.xml")
}
}
}
测试运行者:
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "classpath:features")
public final class RunCucumberIT {
@BeforeClass
public static void init(){
Containers.POSTGRES.start();
System.out.println("Exposed port of db is"+Containers.POSTGRES.getExposedPorts());
System.out.println("Assigned port of db is"+Containers.POSTGRES.getFirstMappedPort());
Containers.WIREMOCK.start();
Containers.S3.start();
}
private RunCucumberIT() {
}
}
在 Containers.POSTGRES.getFirstMappedPort() 失败
Requested port (X) is not mapped
解决方案
推荐阅读
- c# - 如何使用包含在其类依赖注入中的 .net 5 类库的 dll?
- python - Pip 可编辑安装未按预期运行
- docker - Docker 问题(无法加载或找到主类)
- microsoft-dynamics - MS-Dynamics 2016/365 搜索中的 PDF 索引
- python - 问:ValueError: unknown type object python 是什么意思?
- python - 我正在 python 中显示时间,但它没有打印我想要的内容
- git - Windows 上的 npm 安装因 git 存储库而失败
- jquery - ClickFunnels - 如何将我的自定义结帐表单集成到 ClickFunnels?
- javascript - 如何将 Service Worker 任务置于后台?
- python - 识别与前几天相比的缺失值并创建新的数据框 Pandas