Files
qlockify-core-deployment/scripts/deploy.sh
Amirhossein Khalili e015f01cd6
Some checks failed
Deployment CI/CD / validate (push) Has been cancelled
Deployment CI/CD / deploy (push) Has been cancelled
feat(deploy): add gitea actions deployment pipeline
2026-05-14 18:18:26 +03:30

93 lines
2.2 KiB
Bash

#!/usr/bin/env bash
set -Eeuo pipefail
usage() {
cat <<'EOF'
Usage:
deploy.sh <component>
Components:
deployment Update the deployment repo and rebuild nginx + app services
backend Update the backend repo and rebuild backend + celery services
frontend Update the frontend repo and rebuild frontend
full Update all three repos and rebuild all app services
EOF
}
log() {
printf '[deploy] %s\n' "$*"
}
require_git_repo() {
local path="$1"
if [[ ! -d "$path/.git" ]]; then
printf 'Expected git repository at %s\n' "$path" >&2
exit 1
fi
}
sync_repo() {
local path="$1"
local branch="$2"
require_git_repo "$path"
log "Syncing $path -> origin/$branch"
git -C "$path" fetch --prune origin
git -C "$path" checkout "$branch"
git -C "$path" reset --hard "origin/$branch"
}
compose() {
docker compose -f "$DEPLOY_ROOT/docker-compose.yml" "$@"
}
COMPONENT="${1:-}"
if [[ -z "$COMPONENT" ]]; then
usage
exit 1
fi
DEPLOY_ROOT="${DEPLOY_ROOT:-$HOME/qlockify-deployment}"
DEPLOY_BRANCH="${DEPLOY_BRANCH:-main}"
BACKEND_BRANCH="${BACKEND_BRANCH:-main}"
FRONTEND_BRANCH="${FRONTEND_BRANCH:-main}"
DEPLOY_REPO_PATH="$DEPLOY_ROOT"
BACKEND_REPO_PATH="$DEPLOY_ROOT/backend/qlockify-backend-deployment"
FRONTEND_REPO_PATH="$DEPLOY_ROOT/frontend/qlockify-frontend-deployment"
cd "$DEPLOY_ROOT"
case "$COMPONENT" in
deployment)
sync_repo "$DEPLOY_REPO_PATH" "$DEPLOY_BRANCH"
compose config -q
compose up -d --build nginx backend frontend celery celery-beat
;;
backend)
sync_repo "$DEPLOY_REPO_PATH" "$DEPLOY_BRANCH"
sync_repo "$BACKEND_REPO_PATH" "$BACKEND_BRANCH"
compose config -q
compose up -d --build backend celery celery-beat
;;
frontend)
sync_repo "$DEPLOY_REPO_PATH" "$DEPLOY_BRANCH"
sync_repo "$FRONTEND_REPO_PATH" "$FRONTEND_BRANCH"
compose config -q
compose up -d --build frontend
;;
full)
sync_repo "$DEPLOY_REPO_PATH" "$DEPLOY_BRANCH"
sync_repo "$BACKEND_REPO_PATH" "$BACKEND_BRANCH"
sync_repo "$FRONTEND_REPO_PATH" "$FRONTEND_BRANCH"
compose config -q
compose up -d --build nginx backend frontend celery celery-beat
;;
*)
usage
exit 1
;;
esac
compose ps