Files
traceability/deploy.sh
2026-01-25 14:58:57 +01:00

143 lines
4.2 KiB
Bash

#!/bin/bash
# ============================================
# ASF Traceability Matrix Deployment Script
# ============================================
# This script deploys the Traceability Matrix web app
# using Docker Compose with Caddy reverse proxy
#
# Domain: Traceability.nabd-co.com
# ============================================
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
APP_NAME="traceability"
APP_DIR="/opt/traceability"
CADDY_DIR="/root/caddy"
REPO_URL="" # Add your git repo URL if using git deployment
echo -e "${BLUE}============================================${NC}"
echo -e "${BLUE} ASF Traceability Matrix Deployment${NC}"
echo -e "${BLUE}============================================${NC}"
# Function to print status
print_status() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
print_error() {
echo -e "${RED}[✗]${NC} $1"
}
# Check if running as root
if [ "$EUID" -ne 0 ]; then
print_error "Please run as root (sudo ./deploy.sh)"
exit 1
fi
# Step 1: Create application directory
echo ""
echo -e "${BLUE}Step 1: Setting up application directory...${NC}"
mkdir -p $APP_DIR
print_status "Created directory: $APP_DIR"
# Step 2: Copy files to application directory (if running from repo)
echo ""
echo -e "${BLUE}Step 2: Copying application files...${NC}"
if [ -f "docker-compose.yml" ]; then
cp -r . $APP_DIR/
print_status "Copied application files to $APP_DIR"
else
print_warning "No local files found. Please ensure files are in $APP_DIR"
fi
cd $APP_DIR
# Step 3: Ensure Caddy network exists
echo ""
echo -e "${BLUE}Step 3: Checking Docker network...${NC}"
if ! docker network ls | grep -q "caddy_default"; then
print_warning "Caddy network not found. Creating..."
docker network create caddy_default
print_status "Created caddy_default network"
else
print_status "Caddy network exists"
fi
# Step 4: Show Caddy configuration to add
echo ""
echo -e "${BLUE}Step 4: Caddy configuration...${NC}"
# Check if Traceability entry already exists in Caddyfile
if grep -q "Traceability.nabd-co.com" "$CADDY_DIR/Caddyfile" 2>/dev/null; then
print_status "Caddy configuration already exists in Caddyfile"
else
print_warning "Add this entry to your Caddyfile at $CADDY_DIR/Caddyfile:"
echo ""
echo -e "${YELLOW}# -------------------------"
echo "# Traceability Matrix Proxy"
echo "# -------------------------"
echo "Traceability.nabd-co.com {"
echo " reverse_proxy traceability_web:8088"
echo " encode gzip"
echo -e "}${NC}"
echo ""
fi
# Step 5: Build and start the application
echo ""
echo -e "${BLUE}Step 5: Building and starting application...${NC}"
docker compose down --remove-orphans 2>/dev/null || true
docker compose build --no-cache
docker compose up -d
print_status "Application started"
# Step 6: Reload Caddy
echo ""
echo -e "${BLUE}Step 6: Reloading Caddy...${NC}"
cd $CADDY_DIR
docker compose exec -T caddy caddy reload --config /etc/caddy/Caddyfile 2>/dev/null || {
print_warning "Could not reload Caddy automatically. Restarting container..."
docker compose restart caddy 2>/dev/null || docker restart caddy 2>/dev/null || true
}
print_status "Caddy reloaded"
# Step 7: Health check
echo ""
echo -e "${BLUE}Step 7: Running health check...${NC}"
sleep 5
if docker ps | grep -q "traceability_web"; then
print_status "Container is running"
else
print_error "Container failed to start. Check logs with: docker logs traceability_web"
exit 1
fi
# Final output
echo ""
echo -e "${GREEN}============================================${NC}"
echo -e "${GREEN} Deployment Complete!${NC}"
echo -e "${GREEN}============================================${NC}"
echo ""
echo -e "Application URL: ${BLUE}https://Traceability.nabd-co.com${NC}"
echo ""
echo -e "Useful commands:"
echo -e " View logs: ${YELLOW}docker logs -f traceability_web${NC}"
echo -e " Restart: ${YELLOW}docker compose -f $APP_DIR/docker-compose.yml restart${NC}"
echo -e " Stop: ${YELLOW}docker compose -f $APP_DIR/docker-compose.yml down${NC}"
echo -e " Rebuild: ${YELLOW}docker compose -f $APP_DIR/docker-compose.yml up -d --build${NC}"
echo ""