Skip to content

Instantly share code, notes, and snippets.

@c-lliope
Last active April 25, 2018 04:13
Show Gist options
  • Save c-lliope/cad205b2f73c724e42bb091e80dc99fe to your computer and use it in GitHub Desktop.
Save c-lliope/cad205b2f73c724e42bb091e80dc99fe to your computer and use it in GitHub Desktop.
Deploy a `docker-compose` based application to DigitalOcean
#!/bin/bash
# Make sure we're connected to the Docker host
eval $(SHELL=bash docker-machine env)
if hash doctl 2>/dev/null; then
echo "doctl is installed. Continuing."
echo
else
echo "'doctl' is not installed."
echo "Please see https://blog.digitalocean.com/introducing-doctl."
echo
echo "on OS X, try 'brew install doctl'"
exit 1
fi
if hash jq 2>/dev/null; then
echo "jq is installed. Continuing."
echo
else
echo "'jq' is not installed."
echo "Please see https://stedolan.github.io/jq/."
echo
echo "on OS X, try 'brew install jq'"
exit 1
fi
echo "If you do not have a DigitalOcean access key,"
echo "visit https://cloud.digitalocean.com/settings/api/tokens."
echo
doctl auth init
echo "This script is hard-coded to use the first SSH key registered in DigitalOcean."
echo "Out of your SSH keys:"
echo
doctl compute ssh-key list -o json | jq '.[].name'
echo
echo "we will use $(doctl compute ssh-key list -o json | jq '.[0].name')"
echo
echo "Creating droplet with name '$1'"
doctl compute droplet create $1 \
--image docker \
--region sfo2 \
--size s-1vcpu-1gb \
--ssh-keys $(doctl compute ssh-key list -o json | jq -r '.[0].fingerprint') \
--wait
IP=$(doctl compute droplet list -o json | jq -r '.[].networks.v4|.[].ip_address')
doctl compute ssh $1 --ssh-command "ls ~/.ssh/*"
doctl compute ssh $1 --ssh-command "echo '$(cat ~/.ssh/id_rsa.pub)' > ~/.ssh/authorized_keys"
doctl compute ssh $1 --ssh-command "ls ~/.ssh/*"
doctl compute ssh $1 --ssh-command 'git init --bare ridealong.git'
git push $IP:~/ridealong.git
echo "Droplet created with IP '$IP'"
# # Create our app
# heroku apps:create $1
#
# # Set production environment variables
# heroku config:set --app $1 \
# RAILS_ENV=production \
# NODE_ENV=production \
# RAILS_SERVE_STATIC_FILES=true \
# PASSWORD=foobar \
# SECRET_KEY_BASE=$(docker-compose run --rm web rake secret)
#
# # Add a `postgres` database through Heroku Addons
# heroku addons:create heroku-postgresql:hobby-dev --app $1
#
# # Build and publish the app as a `web` dyno
# heroku container:push web --app $1
#
# # Start the database
# heroku run --app $1 -- rake db:migrate
# heroku run --app $1 -- rake db:seed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment