Skip to content

Commit 3a132c0

Browse files
committed
Improve Jenkins db host network
1 parent 69b84fa commit 3a132c0

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

Jenkinsfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@ slaveTemplates.dockerTemplate { label ->
4242
def imageTag = env.TEST_IMAGE_TAG
4343
def runToken = UUID.randomUUID().toString().substring(0, 8)
4444
def buildSuffix = "${env.GIT_COMMIT_FULL}-${env.BUILD_ID}-${runToken}"
45+
def networkName = "test-net-${buildSuffix}"
4546
env.TEST_RUN_SUFFIX = buildSuffix
4647
def failuresDir = "${pwd()}/test_failures_${buildSuffix}"
4748

4849
sh "mkdir -p ${failuresDir}"
50+
sh "docker network create ${networkName}"
4951

50-
// Start postgres containers for each partition
5152
for (int i = 1; i <= numPartitions; i++) {
5253
def postgresContainerName = "test-postgres-${buildSuffix}-p${i}"
5354
sh "docker rm -f ${postgresContainerName} >/dev/null 2>&1 || true"
5455
sh "docker run \
5556
--rm --name ${postgresContainerName} \
57+
--network ${networkName} \
5658
-e POSTGRES_PASSWORD=password \
5759
--health-cmd 'pg_isready -U postgres' \
5860
--health-interval 2s \
@@ -61,7 +63,6 @@ slaveTemplates.dockerTemplate { label ->
6163
-d pgvector/pgvector:pg15"
6264
}
6365

64-
// Wait for each Postgres container to be ready
6566
sh """
6667
set -e
6768
for i in \$(seq 1 ${numPartitions}); do
@@ -84,13 +85,13 @@ slaveTemplates.dockerTemplate { label ->
8485

8586
try {
8687
def partitions = [:]
87-
8888
for (int i = 1; i <= numPartitions; i++) {
8989
def partition = i
90+
def dbHost = "test-postgres-${buildSuffix}-p${partition}"
9091
partitions["Partition ${partition}"] = {
9192
sh "docker run --rm \
92-
--link test-postgres-${buildSuffix}-p${partition}:test-db \
93-
--env DATABASE_URL=postgres://postgres:password@test-db:5432/postgres \
93+
--network ${networkName} \
94+
--env DATABASE_URL=postgres://postgres:password@${dbHost}:5432/postgres \
9495
--env MIX_TEST_PARTITION=${partition} \
9596
-v ${failuresDir}:/app/_build/test/failures \
9697
-t ${imageTag} \
@@ -101,11 +102,16 @@ slaveTemplates.dockerTemplate { label ->
101102
}
102103
}
103104

104-
parallel partitions
105-
} finally {
106-
for (int i = 1; i <= numPartitions; i++) {
107-
sh "docker kill test-postgres-${buildSuffix}-p${i} || true"
105+
timeout(time: 25, unit: 'MINUTES') {
106+
parallel partitions
108107
}
108+
} finally {
109+
sh """
110+
for i in \$(seq 1 ${numPartitions}); do
111+
docker rm -f test-postgres-${buildSuffix}-p\$i 2>/dev/null || true
112+
done
113+
docker network rm ${networkName} 2>/dev/null || true
114+
"""
109115
}
110116
}
111117
}

0 commit comments

Comments
 (0)