-
-
Save andragabr/6451c92ba84d8afe039be7b1b4f9c4c3 to your computer and use it in GitHub Desktop.
Revisions
-
jpospychala renamed this gist
Dec 11, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jpospychala created this gist
Dec 11, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ # this script expects $DOTOKEN variable with your digital ocean token # this script gets or creates smallest DO droplet and remotely executes script on it # afterwards, droplet is destroyed DROPLETNAME=example.com DOHOME="https://api.digitalocean.com/v2" cat <<EOF > .curlargs -s -H "Authorization: Bearer $DOTOKEN" -H "Content-Type: application/json" EOF CURL="curl -K .curlargs" SSHKEYS=`$CURL "$DOHOME/account/keys" | R path ssh_keys | R map path fingerprint` CREATECONTAINER=`cat <<EOF { "name":"$DROPLETNAME", "region":"nyc3", "size":"512mb", "image":"ubuntu-14-04-x64", "ssh_keys":$SSHKEYS} EOF` echo $SSHKEYS function GET_DROPLET { DROPLET=`$CURL "$DOHOME/droplets/" | \ R path droplets | \ R find where "{\"name\": \"$DROPLETNAME\"}"` export IP=`R path networks.v4.0.ip_address <<< $DROPLET` export ID=`R path id <<< $DROPLET` echo "dropet id: $ID ip: $IP" } GET_DROPLET if [ -z "$ID" ]; then echo create droplet! $CURL -X POST -d "$CREATECONTAINER" "$DOHOME/droplets/" while [ -z "$IP" ]; do GET_DROPLET done fi # execute ssh "root@$IP" 'bash -s' < run.sh # delete droplet $CURL -X DELETE "$DOHOME/droplets/$ID" rm .curlargs