Skip to content

Commit 3a2292f

Browse files
aberohamclaude
andcommitted
address review: move docker files to docker/, namespace env vars
Move Dockerfile, docker-compose.yml, generate-env.sh, .env.example into docker/ to keep the repo root clean. Namespace all config env var overrides with NICTOOL_ prefix to match NicTool 2 conventions (NICTOOL_DB_HOST, NICTOOL_DB_USER_PASSWORD, NICTOOL_HTTP_HOST, etc). DB_ROOT_PASSWORD stays unprefixed as it's a MariaDB convention shared with NicTool 2. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1bcf896 commit 3a2292f

7 files changed

Lines changed: 34 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ jobs:
9292
steps:
9393
- uses: actions/checkout@v6
9494
- name: Generate .env
95-
run: ./generate-env.sh
95+
run: ./docker/generate-env.sh
9696
- name: Build and start services
97-
run: docker compose up --build -d --wait
97+
run: docker compose -f docker/docker-compose.yml up --build -d --wait
9898
- name: Run tests
99-
run: docker compose exec api npm test
99+
run: docker compose -f docker/docker-compose.yml exec api npm test
100100
- name: Logs on failure
101101
if: failure()
102-
run: docker compose logs
102+
run: docker compose -f docker/docker-compose.yml logs
103103
- name: Tear down
104104
if: always()
105-
run: docker compose down -v
105+
run: docker compose -f docker/docker-compose.yml down -v
106106

107107
test-win:
108108
needs: [ get-lts ]

.env.example renamed to docker/.env.example

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NicTool API environment configuration
2-
# Copy to .env, or run: ./dist/setup/generate-env.sh
2+
# Copy to .env, or run: ./docker/generate-env.sh
33

44
# --- Database (MariaDB/MySQL) ---
55
DB_ROOT_PASSWORD=changeme
@@ -8,13 +8,10 @@ NICTOOL_DB_USER=nictool
88
NICTOOL_DB_USER_PASSWORD=changeme
99

1010
# --- API config overrides (optional, override conf.d/*.toml defaults) ---
11-
# DB_HOST=127.0.0.1
12-
# DB_PORT=3306
13-
# DB_USER=nictool
14-
# DB_PASSWORD=
15-
# DB_NAME=nictool
16-
# HTTP_HOST=localhost
17-
# HTTP_PORT=3000
11+
# NICTOOL_DB_HOST=127.0.0.1
12+
# NICTOOL_DB_PORT=3306
13+
# NICTOOL_HTTP_HOST=localhost
14+
# NICTOOL_HTTP_PORT=3000
1815

1916
# --- Docker Compose port mapping ---
2017
# DB_PORT=3307
File renamed without changes.
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ services:
1010
SQL_DIR: /sql
1111
volumes:
1212
- db-data:/var/lib/mysql
13-
- ./sql:/sql:ro
14-
- ./sql/init-mysql.sh:/docker-entrypoint-initdb.d/init-mysql.sh:ro
13+
- ../sql:/sql:ro
14+
- ../sql/init-mysql.sh:/docker-entrypoint-initdb.d/init-mysql.sh:ro
1515
ports:
1616
- "${DB_PORT:-3307}:3306"
1717
healthcheck:
@@ -21,19 +21,21 @@ services:
2121
retries: 10
2222

2323
api:
24-
build: .
24+
build:
25+
context: ..
26+
dockerfile: docker/Dockerfile
2527
ports:
2628
- "${API_PORT:-3000}:3000"
2729
depends_on:
2830
db:
2931
condition: service_healthy
3032
environment:
3133
NODE_ENV: development
32-
DB_HOST: db
33-
DB_USER: ${NICTOOL_DB_USER:-nictool}
34-
DB_PASSWORD: ${NICTOOL_DB_USER_PASSWORD}
35-
DB_NAME: ${NICTOOL_DB_NAME:-nictool}
36-
HTTP_HOST: "0.0.0.0"
34+
NICTOOL_DB_HOST: db
35+
NICTOOL_DB_USER: ${NICTOOL_DB_USER:-nictool}
36+
NICTOOL_DB_USER_PASSWORD: ${NICTOOL_DB_USER_PASSWORD}
37+
NICTOOL_DB_NAME: ${NICTOOL_DB_NAME:-nictool}
38+
NICTOOL_HTTP_HOST: "0.0.0.0"
3739
healthcheck:
3840
test: ["CMD", "node", "-e", "fetch('http://localhost:3000/documentation').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"]
3941
interval: 10s

generate-env.sh renamed to docker/generate-env.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
ENV_FILE="$(cd "$(dirname "$0")/../.." && pwd)/.env"
4+
ENV_FILE="$(cd "$(dirname "$0")" && pwd)/.env"
55

66
if [ -f "$ENV_FILE" ]; then
77
echo ".env already exists, not overwriting." >&2
@@ -13,7 +13,7 @@ NT_DB_PW=$(openssl rand -base64 24)
1313

1414
cat > "$ENV_FILE" <<EOF
1515
# NicTool API environment configuration
16-
# Generated by dist/setup/generate-env.sh
16+
# Generated by docker/generate-env.sh
1717
1818
# --- Database (MariaDB/MySQL) ---
1919
DB_ROOT_PASSWORD=$DB_ROOT_PW
@@ -22,13 +22,10 @@ NICTOOL_DB_USER=nictool
2222
NICTOOL_DB_USER_PASSWORD=$NT_DB_PW
2323
2424
# --- API config overrides (optional, override conf.d/*.toml defaults) ---
25-
# DB_HOST=127.0.0.1
26-
# DB_PORT=3306
27-
# DB_USER=nictool
28-
# DB_PASSWORD=
29-
# DB_NAME=nictool
30-
# HTTP_HOST=localhost
31-
# HTTP_PORT=3000
25+
# NICTOOL_DB_HOST=127.0.0.1
26+
# NICTOOL_DB_PORT=3306
27+
# NICTOOL_HTTP_HOST=localhost
28+
# NICTOOL_HTTP_PORT=3000
3229
3330
# --- Docker Compose port mapping ---
3431
# DB_PORT=3307

lib/config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class Config {
5151

5252
function applyEnvOverrides(name, cfg) {
5353
if (name === 'mysql') {
54-
if (process.env.DB_HOST) cfg.host = process.env.DB_HOST
55-
if (process.env.DB_PORT) cfg.port = parseInt(process.env.DB_PORT)
56-
if (process.env.DB_USER) cfg.user = process.env.DB_USER
57-
if (process.env.DB_PASSWORD) cfg.password = process.env.DB_PASSWORD
58-
if (process.env.DB_NAME) cfg.database = process.env.DB_NAME
54+
if (process.env.NICTOOL_DB_HOST) cfg.host = process.env.NICTOOL_DB_HOST
55+
if (process.env.NICTOOL_DB_PORT) cfg.port = parseInt(process.env.NICTOOL_DB_PORT)
56+
if (process.env.NICTOOL_DB_USER) cfg.user = process.env.NICTOOL_DB_USER
57+
if (process.env.NICTOOL_DB_USER_PASSWORD) cfg.password = process.env.NICTOOL_DB_USER_PASSWORD
58+
if (process.env.NICTOOL_DB_NAME) cfg.database = process.env.NICTOOL_DB_NAME
5959
}
6060
if (name === 'http') {
61-
if (process.env.HTTP_HOST) cfg.host = process.env.HTTP_HOST
62-
if (process.env.HTTP_PORT) cfg.port = parseInt(process.env.HTTP_PORT)
61+
if (process.env.NICTOOL_HTTP_HOST) cfg.host = process.env.NICTOOL_HTTP_HOST
62+
if (process.env.NICTOOL_HTTP_PORT) cfg.port = parseInt(process.env.NICTOOL_HTTP_PORT)
6363
}
6464
}
6565

lib/config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, it, before, after } from 'node:test'
33

44
import Config from './config.js'
55

6-
const envOverrideKeys = ['DB_HOST', 'DB_PORT', 'DB_USER', 'DB_PASSWORD', 'DB_NAME', 'HTTP_HOST', 'HTTP_PORT']
6+
const envOverrideKeys = ['NICTOOL_DB_HOST', 'NICTOOL_DB_PORT', 'NICTOOL_DB_USER', 'NICTOOL_DB_USER_PASSWORD', 'NICTOOL_DB_NAME', 'NICTOOL_HTTP_HOST', 'NICTOOL_HTTP_PORT']
77

88
describe('config', () => {
99
const savedEnv = {}

0 commit comments

Comments
 (0)