diff --git a/install.sh b/install.sh index 3105b5e..edd7f2b 100644 --- a/install.sh +++ b/install.sh @@ -17,6 +17,11 @@ NC='\033[0m' # No Color COMPOSE_FILE="docker-compose.prod.yml" ENV_FILE=".env.production" +# Helper: full docker compose command with env file +dc() { + ${DOCKER_SUDO:-} docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" "$@" +} + # ─── Helpers ───────────────────────────────────────────────── info() { echo -e "${BLUE}[INFO]${NC} $*"; } @@ -294,13 +299,13 @@ echo "" info "Building Docker images (this may take a few minutes on first run)..." echo "" -${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" build --no-cache +dc build --no-cache echo "" info "Starting services..." echo "" -${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" up -d +dc up -d # ─── Step 6: Health Check ─────────────────────────────────── @@ -313,11 +318,11 @@ INTERVAL=5 while [[ $ELAPSED -lt $MAX_WAIT ]]; do # Check database - DB_HEALTHY=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps --format json 2>/dev/null | \ + DB_HEALTHY=$(dc ps --format json 2>/dev/null | \ grep -o '"db"[^}]*"healthy"' 2>/dev/null && echo "yes" || echo "no") # Check app - APP_RUNNING=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps --status running --format json 2>/dev/null | \ + APP_RUNNING=$(dc ps --status running --format json 2>/dev/null | \ grep -o '"app"' 2>/dev/null && echo "yes" || echo "no") if [[ "$DB_HEALTHY" == *"yes"* ]] && [[ "$APP_RUNNING" == *"yes"* ]]; then @@ -335,7 +340,7 @@ echo "" SERVICES_UP=true for service in db minio app; do - STATUS=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps "$service" --format "{{.Status}}" 2>/dev/null || echo "not found") + STATUS=$(dc ps "$service" --format "{{.Status}}" 2>/dev/null || echo "not found") if echo "$STATUS" | grep -qi "up\|running\|healthy"; then success "$service: $STATUS" else @@ -345,17 +350,17 @@ for service in db minio app; do done # Check migrate completed -MIGRATE_STATUS=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps migrate --format "{{.Status}}" 2>/dev/null || echo "not found") +MIGRATE_STATUS=$(dc ps migrate --format "{{.Status}}" 2>/dev/null || echo "not found") if echo "$MIGRATE_STATUS" | grep -qi "exited (0)\|completed"; then success "migrate: completed successfully" else - warn "migrate: $MIGRATE_STATUS (check logs: ${DOCKER_SUDO} docker compose -f $COMPOSE_FILE logs migrate)" + warn "migrate: $MIGRATE_STATUS (check logs: docker compose --env-file $ENV_FILE -f $COMPOSE_FILE logs migrate)" fi if [[ "$SERVICES_UP" == "false" ]]; then echo "" error "Some services failed to start. Check logs:" - echo " ${DOCKER_SUDO} docker compose -f $COMPOSE_FILE logs" + echo " docker compose --env-file $ENV_FILE -f $COMPOSE_FILE logs" exit 1 fi @@ -388,11 +393,12 @@ echo "" echo -e " ${BOLD}App URL:${NC} ${APP_URL_CHECK}" echo -e " ${BOLD}Config file:${NC} $(pwd)/$ENV_FILE" echo "" +DC_CMD="docker compose --env-file $ENV_FILE -f $COMPOSE_FILE" echo -e " ${BOLD}Useful commands:${NC}" -echo " View logs: docker compose -f $COMPOSE_FILE logs -f" -echo " Stop: docker compose -f $COMPOSE_FILE down" -echo " Restart: docker compose -f $COMPOSE_FILE restart" -echo " Rebuild: docker compose -f $COMPOSE_FILE up -d --build" +echo " View logs: $DC_CMD logs -f" +echo " Stop: $DC_CMD down" +echo " Restart: $DC_CMD restart" +echo " Rebuild: $DC_CMD up -d --build" echo "" echo -e " ${BOLD}${YELLOW}Next steps:${NC}" echo " 1. Open ${APP_URL_CHECK} and create your account"