-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to check Docker Compose files and GitHub workflow (#12)
- Loading branch information
1 parent
4fb9de8
commit d1a53ff
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
name: Check | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
- run: ./src/check.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ services/webhook-handler | |
!/.gitignore | ||
!/README.md | ||
!/SETUP.md | ||
|
||
!.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env -S COLI_CONC_BASE=. deno run --allow-env --allow-read --allow-sys --ext=ts | ||
|
||
/** | ||
* Checks docker-compose.yml files for issues: | ||
* | ||
* - Duplicate service names | ||
* | ||
* Ideas for other issues to check: | ||
* | ||
* - restart directive | ||
* - Docker networks | ||
* - volume paths | ||
*/ | ||
|
||
Deno.env.set("FORCE_COLOR", "2") | ||
import { existsSync } from "https://deno.land/std/fs/mod.ts" | ||
|
||
// Determine available targets by reading docker-compose.yml files in service subfolders | ||
import { parse as parseYaml } from "https://deno.land/[email protected]/yaml/mod.ts" | ||
import { getEnv } from "../src/utils.ts" | ||
const { servicePath } = getEnv("") | ||
|
||
const serviceNamesToComposeFiles = {} | ||
let ok = true | ||
|
||
for await (const { name, isDirectory } of Deno.readDir(servicePath)) { | ||
if (!isDirectory) { | ||
continue | ||
} | ||
try { | ||
// Try to read docker-compose.yml | ||
const file = `${servicePath}/${name}/docker-compose.yml` | ||
const fileShort = file.replace(servicePath, "") | ||
const compose = parseYaml(await Deno.readTextFile(file)) | ||
const errors: String[] = [] | ||
for (const service of Object.keys(compose?.services || {})) { | ||
if (serviceNamesToComposeFiles[service]) { | ||
errors.push(`!!! Service "${service}" is already defined in ${serviceNamesToComposeFiles[service]}`) | ||
ok = false | ||
} else { | ||
serviceNamesToComposeFiles[service] = fileShort | ||
} | ||
} | ||
if (errors.length) { | ||
console.error(`%c${fileShort}`, "color: red") | ||
errors.forEach(error => console.error(`%c ${error}`, "color: red")) | ||
} else { | ||
console.log(`%c${fileShort}`, "color: green") | ||
console.log("%c All good.", "color: green") | ||
} | ||
} catch (_) { | ||
// Just ignore errors as we are expecting them | ||
} | ||
} | ||
|
||
if (!ok) { | ||
Deno.exit(1) | ||
} |