Preparation
If you want to deploy to Docker without using CDK, the first step is to ensure the handler
export is removed from the backend/index.ts
file. Our projects add a line in that looks like this:
// Remove this line!
export const handler = graphweaver.handler();
This is what tells Graphweaver to use Lambda as the deployment target.
Once you’ve removed that line, you’ll be running in Fastify, both locally and when you build.
Dockerfile
Running graphweaver build
will produce dist/backend/index.js
, which you can run directly with node
. For example:
Dockerfile
# Use the official Node.js image as the base
FROM node:20
# Set the working directory within the container
WORKDIR /usr/src/app
# Copy the application code from the specified directory
COPY ./ ./
# Expose the port your app will run on (e.g., 9001)
EXPOSE 9001
# Run the application (replace with your actual command)
CMD ["node", "index.js"]
Health Check
It is common to need a Health Check. Once you’re running in Fastify mode (e.g. you’ve completed the step in ), a health check is available at /health
which will return status 200 with a body of:
{"status":"ok"}
Troubleshooting
If you’re having a health-check failure on deploy, steps to take to rule things out:
pnpm start
, then open http://localhost:9001/health in a browser.- If you see
{"status":"ok"}
, kill the server with Ctrl-C and proceed to step 2. We have proven that your Graphweaver instance is running in Fastify mode. - If you don’t, ensure you have completed the step above.
- Change directories to
dist/backend
pnpm build
, thenLOGGING_LEVEL=trace node index.js
, finally open http://localhost:9001/health in a browser.- If you see
{"status":"ok"}
, kill the server with Ctrl-C and proceed to step 3. We have proven your builtindex.js
file is ready to go into the Docker container. - If you don’t, check for errors in the output from the node command. They should shed some light on what’s going on.
- Create the example in your current directory
dist/backend
. - Build a container from the Dockerfile with
docker build --tag 'graphweaver_test' .
- Run it with
docker run 'graphweaver_test'
- Open http://localhost:9001/health in a browser.
- If you see
{"status":"ok"}
, we have proven that your built container works. At this stage all that can be wrong is how it’s getting deployed to your hosting provider, or the configuration on that side. - If you don’t, check for errors in the docker run command tab. They should shed some light on what’s going on.