Skip to content

Instantly share code, notes, and snippets.

Last active June 3, 2020 09:13
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# Assumes you have a DIGITALOCEAN_TOKEN env var pre-set
# Assumes you have terraform and mutagen installed
# Assumes DO has an SSH key uploaded
DO_REGION="sgp1" # Set to DO region:
SSH_KEY_FINGERPRINT="your-key-fingerprint" # You can find this in your control panel
if [ -z $DIGITALOCEAN_TOKEN ]; then
exit 1
cat <<EOF >
provider "digitalocean" {}
resource "digitalocean_droplet" "web" {
image = "ubuntu-20-04-x64"
name = "dev"
region = "$DO_REGION"
size = "s-1vcpu-1gb"
ssh_keys = ["$SSH_KEY_FINGERPRINT"]
output "ip_addr" {
value = digitalocean_droplet.web.ipv4_address
terraform init
terraform apply -auto-approve
export REMOTE_IP_ADDR=`terraform output | ruby -e "puts"`
sleep 5 # give DO enough time to come up
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@$REMOTE_IP_ADDR <<'ENDSSH'
apt install --yes make ruby ruby-dev build-essential
gem install bundler
bundle config set path 'vendor/bundle'
mutagen sync create --sync-mode=one-way-safe --name=devproj-code . root@$REMOTE_IP_ADDR:~/
mutagen sync flush devproj-code
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@$REMOTE_IP_ADDR "bundle install"
echo "Dev box ready: ssh root@$REMOTE_IP_ADDR"
# next line only works once the remote service is actually up
# mutagen forward create --name=devproj tcp:localhost:9292 root@$REMOTE_IP_ADDR:tcp:localhost:9292
# TODO: up/down/console/forward/run commands
# TODO: Vultr + other cloud provider support
# Down with:
# mutagen sync terminate -a && terraform destroy -auto-approve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment