#!/usr/bin/env bash # # EHSAN — Mac Mini deployment script. # # Pulls the latest code from the Gitea repository, then rebuilds and restarts # the Docker containers. Run this ON THE MAC MINI, from the repo checkout. # # Flow: Replit -> push to Gitea -> (this script) Mac Mini pulls -> Docker redeploys # # Usage: # ./deploy.sh # # Optional overrides (environment variables): # GIT_REMOTE Git remote to pull from (default: gitea) # GIT_BRANCH Branch to deploy (default: main) # WEB_PORT Host port for the web app (default: 8080) set -euo pipefail GIT_REMOTE="${GIT_REMOTE:-gitea}" GIT_BRANCH="${GIT_BRANCH:-main}" # Always operate from the directory this script lives in. cd "$(dirname "$0")" # --- Resolve the docker compose command (v2 plugin or legacy binary) -------- if docker compose version >/dev/null 2>&1; then COMPOSE="docker compose" elif command -v docker-compose >/dev/null 2>&1; then COMPOSE="docker-compose" else echo "ERROR: Docker Compose was not found. Install Docker Desktop (includes the" >&2 echo " 'docker compose' plugin) or the standalone 'docker-compose' binary." >&2 exit 1 fi echo "==================================================" echo " EHSAN deploy | remote=${GIT_REMOTE} branch=${GIT_BRANCH}" echo "==================================================" echo "" echo "==> [1/4] Pulling latest code from ${GIT_REMOTE}/${GIT_BRANCH}..." if ! git pull "${GIT_REMOTE}" "${GIT_BRANCH}"; then echo "ERROR: 'git pull ${GIT_REMOTE} ${GIT_BRANCH}' failed. Is the '${GIT_REMOTE}' remote" >&2 echo " configured and reachable? (git remote add ${GIT_REMOTE} )" >&2 exit 1 fi echo "" echo "==> [2/4] Stopping current containers..." if ! ${COMPOSE} down --remove-orphans; then echo "ERROR: Failed to stop the existing containers." >&2 exit 1 fi echo "" echo "==> [3/4] Rebuilding containers (this can take a few minutes)..." if ! ${COMPOSE} build --pull; then echo "ERROR: Docker image build failed. See the build output above." >&2 exit 1 fi echo "" echo "==> [4/4] Starting containers..." if ! ${COMPOSE} up -d; then echo "ERROR: Failed to start the containers." >&2 exit 1 fi echo "" echo "==================================================" echo " SUCCESS: Deployment complete." echo "==================================================" ${COMPOSE} ps echo "" echo "The app should now be available on this machine at: http://localhost:${WEB_PORT:-8080}"