Skip to content

feat: docker compose support + env var config overrides#40

Merged
msimerson merged 6 commits intoNicTool:mainfrom
aberoham:feat/docker-support
Apr 10, 2026
Merged

feat: docker compose support + env var config overrides#40
msimerson merged 6 commits intoNicTool:mainfrom
aberoham:feat/docker-support

Conversation

@aberoham
Copy link
Copy Markdown
Contributor

@aberoham aberoham commented Apr 8, 2026

Matt -- this is my Claw's first crack at #19. The goal was to get from clone to running API in two commands, which worked well once claude and I figured out the mariadb auth dance.

The theme is making the API easy to run locally without touching the existing config files or CI behavior. Everything should be backwards compatible -- if no env vars are set, behavior is identical to today.

The two-command version: ./generate-env.sh && docker compose up --build

That gets you MariaDB 11 + the API on node:22-trixie-slim (Debian Trixie, current stable). generate-env.sh follows the same convention as the NicTool 2 one -- random passwords, safe to re-run.

The config change is the interesting bit -- lib/config.js now checks env vars like DB_HOST, DB_PASSWORD, HTTP_HOST after parsing TOML. The TOML values become defaults that env vars can override. This is what makes docker compose work without maintaining separate config files, but it should also help with any deployment where env vars are easier than editing TOML (k8s, systemd, etc.).

init-mysql.sh needed a few tweaks to work inside the mariadb container -- it picks up MYSQL_ROOT_PASSWORD, prefers the mariadb client over mysql (mariadb 11 dropped the symlink), and uses CREATE DATABASE IF NOT EXISTS so it plays nice with the container's own init. All 339 tests pass in docker.

Two questions for you --

  1. I put the Dockerfile at the project root since that's the standard node convention and the build context is just . -- but NicTool 2 used dist/docker/. Want me to move it?
  2. Env var naming: went with DB_HOST/DB_PASSWORD/HTTP_HOST -- should these be namespaced like NICTOOL_DB_HOST instead?

Let me know if anything needs rework or looks OK to merge as-is.

aberoham and others added 2 commits April 8, 2026 23:13
docker compose up gets the API running against MariaDB 11 on
node:22-trixie-slim. generate-env.sh creates .env with random
passwords, same convention as NicTool 2's generate-env.sh.

config.js now checks env vars (DB_HOST, DB_PASSWORD, HTTP_HOST,
etc.) after parsing TOML -- fully backwards compatible, the TOML
values are just defaults now. config tests save/clear/restore the
env vars so they should pass in both CI and docker.

init-mysql.sh picks up MYSQL_ROOT_PASSWORD when running inside
the mariadb container, prefers the mariadb client over mysql,
and supports DB_USER/DB_NAME/SQL_DIR env vars.

quick start:
  ./generate-env.sh && docker compose up --build

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@msimerson
Copy link
Copy Markdown
Contributor

  1. I have an irrational dislike for stuff polluting the top level of my repos. Dropping it into ./docker/ or similar would be my preference.
  2. namespacing is generally a good practice. Since the vars exist, who knows where else they might get used.

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>
@msimerson
Copy link
Copy Markdown
Contributor

Is this still a Draft?

Adds an optional 'server' service behind the 'ui' and 'e2e'
profiles. Builds from the sibling NicTool/server repo, configurable
via NICTOOL_SERVER_PATH for CI checkouts.

  docker compose --profile ui up --build    # full stack
  docker compose up --build                 # db + api only

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aberoham
Copy link
Copy Markdown
Contributor Author

aberoham commented Apr 9, 2026

i'm knackered, need to test in daylight w/fresh font' of tokens

- NICTOOL_TLS env var controls TLS (defaults to auto, which
  preserves existing cert discovery behavior). Set to false
  in local .env for plain HTTP dev.
- Bind-mount server source (index.js, bin/, html/) so edits
  are live without rebuilding the image
- Port mapping uses SERVER_PORT and SERVER_CONTAINER_PORT
  env vars for flexibility

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aberoham aberoham marked this pull request as ready for review April 10, 2026 19:52
- Validate port env vars (NICTOOL_DB_PORT, NICTOOL_HTTP_PORT) via
  parsePort() — throws on non-numeric or out-of-range values instead
  of silently passing NaN to the connection layer.

- Add comment to Dockerfile explaining why --omit=dev is safe for
  running tests (node:test is stdlib, devDeps are only eslint/prettier).

- Add comment to init-mysql.sh explaining SQL_DIR default behavior
  in Docker vs. bare-metal contexts.

- Add trailing newline to init-mysql.sh.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@msimerson msimerson merged commit e3f4f5b into NicTool:main Apr 10, 2026
9 checks passed
@msimerson msimerson mentioned this pull request Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants