? 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