aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2019-06-10 16:01:26 -0300
committerEuAndreh <eu@euandre.org>2019-06-10 16:01:26 -0300
commit2292283dca4a2c525d9d93c99a605f926e93585a (patch)
tree79bf5d59dc009dee51442c02306f1b7397344b6d /scripts
parentDisable $DESTROY_VOLUME operational toggle (diff)
downloadtoph-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')
-rwxr-xr-xscripts/box/create-backup.env.sh2
-rwxr-xr-xscripts/ci/mail.sh33
-rwxr-xr-xscripts/ci/provision.sh11
3 files changed, 44 insertions, 2 deletions
diff --git a/scripts/box/create-backup.env.sh b/scripts/box/create-backup.env.sh
index 2c97594..f5cd3b0 100755
--- a/scripts/box/create-backup.env.sh
+++ b/scripts/box/create-backup.env.sh
@@ -6,7 +6,9 @@ export BORG_PASSPHRASE="${BORG_PASSPHRASE}"
# The configured $BORG_REPO is already the rsync remote.
# No need to send the files after the backup is done.
borg create \
+ --verbose \
--stats \
+ --progress \
--compression lzma,6 \
"${BORG_REPO}::{hostname}-{now}-${VPS_COMMIT_SHA}" \
"${VOLUME_HOME}"/*
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..."