From 8492b7cf3ded4e646879ab55261e78e739b311b2 Mon Sep 17 00:00:00 2001 From: Dan Head Date: Mon, 16 Apr 2018 13:30:01 +0100 Subject: [PATCH] Move deploy script to bash --- .circleci/config.yml | 3 +-- deploy.sh | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 deploy.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 70a927d..eb0e687 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,5 +8,4 @@ jobs: - run: sudo apt install -y rsync - run: npm install - run: npm run build - - run: rsync -avzu --progress -h theme $SSH_USER@$SSH_IP:~/windycoys_theme - + - run: bash deploy.sh diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..8d997e2 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Test rsync is installed and ENV variables are set +hash rsync 2>/dev/null || { echo >&2 "Error: rsync is not installed. Aborting."; exit 1; } +[ -z "$SSH_IP" ] && { echo >&2 "Error: SSH_IP is missing. Aborting."; exit 1; } +[ -z "$SSH_USER" ] && { echo >&2 "Error: SSH_USER is missing. Aborting."; exit 1; } + +# Deploy theme with rsync +rsync -e "ssh -o StrictHostKeyChecking=no" -avzuh --progress \ + theme $SSH_USER@$SSH_IP:~/windycoys_theme + +#Test curl is installed and Cloudflare ENV variables are set +hash curl 2>/dev/null || { echo >&2 "Error: curl is not installed. Aborting."; exit 1; } +[ -z "$CLOUDFLARE_API_KEY" ] && { echo >&2 "Error: CLOUDFLARE_API_KEY is missing. Aborting."; exit 1; } +[ -z "$CLOUDFLARE_EMAIL" ] && { echo >&2 "Error: CLOUDFLARE_EMAIL is missing. Aborting."; exit 1; } +[ -z "$CLOUDFLARE_IDENTIFIER" ] && { echo >&2 "Error: CLOUDFLARE_IDENTIFIER is missing. Aborting."; exit 1; } + +curl -X DELETE \ + -H "Content-Type: application/json" \ + -H "X-Auth-Key: $CLOUDFLARE_API_KEY" \ + -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ + --data '{"purge_everything":true}' \ + "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_IDENTIFIER/purge_cache" + +