blob: 4ae29e563c07a169a2b84f6b0bd0ee7e245a1e74 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/usr/bin/env nix-shell
#!nix-shell -i bash ../../shell.nix
# shellcheck shell=bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
cd ../../
echo "Shutting down running containers and backing up data..."
ssh "$TLD" "cd /home/vps/ && docker-compose down"
scp ./secrets/borg_remote.pub "$TLD":/root/.ssh/id_rsa.pub
scp ./secrets/borg_remote "$TLD":/root/.ssh/id_rsa
VPS_COMMIT_SHA="$(git rev-parse HEAD)" envsubst < ./scripts/box/run-backup-template.sh | ssh "$TLD" 'cat > /home/vps/run-backup.sh && chmod +x /home/vps/run-backup.sh'
ssh "$TLD" /home/vps/run-backup.sh
echo "Done."
echo "Running 'terraform plan' and storing the planfile..."
# Terraform plan
terraform --version
terraform init
mkdir -p "../vps-state/secrets/plan-files/"
PLAN_FILE="../vps-state/secrets/plan-files/$(date -Iseconds)-$(git rev-parse HEAD).tfplan"
terraform plan -input=false -out="$PLAN_FILE"
# Store on git repo
pushd ../vps-state/
git add "secrets/plan-files/$PLAN_FILE"
git commit -m "CI: add .tfplan plan file for CI run $(git rev-parse HEAD)"
git push origin master
popd
echo "Done."
echo "Running 'terraform apply'..."
terraform apply -input=false -auto-approve "$PLAN_FILE"
echo "Done."
echo "Storing .tfstate file..."
pushd ../vps-state/
git add secrets/terraform.tfstate secrets/terraform.tfstate.backup
git commit -m "CI: update Terraform .tfstate files for CI run $(git rev-parse HEAD)"
git push origin master
popd
echo "Done."
echo "Locking git-crypt repositories back..."
git crypt lock
pushd ../vps-state/
git crypt lock
popd
echo "Done."
|