diff options
author | EuAndreh <eu@euandre.org> | 2019-06-10 16:01:26 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2019-06-10 16:01:26 -0300 |
commit | 2292283dca4a2c525d9d93c99a605f926e93585a (patch) | |
tree | 79bf5d59dc009dee51442c02306f1b7397344b6d /scripts/ci | |
parent | Disable $DESTROY_VOLUME operational toggle (diff) | |
download | toph-2292283dca4a2c525d9d93c99a605f926e93585a.tar.gz toph-2292283dca4a2c525d9d93c99a605f926e93585a.tar.xz |
Send logs via email after finishing provision.sh
The email will be send for both sucessfull and failed runs.
Diffstat (limited to 'scripts/ci')
-rwxr-xr-x | scripts/ci/mail.sh | 33 | ||||
-rwxr-xr-x | scripts/ci/provision.sh | 11 |
2 files changed, 42 insertions, 2 deletions
diff --git a/scripts/ci/mail.sh b/scripts/ci/mail.sh new file mode 100755 index 0000000..d15c5db --- /dev/null +++ b/scripts/ci/mail.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../../ + +VPS_COMMIT_SHA="${1:-}" +[[ -z "${VPS_COMMIT_SHA}" ]] && { + echo 'Error: missing $VPS_COMMIT_SHA positional argument.' + exit 2 +} + +SUBJECT="VPS CI run #${JOB_ID} logs" +ATTACHMENT_PATH='logs.txt' +BODY=$(cat <<EOF +CI run for commit ${VPS_COMMIT_SHA}. +See failed run: +https://builds.sr.ht/~euandreh/job/${JOB_ID} + +Logs are attached. + +EOF +) + +cat ./logs/*.txt > "${ATTACHMENT_PATH}" + +curl "${MAILGUN_URL}" \ + -s \ + --user "${MAILGUN_USER}" \ + -F from="${MAILGUN_FROM}" \ + -F to="${MAILGUN_TO}" \ + -F subject="${SUBJECT}" \ + -F text="${BODY}" \ + -F attachment="@${ATTACHMENT_PATH}" diff --git a/scripts/ci/provision.sh b/scripts/ci/provision.sh index 8b058e2..ff71cb6 100755 --- a/scripts/ci/provision.sh +++ b/scripts/ci/provision.sh @@ -8,6 +8,13 @@ cd ../../ VPS_COMMIT_SHA="$(git rev-parse HEAD)" export VPS_COMMIT_SHA +mail_debug_log() { + echo "Sending logs via email..." + ./scripts/ci/mail.sh "${VPS_COMMIT_SHA}" + echo "Done." +} +trap mail_debug_log EXIT + create_known_hosts_file() { echo "${TLD},$(terraform output public_floating_ip) ssh-rsa $(awk '{print $2}' < ./secrets/ssh/vps-box-server.pub)" > ./generated-known-hosts.txt } @@ -29,7 +36,7 @@ echo "Shutting down running containers and backing up data..." create_known_hosts_file ssh "$TLD" "cd /home/vps/ && docker-compose down" setup_borg_files ./scripts/box/create-backup.env.sh create-backup.sh -ssh "$TLD" /home/vps/create-backup.sh +ssh "$TLD" /home/vps/create-backup.sh 2>&1 > ./logs/borg-create.txt echo "Done." echo "Initializing Terraform..." @@ -71,7 +78,7 @@ echo "Done." echo "Running the Ansible playbook..." create_known_hosts_file -ansible-playbook provision.yaml +ansible-playbook -vvv provision.yaml 2>&1 > ./logs/ansible.txt echo "Done." echo "Locking git-crypt repositories back..." |