? This guide shows you how to deploy an Encore application to DigitalOcean using the new encore build command, part of Encore's open source CLI.
This is handy if you prefer manual deployment over the automation offered by Encore's Cloud Platform.
Even when deploying manually, Encore simplifies the process by providing tools to build and configure your app.⚡️
Now let's take a look at how to deploy an Encore app to DigitalOcean's App Platform using Docker and encore build.?
Create a New Encore App:
encore app create myapp
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.
docker tag myapp registry.digitalocean.com/YOUR_REGISTRY_NAME/myapp:latest
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:
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 a table ```sql CREATE TABLE users ( id SERIAL PRIMARY KEY, name VARCHAR(50) ); INSERT INTO users (name) VALUES ('Alice');
const mydb = new SQLDatabase("mydb", { migrations: "./migrations", }); export const getUser = api( { expose: true, method: "GET", path: "/names/:id" }, async ({id}: {id:number}): Promise => { return await mydb.queryRow`SELECT * FROM users WHERE id = ${id}` as { id: number; name: string }; } );
{ "$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):
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
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.
免責事項: 提供されるすべてのリソースの一部はインターネットからのものです。お客様の著作権またはその他の権利および利益の侵害がある場合は、詳細な理由を説明し、著作権または権利および利益の証拠を提出して、電子メール [email protected] に送信してください。 できるだけ早く対応させていただきます。
Copyright© 2022 湘ICP备2022001581号-3