*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects

Various improvements

Merged Tsepelakis, Sotirios requested to merge st/dev into main
15 files
+ 427
109
Compare changes
  • Side-by-side
  • Inline
Files
15
+ 57
0
#!/bin/bash
#
# Deployment script for CRDM Logs.
# Intended for execution by the GitLab Runner.
set -euo pipefail
# Ensure required environment variables are set.
# DEPLOYMENT_HOST denotes the SSH TARGET. Can be only ONE IP or DNS name.
if [ -z "$DEPLOYMENT_HOST" ]; then
echo "[ERROR] Make sure DEPLOYMENT_HOST is set." >&2
exit 1
fi
# ----------------------- #
# Repository checks #
# ----------------------- #
DEPLOYMENT_PATH="${DEPLOYMENT_PATH:-crdm-logging-setup}"
SSH_TARGET="${DEPLOYMENT_USER:-logs}@${DEPLOYMENT_HOST}"
# SSH to target, initialize repo if it doesn't exist.
# Otherwise, tear down old deployment and pull changes.
ssh "${SSH_TARGET}" "bash" <<- EOF
set -eu pipefail
mkdir -p "${DEPLOYMENT_PATH}" && cd "${DEPLOYMENT_PATH}"
if git status > /dev/null 2>&1; then
echo "[INFO] Pulling origin."
git pull "${CI_REPOSITORY_URL}"
else
echo "[INFO] Git repository doesn't exist, cloning and setting up."
git clone "${CI_REPOSITORY_URL}" . > /dev/null 2>&1
fi
echo -n "[INFO] " && git checkout "${CI_COMMIT_BRANCH}"
EOF
# ----------------------- #
# .env file checks #
# ----------------------- #
# Dump variables and transfer the file.
echo "[INFO] Dumping variables to .env file."
./scripts/dump-vars.sh ".env"
scp ".env" "${SSH_TARGET}:${DEPLOYMENT_PATH}/.env"
# SSH again, check if ssl directory is empty: setup or rerun.
ssh "${SSH_TARGET}" "bash" <<- EOF
set -eu pipefail
cd "${DEPLOYMENT_PATH}"
if [ $(find "./ssl" -type f ! -name '.gitkeep' | wc -l) -eq 0 ]; then
echo "[INFO] SSL directory only contains .gitkeep. Running setup.sh to create certificates."
./scripts/setup.sh
else
echo "[INFO] SSL directory is not empty. Skipping certificate setup."
docker compose up -d
fi
EOF
Loading