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:
cd
terraform plan
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:
variable "app_name" {
type = string
description = "Application Name"
default = "mage-data-prep"
}
Region (optional)
In the file ./digitalocean/variables.tf, you can change the region:
variable "region" {
type = string
description = "Region of the datacenters"
default = "sfo3"
}
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:
cd digitalocean
- Initialize Terraform:
terraform init
- Deploy:
terraform apply
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 :
docker run -d -p 6789:6789 -v $(pwd):/home/src mageai/mageai /app/run_app.sh mage start default_repo
To update Mage to latest version, you can pull latest docker image with command:
docker pull mageai/mageai:latest
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:
terraform destroy
A sample output could look like this:
Destroy complete! Resources: 10 destroyed.