Skip to content

Commit 65a9fbf

Browse files
committed
Hardcode databases in CI
1 parent bd6347f commit 65a9fbf

File tree

2 files changed

+121
-21
lines changed

2 files changed

+121
-21
lines changed

.github/workflows/ci.yml

Lines changed: 107 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@ jobs:
3131
container:
3232
image: registry.gitlab.com/finestructure/spi-base:1.1.1
3333
options: --privileged
34-
services:
35-
postgres:
36-
image: postgres:16-alpine
37-
env:
38-
POSTGRES_DB: spi_test
39-
POSTGRES_USER: spi_test
40-
POSTGRES_PASSWORD: xxx
41-
ports:
42-
- '5432:5432'
43-
options: >-
44-
--health-cmd pg_isready
45-
--health-interval 10s
46-
--health-timeout 5s
47-
--health-retries 5
4834
steps:
4935
- name: GH Runner bug workaround
5036
run: sysctl -w vm.mmap_rnd_bits=28
@@ -59,6 +45,113 @@ jobs:
5945
COLLECTION_SIGNING_PRIVATE_KEY: ${{ secrets.COLLECTION_SIGNING_PRIVATE_KEY }}
6046
DATABASE_HOST: postgres
6147
DATABASE_PORT: '5432'
48+
services:
49+
# Make sure the ports expose here (6000-60007) align with the ports
50+
# hard-coded in DatabasePool.runningDatabases().
51+
db-0:
52+
image: postgres:16-alpine
53+
env:
54+
POSTGRES_DB: spi_test
55+
POSTGRES_USER: spi_test
56+
POSTGRES_PASSWORD: xxx
57+
ports:
58+
- '6000:5432'
59+
options: >-
60+
--health-cmd pg_isready
61+
--health-interval 10s
62+
--health-timeout 5s
63+
--health-retries 5
64+
db-1:
65+
image: postgres:16-alpine
66+
env:
67+
POSTGRES_DB: spi_test
68+
POSTGRES_USER: spi_test
69+
POSTGRES_PASSWORD: xxx
70+
ports:
71+
- '6001:5432'
72+
options: >-
73+
--health-cmd pg_isready
74+
--health-interval 10s
75+
--health-timeout 5s
76+
--health-retries 5
77+
db-2:
78+
image: postgres:16-alpine
79+
env:
80+
POSTGRES_DB: spi_test
81+
POSTGRES_USER: spi_test
82+
POSTGRES_PASSWORD: xxx
83+
ports:
84+
- '6002:5432'
85+
options: >-
86+
--health-cmd pg_isready
87+
--health-interval 10s
88+
--health-timeout 5s
89+
--health-retries 5
90+
db-3:
91+
image: postgres:16-alpine
92+
env:
93+
POSTGRES_DB: spi_test
94+
POSTGRES_USER: spi_test
95+
POSTGRES_PASSWORD: xxx
96+
ports:
97+
- '6003:5432'
98+
options: >-
99+
--health-cmd pg_isready
100+
--health-interval 10s
101+
--health-timeout 5s
102+
--health-retries 5
103+
db-4:
104+
image: postgres:16-alpine
105+
env:
106+
POSTGRES_DB: spi_test
107+
POSTGRES_USER: spi_test
108+
POSTGRES_PASSWORD: xxx
109+
ports:
110+
- '6004:5432'
111+
options: >-
112+
--health-cmd pg_isready
113+
--health-interval 10s
114+
--health-timeout 5s
115+
--health-retries 5
116+
db-5:
117+
image: postgres:16-alpine
118+
env:
119+
POSTGRES_DB: spi_test
120+
POSTGRES_USER: spi_test
121+
POSTGRES_PASSWORD: xxx
122+
ports:
123+
- '6005:5432'
124+
options: >-
125+
--health-cmd pg_isready
126+
--health-interval 10s
127+
--health-timeout 5s
128+
--health-retries 5
129+
db-6:
130+
image: postgres:16-alpine
131+
env:
132+
POSTGRES_DB: spi_test
133+
POSTGRES_USER: spi_test
134+
POSTGRES_PASSWORD: xxx
135+
ports:
136+
- '6006:5432'
137+
options: >-
138+
--health-cmd pg_isready
139+
--health-interval 10s
140+
--health-timeout 5s
141+
--health-retries 5
142+
db-7:
143+
image: postgres:16-alpine
144+
env:
145+
POSTGRES_DB: spi_test
146+
POSTGRES_USER: spi_test
147+
POSTGRES_PASSWORD: xxx
148+
ports:
149+
- '6007:5432'
150+
options: >-
151+
--health-cmd pg_isready
152+
--health-interval 10s
153+
--health-timeout 5s
154+
--health-retries 5
62155
63156
release-build-linux:
64157
name: Release build

Tests/AppTests/Helpers/DatabasePool.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,20 @@ actor DatabasePool {
9999
}
100100

101101
private func runningDatabases() async throws -> [Database] {
102-
let stdout = try await ShellOut.shellOut(to: .getContainerNames).stdout
103-
return stdout
104-
.components(separatedBy: "\n")
105-
.filter { $0.starts(with: "spi_test_") }
106-
.map { String($0.dropFirst("spi_test_".count)) }
107-
.compactMap(Int.init)
108-
.map(Database.init(port:))
102+
if isRunningInCI() {
103+
// We don't have docker available in CI to probe for running dbs.
104+
// Instead, we have a hard-coded list of dbs we launch in the GH workflow
105+
// file and correspondingly, we hard-code their ports here.
106+
return (6000..<6008).map(Database.init)
107+
} else {
108+
let stdout = try await ShellOut.shellOut(to: .getContainerNames).stdout
109+
return stdout
110+
.components(separatedBy: "\n")
111+
.filter { $0.starts(with: "spi_test_") }
112+
.map { String($0.dropFirst("spi_test_".count)) }
113+
.compactMap(Int.init)
114+
.map(Database.init(port:))
115+
}
109116
}
110117

111118
private func retainDatabase() async throws -> Database {

0 commit comments

Comments
 (0)