#!/usr/bin/env bash # Ansible-managed deploy script set -euo pipefail REPO_URL="{{ app_repo_url }}" BRANCH="{{ app_repo_branch }}" APP_ROOT="{{ app_repo_dest }}" BACKEND_DIR="{{ app_backend_dir }}" FRONTEND_DIR="{{ app_frontend_dir }}" ENV_FILE="{{ app_root }}/.env.{{ app_env }}" echo "[deploy] repo=${REPO_URL} branch=${BRANCH} root=${APP_ROOT}" if [[ ! -d "${APP_ROOT}/.git" ]]; then echo "[deploy] cloning repo" install -d -m 0755 "${APP_ROOT}" git clone --branch "${BRANCH}" --single-branch "${REPO_URL}" "${APP_ROOT}" fi echo "[deploy] syncing branch" git -C "${APP_ROOT}" fetch origin --prune if ! git -C "${APP_ROOT}" rev-parse --verify --quiet "refs/remotes/origin/${BRANCH}" >/dev/null; then echo "[deploy] ERROR: branch '${BRANCH}' not found on origin" exit 2 fi git -C "${APP_ROOT}" checkout -B "${BRANCH}" "origin/${BRANCH}" git -C "${APP_ROOT}" pull --ff-only origin "${BRANCH}" if [[ "{{ app_enable_backend | bool }}" == "True" ]]; then echo "[deploy] backend install" cd "${BACKEND_DIR}" {{ app_backend_install_cmd }} echo "[deploy] backend migrations" {{ app_backend_migrate_cmd }} fi if [[ "{{ app_enable_frontend | bool }}" == "True" ]]; then echo "[deploy] frontend install" cd "${FRONTEND_DIR}" {{ app_frontend_install_cmd }} echo "[deploy] frontend build" {{ app_frontend_build_cmd }} fi echo "[deploy] restarting services" {% if app_enable_backend | bool %} systemctl restart app-backend.service {% endif %} {% if app_enable_frontend | bool %} systemctl restart app-frontend.service {% endif %} echo "[deploy] done"