docs/go/self-host/deploy-to-digital-ocean-wip.md
If you prefer manual deployment over the automation offered by Encore's Platform, Encore simplifies the process of deploying your app to the cloud provider of your choice. This guide will walk you through deploying an Encore app to DigitalOcean's App Platform using Docker.
Create a New Encore App:
encore app create myapp
Hello World template.Build a Docker image:
encore build docker myapp
To deploy your Docker image to DigitalOcean, you need to push it to a container registry. DigitalOcean supports its own container registry, but you can also use DockerHub or other registries. Here’s how to push the image to DigitalOcean’s registry:
Create a DigitalOcean Container Registry:
Login to DigitalOcean's registry: Use the login command provided by DigitalOcean, which will look something like this:
doctl registry login
You’ll need the DigitalOcean CLI for this, which can be installed from DigitalOcean CLI documentation.
Tag your Docker image: Tag your image to match the registry’s URL.
docker tag myapp registry.digitalocean.com/YOUR_REGISTRY_NAME/myapp:latest
Push your Docker image to the registry:
docker push registry.digitalocean.com/YOUR_REGISTRY_NAME/myapp:latest
Navigate to the App Platform: Go to DigitalOcean's App Platform.
Create a New App:
Select the Docker Image Source:
Configure the App Settings:
Deploy the App:
Access the Application:
curl https://myapp.ondigitalocean.app/hello/world
View Logs and Metrics:
Manage Scaling and Deployment Settings:
DigitalOcean’s App Platform provides managed databases, allowing you to add a database to your app easily. Here’s how to set up a managed database for your app:
Navigate to the DigitalOcean Control Panel:
Create a New Database Cluster:
Configure the Database Settings:
Create a Database
psql -h mydb.db.ondigitalocean.com -U doadmin -d mydb -p 25060
CREATE DATABASE mydb;
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(50)
);
INSERT INTO users (name) VALUES ('Alice');
Declare a Database in your Encore app:
mydb database to your app (Encore Database Documentation) const mydb = new SQLDatabase("mydb", {
migrations: "./migrations",
});
export const getUser = api(
{ expose: true, method: "GET", path: "/names/:id" },
async ({id}: {id:number}): Promise<{ id: number; name: string }> => {
return await mydb.queryRow`SELECT * FROM users WHERE id = ${id}` as { id: number; name: string };
}
);
Create an Encore Infrastructure config
infra.config.json in the root of your Encore app.{
"$schema": "https://encore.dev/schemas/infra.schema.json",
"sql_servers": [
{
"host": "mydb.db.ondigitalocean.com:25060",
"tls_config": {
"ca": "-----BEGIN CERTIFICATE-----\n..."
},
"databases": {
"mydb": {
"username": "doadmin",
"password": {"$env": "DB_PASSWORD"}
}
}
}]
}
Set Up Environment Variables (Optional):
DB_PASSWORD.Build and push the Docker image:
encore build docker --config infra.config.json myapp
docker tag myapp registry.digitalocean.com/YOUR_REGISTRY_NAME/myapp:latest
docker push registry.digitalocean.com/YOUR_REGISTRY_NAME/myapp:latest
Test the Database Connection:
curl https://myapp.ondigitalocean.app/names/1
That’s it! You’ve successfully deployed an Encore app to DigitalOcean’s App Platform using Docker. You can now scale your app, monitor its performance, and manage it easily through the DigitalOcean dashboard. If you encounter any issues, refer to the DigitalOcean documentation or the Encore community for help. Happy coding!