Files
Ehsan/deploy.sh
T
Replit Agent 9e602d53fa Add deployment workflow to push code to Gitea and redeploy on Mac Mini
Configure Replit project for deployment to a self-hosted Gitea repository, including a `deploy.sh` script on a Mac Mini to pull changes, stop, rebuild, and restart Docker containers.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 1fa9329f-0cec-4a2f-80e8-e26dbae3142e
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 29017a07-e519-4b14-bdf7-b913b959d38f
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/4d696b13-86f2-4c9d-be0d-95b293430047/1fa9329f-0cec-4a2f-80e8-e26dbae3142e/ODGOKcj
Replit-Helium-Checkpoint-Created: true
2026-06-06 10:11:36 +00:00

77 lines
2.4 KiB
Bash
Executable File

#!/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} <GITEA_URL>)" >&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}"