#!/bin/bash # Gitea Deployment Script # Deploys Gitea Git repository server using Docker Compose set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # Configuration GITEA_DOMAIN="${GITEA_DOMAIN:-git.local}" GITEA_PORT="${GITEA_PORT:-3000}" SSH_PORT="${SSH_PORT:-2222}" COMPOSE_FILE="${COMPOSE_FILE:-$(dirname "$0")/../../docker-compose/gitea.yml}" log_info() { echo -e "${GREEN}[INFO]${NC} $1" } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } check_docker() { if ! command -v docker &> /dev/null; then log_error "Docker not found. Please install Docker first." exit 1 fi if ! docker ps &>/dev/null; then log_error "Docker daemon not running. Please start Docker." exit 1 fi if ! command -v docker-compose &> /dev/null && ! docker compose version &>/dev/null; then log_error "Docker Compose not found. Please install Docker Compose." exit 1 fi } update_compose_file() { log_info "Updating Docker Compose configuration..." # Update domain in compose file if needed if [ -f "$COMPOSE_FILE" ]; then sed -i "s/git.local/$GITEA_DOMAIN/g" "$COMPOSE_FILE" || true log_info "Docker Compose file configured" fi } deploy_gitea() { log_info "Deploying Gitea using Docker Compose..." # Determine compose command if docker compose version &>/dev/null; then COMPOSE_CMD="docker compose" else COMPOSE_CMD="docker-compose" fi # Deploy cd "$(dirname "$COMPOSE_FILE")" $COMPOSE_CMD -f "$(basename "$COMPOSE_FILE")" up -d log_info "Waiting for Gitea to be ready..." sleep 10 # Wait for service to be healthy MAX_WAIT=120 ELAPSED=0 while [ $ELAPSED -lt $MAX_WAIT ]; do if curl -s "http://localhost:$GITEA_PORT" &>/dev/null; then log_info "Gitea is ready!" return 0 fi log_info "Waiting for Gitea to start... ($ELAPSED/$MAX_WAIT seconds)" sleep 5 ELAPSED=$((ELAPSED + 5)) done log_warn "Gitea may not be fully ready yet. Check logs with:" log_info " docker logs gitea" } show_info() { log_info "Gitea deployment completed!" log_info "" log_info "Access Gitea at:" log_info " Web UI: http://$GITEA_DOMAIN:$GITEA_PORT" log_info " SSH: ssh://git@$GITEA_DOMAIN:$SSH_PORT" log_info "" log_info "Default credentials (change on first login):" log_info " Username: root" log_info " Password: (set during first-time setup)" log_info "" log_info "Useful commands:" log_info " View logs: docker logs gitea" log_info " Stop: docker-compose -f $COMPOSE_FILE down" log_info " Restart: docker-compose -f $COMPOSE_FILE restart" } main() { log_info "Starting Gitea deployment..." check_docker update_compose_file deploy_gitea show_info } main "$@"