Deploy to DigitalOcean with Terraform
Pre-requisites
Setup
Download Mage maintained Terraform scripts.
Terraform plan
You can run the following command to see all the resources that will be created by Terraform:
1. Configure access token
Generate DigitalOcean access token by following the guide: https://developer.hashicorp.com/terraform/tutorials/applications/digitalocean-provider#generate-digitalocean-access-token
Set the token in DIGITALOCEAN_ACCESS_TOKEN
environment variable
2. Create ssh key
Create ssh key with command: ssh-keygen
. In the file
./digitalocean/variables.tf, update the value of ssh_pub_key
to your path of public key.
3. Customize Terraform settings
Application name (optional)
In the file ./digitalocean/variables.tf, you can change the default application name that will appear in DigitalOcean:
Region (optional)
In the file ./digitalocean/variables.tf, you can change the region:
More
Other variables defined in ./digitalocean/variables.tf can also be customized to your needs.
4. Provision resources
Using CLI
- Change directory into scripts folder:
- Initialize Terraform:
- Deploy:
Once it’s finished deploying, you can get the IP from the output.
5. Run app in the provisioned Droplet
SSH into the instance: ssh -i [path_to_private_key] root@[ip]
Run command to start Mage app in :
To update Mage to latest version, you can pull latest docker image with command:
Then, just restart the Mage app with the same docker run
command above.
6. Open browser with Mage
Once you’ve launched the Droplet and started Mage, you can access Mage from your web browser by entering the following:
http://[ip]:[port]
Change the IP to match the IP of your Droplet and the port that you’re using for Mage.
Misc
Terminate all resources
If you want to delete all resources created from deploying, run the following command:
A sample output could look like this: