infra-controller/scripts/deploy-app
Jeremie Fraeys 0291800ef5
Some checks failed
Deploy / deploy (push) Failing after 7s
Option B: stop unused services; add restricted SSH scripts
2026-01-20 12:18:09 -05:00

43 lines
846 B
Bash

#!/usr/bin/env bash
set -euo pipefail
APP_NAME="${1:-}"
GIT_REF="${2:-}"
if [[ -z "$APP_NAME" || -z "$GIT_REF" ]]; then
echo "usage: deploy-app <app_name> <git_ref>" >&2
exit 2
fi
if ! [[ "$APP_NAME" =~ ^[A-Za-z0-9._-]+$ ]]; then
echo "invalid app name: $APP_NAME" >&2
exit 2
fi
if ! [[ "$GIT_REF" =~ ^[0-9a-fA-F]{7,40}$ ]]; then
echo "invalid git ref: $GIT_REF" >&2
exit 2
fi
APP_DIR="/srv/apps/$APP_NAME"
if [[ ! -d "$APP_DIR/.git" ]]; then
echo "app repo not present at $APP_DIR; clone it first (or extend deploy-app to clone)" >&2
exit 1
fi
cd "$APP_DIR"
git fetch --all --prune
git checkout -f "$GIT_REF"
git submodule update --init --recursive
if [[ -x "./deploy.sh" ]]; then
./deploy.sh
else
echo "ERROR: deploy.sh missing or not executable" >&2
exit 1
fi
/usr/local/sbin/sync-infra "$APP_NAME" "$APP_DIR"