TL;DR
Use serverzie setup to auto configure your project.
Continue if you’d like to understand the steps in more detail and customize the setup further.
Prerequisites
- You need Docker installed on your machine to follow this guide, if it isn’t installed yet, follow the Docker installation guide to set it up for your computer.
- You need serverize account, if you don’t have one, follow the serverize sign up guide.
Project Structure
Once you’ve finished adding the required files, your project should look like this:
Adding a Dockerfile
To put your Deno project in a container, you need to create a Dockerfile in your project’s main folder. This file tells Docker how to build and run your app.
In the root of your project, create a file named Dockerfile
and add the following content:
It consists of four stages
-
base: This stage creates a base image for all subsequent stages and sets the working directory to
/app
. -
deps: Install dependencies to be compiled later.
-
builder: Compiles the source code and outputs it as an executable.
-
start:
- Copies the compiled executable from the
builder
stage. - Sets the user to
deno
to ensure the app runs as a non-root user for better security. - Exposes port
3000
. - Runs the executable which starts the server.
- Copies the compiled executable from the
Dockerignore
To make your Docker build faster, create a .dockerignore
file to tell Docker which files to ignore in order to reduce the size of the image and speeds up the build process and deployment process.
Create a .dockerignore
file in the root of your project and add the following content:
This list excludes directories like node_modules
, which can be quite large, as well as other files like .git
, .env
, and configuration files that aren’t needed within the Docker container or might contain sensitive information.
Note
The smaller the image size, the quicker the deployment; only transfer the bare minimum of files to the final stage.
Deploy Your Project
After completing all the previous steps, you are now ready to deploy your application to Serverize.
Replace <project-name>
with the actual name of your project. This command will package and deploy your application, leveraging Serverize to handle the setup and deployment seamlessly.
Automating Deployments with CI/CD
You can automate the deployment of your application to Serverize by using Continuous Integration and Continuous Deployment (CI/CD) tools like GitHub Actions. This setup ensures that your application is deployed whenever new code is pushed to the main branch.
For detailed instructions on configuring CI/CD with Serverize and GitHub Actions, refer to our CI/CD guide.
Takeaways
- Make sure to expose the correct port in your Dockerfile.
- The
CMD
command in your Dockerfile should start your application.
Happy deploying! If you run into any issues or need further assistance, feel free to drop a message in our Discord community.