diff options
Diffstat (limited to 'scripts/ci/deploy.sh')
-rwxr-xr-x | scripts/ci/deploy.sh | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/scripts/ci/deploy.sh b/scripts/ci/deploy.sh deleted file mode 100755 index 9be5758..0000000 --- a/scripts/ci/deploy.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash ../../shell.nix -# shellcheck shell=bash -set -Eeuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")" -cd ../../ -PROJECT_ROOT="${PWD}" - -finish-phase() { - local -r exit_code="${?}" - - cd "${PROJECT_ROOT}" - - if [[ "${exit_code}" = 0 ]]; then - echo "Finished successfully." - else - echo "TRAPPED ERROR!" - fi - echo "Running final steps..." - - echo "Sending logs via email..." - ./scripts/ci/mail.sh "${exit_code}" - echo "Done." - - echo "Storing file changes to '.tfstate' files..." - pushd ../vps-state/ - git add . - git commit -m "CI: fallback add all after deploy.sh failure for CI run $VPS_COMMIT_SHA" ||: - 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." - - echo "Finished cleanup." -} -trap finish-phase EXIT - -create-known-hosts-file() { - echo "${TLD},$(terraform output public_floating_ip) ssh-rsa $(awk '{print $2}' < ./secrets/ssh/vps-box-server.pub)" > ./generated/generated-known-hosts.txt -} - -echo "Interpolating files with envsubst..." -envsubst < ./ssh.env.conf >> ~/.ssh/config -envsubst < ./hosts.env > ./generated/hosts -envsubst < ./docker-compose.env.yaml > ./generated/docker-compose.yaml -envsubst < ./provision.env.yaml > ./generated/provision.yaml -envsubst < ./scripts/box/user-data.env.sh > ./generated/user-data.sh -envsubst < ./scripts/box/create-backup.env.sh > ./generated/create-backup.sh -envsubst < ./scripts/box/restore-backup.env.sh > ./generated/restore-backup.sh -echo "Done." - -echo "Running the Ansible shutdown.yaml playbook..." -create-known-hosts-file -ansible-playbook -v shutdown.yaml > ./logs/ansible-shutdown.txt -echo "Done." - -echo "Initializing Terraform..." -terraform --version -terraform init -echo "Done." - -if [[ "${DESTROY_VPS:-}" != "" ]]; then - echo "Destroying existing infrastructure..." - terraform destroy -input=false -auto-approve > ./logs/terraform-destroy.txt 2>&1 -else - echo 'Refreshing view on existing infrastructure...' - terraform refresh > ./logs/terraform-refresh.txt 2>&1 -fi -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}" > ./logs/terraform-plan.txt 2>&1 -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}" -git push origin master -popd -echo "Done." - -echo "Running 'terraform apply'..." -terraform apply -input=false -auto-approve "${PLAN_FILE_PATH}" > ./logs/terraform-apply.txt 2>&1 -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 ${VPS_COMMIT_SHA}" --allow-empty -git push origin master -popd -echo "Done." - -echo "Running the Ansible provision.yaml playbook..." -create-known-hosts-file -cp ./generated/provision.yaml ./provision.yaml -ansible-playbook -v provision.yaml > ./logs/ansible-provision.txt -echo "Done." |