Dev CLI (experimental)
Jamsocket also provides an experimental dev CLI that can make developing session backend code much easier by
- automatically rebuilding session backend docker images and pushing to Jamsocket, and
- running a local proxy server for spawn requests to manage backends that were spawned during development.
The dev command (npx jamsocket dev
) must be run in a directory with a jamsocket.config.js
file which should look something like this:
module.exports = {
dockerfile: './src/session-backend/Dockerfile',
service: 'my-service-dev',
watch: ['./src/session-backend'],
}
Here's what each of the properties mean:
dockerfile
- this is the path to the Dockerfile that builds your session backend code.service
- this is the name of the Jamsocket service that your session backend code should be pushed to. (You can create a service withnpx jamsocket service create [YOUR SERVICE NAME]
or at app.jamsocket.com.)watch
- this is an array of paths to watch for changes for automatically building / pushing your session backend.
In other words, the dev CLI will watch the paths listed in the watch
array, then rebuild the Dockerfile defined by the dockerfile
path, and finally push the resulting image to the Jamsocket service defined by the service
property.
When using the dev CLI, you should make spawn requests to http://localhost:8080 instead of hitting the Jamsocket API directly.
The dev CLI keeps track of which backends were spawned during development. When you make a change to your session backend code, a new docker image will be built and pushed to Jamsocket, and any backends running a previous version of the code will be terminated. When a new backend is spawned, the CLI will automatically stream its backend statuses and logs to the terminal. And when you stop the dev CLI, all backends spawned during the development session will be terminated.
Example
Given a config that looks like this:
module.exports = {
dockerfile: './src/session-backend/Dockerfile',
service: 'my-service-dev',
watch: ['./src/session-backend'],
}
And a Dockerfile that looks like this:
When you run the dev CLI command, like so...
The Dockerfile (at src/session-backend/Dockerfile
) will be built and pushed to your Jamsocket service named my-service-dev
.
Then, when you spawn a session backend with a request like this, ...
You'll get back a URL that might look like https://ab123.jamsocket.run
. Requests sent to this URL will be routed to your session backend, as long as it has a server listening on port 8080. (You can see an example Dockerfile and NodeJS server in the Hello World Tutorial.)