diff --git a/images/createImage b/images/createImage index e7e476f71..ec76b96a4 100755 --- a/images/createImage +++ b/images/createImage @@ -89,16 +89,14 @@ if [[ -z "${box_name}" ]]; then box_name="box-${deploy_env}-${pretty_revision}-${now}" # remove slashes # create a new server if no name given - caas_ssh_key_id=$($vps get_ssh_key_id "caas") - if [[ -z "${caas_ssh_key_id}" ]]; then + if ! caas_ssh_key_id=$($vps get_ssh_key_id "caas"); then echo "Could not query caas ssh key" exit 1 fi echo "Detected caas ssh key id: ${caas_ssh_key_id}" echo "Creating Server with name [${box_name}]" - server_id=$($vps create ${caas_ssh_key_id} ${box_name}) - if [[ -z "${server_id}" ]]; then + if ! server_id=$($vps create ${caas_ssh_key_id} ${box_name}); then echo "Failed to create server" exit 1 fi @@ -112,7 +110,10 @@ if [[ -z "${box_name}" ]]; then done echo "" else - server_id=$($vps get_id "${box_name}") + if ! server_id=$($vps get_id "${box_name}"); then + echo "Could not determine id from name" + exit 1 + fi echo "Reusing server with id: ${server_id}" $vps power_on "${server_id}" @@ -121,8 +122,7 @@ fi # Query until we get an IP while true; do echo "Trying to get the server IP" - server_ip=$($vps get_ip "${server_id}") - if [[ "${server_ip}" != "" ]]; then + if server_ip=$($vps get_ip "${server_id}"); then echo "Server IP : [${server_ip}]" break fi @@ -166,18 +166,30 @@ echo "Waiting for 10 seconds for server to shutdown" sleep 30 echo "Powering off server" -$vps power_off "${server_id}" +if ! $vps power_off "${server_id}"; then + echo "Could not power off server" + exit 1 +fi snapshot_name="box-${deploy_env}-${pretty_revision}-${now}" echo "Snapshotting as ${snapshot_name}" -$vps snapshot "${server_id}" "${snapshot_name}" +if ! $vps snapshot "${server_id}" "${snapshot_name}"; then + echo "Could not snapshot" + exit 1 +fi -image_id=$($vps get_image_id "${snapshot_name}") +if ! image_id=$($vps get_image_id "${snapshot_name}"); then + echo "Could not get image id" + exit 1 +fi echo "Image id is ${image_id}" if [[ "${destroy_server}" == "yes" ]]; then echo "Destroying server" - $vps destroy "${server_id}" + if ! $vps destroy "${server_id}"; then + echo "Could not destroy server" + exit 1 + fi else echo "Skipping server destroy" fi diff --git a/images/digitalocean.sh b/images/digitalocean.sh index 27a19b3b1..9ce1b7938 100755 --- a/images/digitalocean.sh +++ b/images/digitalocean.sh @@ -17,10 +17,12 @@ function debug() { } function get_ssh_key_id() { - $CURL "https://api.digitalocean.com/v2/account/keys" \ + id=$($CURL "https://api.digitalocean.com/v2/account/keys" \ | $JSON ssh_keys \ | $JSON -c "this.name === \"$1\"" \ - | $JSON 0.id + | $JSON 0.id) + [[ -z "$id" ]] && exit 1 + echo "$id" } function create_droplet() { @@ -33,17 +35,23 @@ function create_droplet() { local data="{\"name\":\"${box_name}\",\"size\":\"${box_size}\",\"region\":\"${image_region}\",\"image\":\"${ubuntu_image_slug}\",\"ssh_keys\":[ \"${ssh_key_id}\" ],\"backups\":false}" - $CURL -X POST -H 'Content-Type: application/json' -d "${data}" "https://api.digitalocean.com/v2/droplets" | $JSON droplet.id + id=$($CURL -X POST -H 'Content-Type: application/json' -d "${data}" "https://api.digitalocean.com/v2/droplets" | $JSON droplet.id) + [[ -z "$id" ]] && exit 1 + echo "$id" } function get_droplet_ip() { local droplet_id="$1" - $CURL "https://api.digitalocean.com/v2/droplets/${droplet_id}" | $JSON "droplet.networks.v4[0].ip_address" + ip=$($CURL "https://api.digitalocean.com/v2/droplets/${droplet_id}" | $JSON "droplet.networks.v4[0].ip_address") + [[ -z "$ip" ]] && exit 1 + echo "$ip" } function get_droplet_id() { local droplet_name="$1" - $CURL "https://api.digitalocean.com/v2/droplets?per_page=100" | $JSON "droplets" | $JSON -c "this.name === '${droplet_name}'" | $JSON "[0].id" + id=$($CURL "https://api.digitalocean.com/v2/droplets?per_page=100" | $JSON "droplets" | $JSON -c "this.name === '${droplet_name}'" | $JSON "[0].id") + [[ -z "$id" ]] && exit 1 + echo "$id" } function power_off_droplet() { diff --git a/images/vultr.js b/images/vultr.js index c15c7727e..46bf953c0 100755 --- a/images/vultr.js +++ b/images/vultr.js @@ -38,7 +38,7 @@ function getSshKeyId(keyName, callback) { function create(keyId, name, callback) { var regionId = 5; // LA (https://api.vultr.com/v1/regions/list) var planId = 29; // 768MB RAM (https://api.vultr.com/v1/regions/list) - var osid = 191; // Ubuntu 15.04 x64 (see https://api.vultr.com/v1/os/list) + var osid = 191; // Ubuntu 15.04 x64 (see https://api.vultr.com/v1/os/list). 15.04 has some systemd issue var res = request.post('https://api.vultr.com/v1/server/create') .query({ api_key : gApiToken }) @@ -51,9 +51,7 @@ function create(keyId, name, callback) { return callback(null, res.body.SUBID); } -function getIp(id, callback){ - console.error('getting the ip of ', id); - +function getIp(id, callback) { var res = request.get('https://api.vultr.com/v1/server/list') .query({ api_key : gApiToken, SUBID: id }) .end();