Skip to content

Commit 1970171

Browse files
committed
ci: validate Docker Compose overlay merges
1 parent 7983098 commit 1970171

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/checks.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,24 @@ jobs:
5858
run: npm ci
5959
- name: Run ESLint
6060
run: npm run build:check
61+
compose-validate:
62+
name: Validate Docker Compose overlays (Tor / I2P)
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v3
67+
- name: Validate merged compose files
68+
env:
69+
SECRET: ci_placeholder_not_for_production_use_repeat_to_64chars_aaaaaaaa
70+
run: node ./scripts/verify-compose-overlays.mjs
6171
test-units-and-cover:
6272
name: Unit Tests And Coverage
6373
runs-on: ubuntu-latest
6474
needs:
6575
- commit-lint
6676
- lint
6777
- build-check
78+
- compose-validate
6879
steps:
6980
- name: Checkout
7081
uses: actions/checkout@v3
@@ -100,6 +111,7 @@ jobs:
100111
- commit-lint
101112
- lint
102113
- build-check
114+
- compose-validate
103115
steps:
104116
- name: Checkout
105117
uses: actions/checkout@v3

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
"tor:docker:compose:start": "./scripts/start_with_tor",
5656
"tor:hostname": "./scripts/print_tor_hostname",
5757
"tor:docker:compose:stop": "./scripts/stop",
58+
"i2p:docker:compose:start": "./scripts/start_with_i2p",
59+
"i2p:hostname": "./scripts/print_i2p_hostname",
60+
"i2p:docker:compose:stop": "./scripts/stop",
61+
"compose:validate": "node ./scripts/verify-compose-overlays.mjs",
5862
"docker:integration:run": "docker compose -f ./test/integration/docker-compose.yml run --rm tests",
5963
"docker:test:integration": "npm run docker:integration:run -- npm run test:integration",
6064
"docker:cover:integration": "npm run docker:integration:run -- npm run cover:integration",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Validates docker-compose.yml merged with Tor / I2P overlays (config -q).
4+
* Requires Docker Desktop / Engine. Does not start containers.
5+
*/
6+
import { spawnSync } from 'node:child_process'
7+
import { existsSync } from 'node:fs'
8+
import { fileURLToPath } from 'node:url'
9+
import { dirname, join } from 'node:path'
10+
11+
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
12+
process.chdir(root)
13+
14+
function resolveDockerExe() {
15+
if (process.env.DOCKER_EXE && existsSync(process.env.DOCKER_EXE)) {
16+
return process.env.DOCKER_EXE
17+
}
18+
if (process.platform === 'win32' && process.env.ProgramFiles) {
19+
const candidate = join(
20+
process.env.ProgramFiles,
21+
'Docker',
22+
'Docker',
23+
'resources',
24+
'bin',
25+
'docker.exe',
26+
)
27+
if (existsSync(candidate)) {
28+
return candidate
29+
}
30+
}
31+
return 'docker'
32+
}
33+
34+
const dockerExe = resolveDockerExe()
35+
36+
const dockerCheck = spawnSync(dockerExe, ['compose', 'version'], { encoding: 'utf8' })
37+
if (dockerCheck.error || dockerCheck.status !== 0) {
38+
process.stderr.write(
39+
'docker is not installed or not on PATH. Install Docker Desktop / Engine, then run:\n' +
40+
' npm run compose:validate\n' +
41+
'On Windows, ensure Docker Desktop is running, or set DOCKER_EXE to the full path to docker.exe.\n',
42+
)
43+
process.exit(1)
44+
}
45+
46+
if (!process.env.SECRET || process.env.SECRET.length < 16) {
47+
process.env.SECRET =
48+
'ci_placeholder_not_for_production_use_repeat_to_64chars_aaaaaaaa'
49+
}
50+
51+
const runs = [
52+
['docker-compose.yml', 'docker-compose.i2p.yml'],
53+
['docker-compose.yml', 'docker-compose.tor.yml'],
54+
['docker-compose.yml', 'docker-compose.tor.yml', 'docker-compose.i2p.yml'],
55+
]
56+
57+
for (const files of runs) {
58+
const args = ['compose']
59+
for (const f of files) {
60+
args.push('-f', f)
61+
}
62+
args.push('config', '-q')
63+
const label = files.join(' + ')
64+
process.stdout.write(`== ${label} ==\n`)
65+
const r = spawnSync(dockerExe, args, { stdio: 'inherit' })
66+
if (r.status !== 0) {
67+
process.stderr.write(`compose validation failed for: ${label}\n`)
68+
process.exit(r.status ?? 1)
69+
}
70+
process.stdout.write('OK\n')
71+
}
72+
73+
process.stdout.write('All compose overlay merges validate successfully.\n')

scripts/verify_compose_overlays

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# Delegates to Node so the same validation runs on Windows (npm) and Linux/macOS.
3+
exec node "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/verify-compose-overlays.mjs"

0 commit comments

Comments
 (0)