nft.storage
nft.storage copied to clipboard
refactor run-with-dependencies shell script & fold into cli.js
As part of the epic journey that was #2065, I ended up adding a shell script called run-with-dependencies.sh
to bring the docker compose environment up and down, and a run-test.sh
script to kick off the test suite. I used shell scripts because they were easy to get going with as I was trying to figure out if testcontainers was the cause of a show-stopping issue, and we merged them in to avoid that PR branch going stale. This issue is to track replacing them with a JS solution for better maintainability and consistency.
The run-with-dependencies
script is essentially doing the same thing as services start
and services stop
, except that it will run an arbitrary command in between, and export some config variables to point to the right service ports. I really like the "with dependencies" pattern, since it ensures that things always get cleaned up even if things exit abnormally. But I think it may make more sense as a flag, e.g. --with-services
, or something.
So, my tentative plan is:
- [ ] add new
run-dev
andrun-test
subcommands to the cli, to setup and run the dev server and ava, respectively.- These can either use
execa
+ the command line tools, or use the Miniflare / Ava JS APIs.
- These can either use
- [ ] give those new commands a
--with-services
flag, which causes them to be sandwiched between docker composeup
anddown
calls (usingexeca
)- this also causes the
DATABASE_URL
and other port-dependent config vars to be overridden and made available to therun-dev
/run-test
commands, so they can use the dynamic values instead of whatever is in.env
- this also causes the
- [ ] also add a
--persist
flag, to enable persistent data volumes.
This seems like a pretty flexible solution - you can run dev and test either with or without an automatic environment, so if you have a custom set of volumes for debugging or something, you can set that up manually and run cli.js run-dev
without the --with-services
flag. But the npm scripts would include the flag, so by default everything is nicely automatic and isolated.
Anyone with ideas for improvement or a better plan for hooking this up should please chime in!