Part 5 of 10
Set Up a Deployment Environment on DigitalOcean
Install VS Code and Elements, build a todos app by asking an AI agent, and deploy the app to DigitalOcean. Then tour the project environment, the elements command, the website and the business.
- 1. Introduction 0:18
- 2. Install VS Code 3:30
- 3. Install Elements 1:27
- 4. Create Your First App 5:26
- 5. Set Up a Deployment Environment on DigitalOcean 4:49
- 6. Deploy Your App 3:11
- 7. The Project Environment 2:32
- 8. The Elements Tooling 6:07
- 9. The Elements Website and Community 2:48
- 10. The Elements Business 1:27
In this video we draw what a deployment looks like, then create a DigitalOcean droplet to run the app and a managed Postgres cluster for its data, and copy the details the agent needs to deploy. ## What a deployment is You write and build the app on your laptop, and you control the deployment from there too. The app runs on a virtual private server. We use DigitalOcean, where a server is called a droplet: a virtual machine running Ubuntu Linux. Amazon and other providers work too. Elements deploys to any Ubuntu server you reach over SSH. - **A prototype** needs your laptop and one droplet. Elements installs Postgres on that machine and creates the app's databases there. - **A business app**, or one that will add app servers, keeps its data in one database the servers share. That can be a Postgres machine you run yourself, or a managed provider such as DigitalOcean's Managed Postgres, which is what we use here. DigitalOcean charges monthly for each droplet and for the database. See [DigitalOcean's pricing](https://www.digitalocean.com/pricing) for the current rates. Start with one app server. Add a second for redundancy, so one picks up the load if the other fails, and add more when you have many users. Elements balances the load across the app servers automatically: create a droplet, tell the agent about it, and the agent configures Elements. If you have a domain name, give it to the agent too. Elements sets up the HTTPS certificates and keeps the app servers working together. ### 1. Create a droplet Create a [DigitalOcean](https://www.digitalocean.com) account if you don't have one. On your home page, click **Create** and choose **Droplets**. - **Region:** the default data center, or one you prefer. - **Image:** Ubuntu, the latest version. - **Size:** the default type. It defaults to 2 CPUs and 4 GB of memory; 1 CPU and 2 GB also work. - **Storage:** the default. - **SSH key:** click **Add SSH Key** and follow the instructions, or select a key you already have. - **Networking:** make sure the public IPv4 address is turned on. The app server faces the public internet. Leave the rest and click **Create Droplet**. ### 2. Note the droplet's IP addresses The droplet takes a minute or two, and its connection details a few seconds more. The panel shows a public IPv4 address and a private IP address. The agent needs both to set up the deployment. ### 3. Create a managed Postgres cluster Click **Create** at the top again and choose the managed database. - **Engine:** PostgreSQL, the latest version. - **Plan:** Standard edition. - **Storage:** the default. Leave the other defaults and click to create the database cluster. It takes longer than the droplet. ### 4. Copy the connection details When the cluster is ready, scroll down to the **Connection details** panel and click its copy button. Paste them into the agent with the droplet's IP addresses, and the agent sets Elements up to use the new database cluster.
Let me give you a quick visualization of deployment in Elements. You're going to start off on your laptop where you're writing the code and you're building the todos application like we just were doing. And you're going to control the deployment from your laptop. To do that, we need to get a machine running on a virtual private server, a machine running somewhere. And we're going to use DigitalOcean or DO for that. You can use Amazon, you can use a bunch of other providers that are out there. But DigitalOcean, I find, is a good way to get started if you're not sure. DigitalOcean has something called a droplet. And a droplet is essentially just a virtual machine.
And we're going to have one droplet that gives us an Ubuntu Linux machine. And that's where we're going to put our application. Now, when you're starting off, if you're just prototyping, you just have your laptop, and you're going to have one deployment machine. And that's all you're going to need, because Elements automatically puts a Postgres database cluster onto the app machine itself. But if you're running a business, or it's a real application, or you're going to add additional app servers over time, and we'll talk about why you might want to do that, you're going to want to have a managed database instance. And DigitalOcean provides that for us automatically, managed Postgres, but there are many providers out there that do it as well.
Now, a typical cost, this can change over time, but as of today, to get a droplet will cost roughly between $6 and $12. So we'll say $6 for one, $12 if you have two, and then the managed database will be something in the order of $15 per month. And this gives you a sense of what a deployment environment will cost. You can start off with one app server, like I said, but if you need redundancy, for example, if one fails for some reason, you want another one to pick up the load, you can add two. If you have lots of users, let's say 50,000 or more users, you might consider having another app server to distribute the load amongst your users.
So the browser will alternate between going to this server and this server so that the load gets distributed more easily. Now, load balancing in Elements is handled automatically. You don't have to worry about it at all. You just create new droplets and tell your agent about it, and it will configure Elements properly, and everything that needs to happen will happen. Also, if you have a domain name or a URL, you can also give that to your agent, and it will automatically handle SSL certificates and make sure that all of the application servers are working together. So all you need to do is to create new DigitalOcean droplets or using whatever service you want, tell Elements about it through your agent and everything should happen automatically.
Okay, with that said, let's get on with it and create a DigitalOcean droplet and managed Postgres. If you haven't created a DigitalOcean account yet, go ahead and do that. And once you're in your homepage area, click the create button and start off by creating a droplet. You can use the default data center that is selected or change it if you would like. For an image, choose Ubuntu and the latest version. For configuration type, you can leave the default. CPU size defaults to 2, but you can also get away with using 1, and for memory you can leave 4, but again you can get away with 2 if you want. Storage is fine at the default. If you haven't created an SSH key yet, go ahead and click the Add SSH Key button and follow the instructions.
Otherwise, select the SSH key that you already have. Now, this is important for networking. Make sure that the IPv4 public address is checked, that that is on, because this is going to be a public internet-facing application server. The rest you can leave alone, and press Create Droplet. It might take a minute or two to create the droplet and another couple of seconds for these connection details to appear, but at the end of this process, you should see a panel with a public IPv4 address and private IP address, and you'll need both of these to give to your agent to set up the deployment. Before we leave DigitalOcean, go up to the top Create button again and go to Managed Database, and we'll create our Postgres instance while we're here.
Select the Postgres application. The latest version is fine. Standard edition, the Kansas data center, and all of the defaults should be fine. It looks like there was a slight price increase, so $20.30 per month, and the storage size is fine. All of the defaults you can leave alone. And when you're done with that, create the database cluster. This process will take a little bit longer than it takes to create a droplet. Wait for it to complete, and you should see connection details in a panel that we can use to then give to our agent and set up deployment. Once that process completes, you can scroll down a little bit, and you're going to see a panel here called Connection Details with a copy button.
Click that copy button. We're going to paste these back into our agent, and it will get Elements set up to use this new database cluster.
Add a comment