-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command to start a local container #491
Conversation
4d21108
to
5e67319
Compare
17e72ec
to
7ab0dbc
Compare
ca659cf
to
6b8e3f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking sharp.
I still want the ability to push a schema to a database (creating it if it doesn't already exist), but this is slick by itself too.
@@ -79,7 +80,7 @@ | |||
"pretest:ci": "npm run build:app", | |||
"test:ci": "mocha --forbid-only --recursive ./test --require ./test/mocha-root-hooks.mjs --reporter mocha-multi-reporters --reporter-options configFile=./test/config/reporter.json", | |||
"build": "npm run build:app && npm run build:sea", | |||
"build:app": "esbuild --bundle ./src/user-entrypoint.mjs --platform=node --outfile=./dist/cli.cjs --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=importMetaUrl --define:process.env.NODE_ENV=\\\"production\\\"", | |||
"build:app": "esbuild --loader:.node=file --bundle ./src/user-entrypoint.mjs --platform=node --outfile=./dist/cli.cjs --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=importMetaUrl --define:process.env.NODE_ENV=\\\"production\\\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr: What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some node modules like low level crypto libraries esbuild does not bundle by default. This instructs esbuild to do so by copying the files it needs into the bundle.
containerPort, | ||
}); | ||
logger.stderr( | ||
`[StartContainer] Container '${containerName}' started. Monitoring HealthCheck for readiness.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, we could update colorize
(and codeToAnsi
) to support colorizing logs in a couple lines:
https://textmate-grammars-themes.netlify.app/?theme=github-dark-high-contrast&grammar=log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea.
src/commands/local.mjs
Outdated
image: { | ||
describe: "The image to run locally", | ||
type: "string", | ||
default: "fauna/faunadb:latest", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this customizable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably doesn't need to be. I put it in case someone wanted to use the "nightly" container build. But taht seems like an internal concern not appropriate for this tooling.
There are specific versions published: https://hub.docker.com/r/fauna/faunadb/tags
So i could see a case for having the tag be mutable for debugging. So you'd take a --tag argument instead. But we could also just drop it and always do latest which seems more appropriate for a web service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this flag.
type: "boolean", | ||
default: true, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this in a future PR, but I really love to see FSL directory flag and a database name flag that this command creates and pushes into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good idea for starting up dev and test environments.
it("Creates and starts a container when none exists", async () => { | ||
docker.pull.onCall(0).resolves(); | ||
docker.modem.followProgress.callsFake((stream, onFinished) => { | ||
onFinished(); | ||
}); | ||
docker.listContainers.onCall(0).resolves([]); | ||
fetch.onCall(0).resolves(f({})); // fast succeed the health check | ||
logsStub.callsFake(async () => ({ | ||
on: () => {}, | ||
destroy: () => {}, | ||
})); | ||
docker.createContainer.resolves({ | ||
start: startStub, | ||
logs: logsStub, | ||
unpause: unpauseStub, | ||
}); | ||
await run("local", container); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool tests :)
default: "8443", | ||
}, | ||
name: { | ||
describe: "The name to give the container", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe: "The name to give the container", | |
describe: "The name to give the container.", |
/** | ||
* Ensures the container is running | ||
* @param {string} imageName The name of the image to create the container from | ||
* @param {string} containerName The name of the container to start | ||
* @param {number} hostPort The port on the host machine mapped to the container's port | ||
* @param {number} containerPort The port inside the container Fauna listens on | ||
* @param {boolean} pull Whether to pull the latest image | ||
* @returns {Promise<void>} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love the JSDoc annotations, they're really polished / helpful
logger.stderr( | ||
`[ContainerReady] Container '${containerName}' is up and healthy.`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for this PR, but this is probably a good fit for one of the verbosity level loggers (logger.debug/info/warn/error/fatal
). maybe we put it on info and change the default log level to include info? going through the verbosity loggers gives users easier / better sifting (b/c you give it a component and a log level, and they can use those to filter in/out sets of logs).
Co-authored-by: echo-bravo-yahoo <[email protected]>
Ticket(s): FE-5990
Problem
Fauna's docker container gives users an easy way to implement a reliable inner loop development cycle. It makes it easy for them to develop schemas and programs against Fauna locally, without incurring any service costs.
Our support for the container in tooling is absent. User's have to find it and build scripts to fire it up.
Solution
Take a first step to making the container more prevalent in the tooling by making a CLI command to start the container.
Result
You can start a local Fauna with
fauna local
Testing
Ran the tests. Notice how I added a bunch for the container.
Out of Scope
I need to add tests for different argv inputs, including incorrect inputs. I've put a generic skipped test to flag that for now.