diff options
Diffstat (limited to 'scripts/ci/provision.sh')
-rwxr-xr-x | scripts/ci/provision.sh | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/scripts/ci/provision.sh b/scripts/ci/provision.sh index 1000a55..87bb4c5 100755 --- a/scripts/ci/provision.sh +++ b/scripts/ci/provision.sh @@ -8,25 +8,38 @@ cd ../../ VPS_COMMIT_SHA="$(git rev-parse HEAD)" export VPS_COMMIT_SHA +# FIXME: use Ansible instead +setup_borg_files() { + local -r template_file="${1}" + local -r destination_name="${2}" + scp ./secrets/borg/borg-remote.pub "$TLD":/root/.ssh/id_rsa.pub + scp ./secrets/borg/borg-remote "$TLD":/root/.ssh/id_rsa + scp ./secrets/borg/known-hosts.txt "$TLD":/root/.ssh/known_hosts + ssh "$TLD" 'chmod 600 /root/.ssh/id_rsa' + envsubst < "${template_file}" | ssh "$TLD" "cat > /home/vps/${destination_name} && chmod +x /home/vps/${destination_name}" + ssh "$TLD" "chmod +x /home/vps/${destination_name}" +} + echo "Shutting down running containers and backing up data..." ssh "$TLD" "cd /home/vps/ && docker-compose down" -scp ./secrets/borg/borg-remote.pub "$TLD":/root/.ssh/id_rsa.pub -scp ./secrets/borg/borg-remote "$TLD":/root/.ssh/id_rsa -scp ./secrets/borg/known-hosts.txt "$TLD":/root/.ssh/known_hosts -ssh "$TLD" 'chmod 600 /root/.ssh/id_rsa' -envsubst < ./scripts/box/run-backup.env.sh | ssh "$TLD" 'cat > /home/vps/run-backup.sh && chmod +x /home/vps/run-backup.sh' -ssh "$TLD" /home/vps/run-backup.sh +setup_borg_files ./scripts/box/create-backup.env.sh create-backup.sh +ssh "$TLD" /home/vps/create-backup.sh echo "Done." -echo "Running 'terraform plan' and storing the planfile..." +echo "Initializing Terraform..." terraform --version terraform init +echo "Done." + +echo "Destroying existing infrastructure..." +terraform destroy -input=false -auto-approve +echo "Done." + +echo "Running 'terraform plan' and storing the planfile..." mkdir -p "../vps-state/secrets/plan-files/" PLAN_FILE_NAME="$(date -Iseconds)-$VPS_COMMIT_SHA.tfplan" PLAN_FILE_PATH="../vps-state/secrets/plan-files/$PLAN_FILE_NAME" - terraform plan -input=false -out="$PLAN_FILE_PATH" - pushd ../vps-state/ git add "secrets/plan-files/$PLAN_FILE_NAME" git commit -m "CI: add .tfplan plan file for CI run $VPS_COMMIT_SHA" @@ -46,6 +59,10 @@ git push origin master popd echo "Done." +echo "Restoring data from backup into volume..." +setup_borg_files ./scripts/box/restore-backup.env.sh restore-backup.sh +echo "Done." + echo "Running the Ansible playbook..." ansible-playbook provision.yaml echo "Done." |