Some checks failed
Deploy Application / deploy (push) Has been cancelled
137 lines
3.5 KiB
Bash
Executable File
137 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
||
# ==============================================================================
|
||
# Infrastructure Deployment Script
|
||
# ==============================================================================
|
||
# Deploys individual infrastructure stacks (traefik, gitea, postgresql)
|
||
# Usage: ./deploy.sh <stack-name> [all]
|
||
# ==============================================================================
|
||
|
||
set -e
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
cd "$SCRIPT_DIR"
|
||
|
||
# Colors for output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m' # No Color
|
||
|
||
# Function to print colored output
|
||
print_info() {
|
||
echo -e "${BLUE}ℹ${NC} $1"
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✅${NC} $1"
|
||
}
|
||
|
||
print_warning() {
|
||
echo -e "${YELLOW}⚠️${NC} $1"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}❌${NC} $1"
|
||
}
|
||
|
||
# Function to deploy a stack
|
||
deploy_stack() {
|
||
local stack_name=$1
|
||
local stack_dir="$SCRIPT_DIR/$stack_name"
|
||
|
||
if [ ! -d "$stack_dir" ]; then
|
||
print_error "Stack '$stack_name' not found in $stack_dir"
|
||
return 1
|
||
fi
|
||
|
||
print_info "Deploying stack: $stack_name"
|
||
cd "$stack_dir"
|
||
|
||
# Check if secrets exist
|
||
if [ -d "secrets" ]; then
|
||
local missing_secrets=()
|
||
for secret_file in secrets/*.txt; do
|
||
if [ ! -f "$secret_file" ]; then
|
||
missing_secrets+=("$secret_file")
|
||
fi
|
||
done
|
||
|
||
if [ ${#missing_secrets[@]} -gt 0 ]; then
|
||
print_warning "Some secrets are missing. Please create them first."
|
||
print_info "See SECRETS.md for instructions."
|
||
return 1
|
||
fi
|
||
fi
|
||
|
||
# Pull latest images
|
||
print_info "Pulling latest images..."
|
||
docker compose pull || print_warning "Failed to pull images, continuing..."
|
||
|
||
# Deploy stack
|
||
print_info "Starting stack..."
|
||
docker compose up -d
|
||
|
||
# Wait for services to be healthy
|
||
print_info "Waiting for services to be healthy..."
|
||
sleep 5
|
||
|
||
# Check service status
|
||
print_info "Checking service status..."
|
||
docker compose ps
|
||
|
||
print_success "Stack '$stack_name' deployed successfully"
|
||
}
|
||
|
||
# Function to create required networks
|
||
create_networks() {
|
||
print_info "Creating required networks..."
|
||
|
||
# Create infrastructure network if it doesn't exist
|
||
if ! docker network ls | grep -q "infrastructure"; then
|
||
print_info "Creating infrastructure network..."
|
||
docker network create infrastructure
|
||
print_success "Infrastructure network created"
|
||
else
|
||
print_info "Infrastructure network already exists"
|
||
fi
|
||
|
||
# traefik-public network will be created by Traefik stack
|
||
# app-internal network will be created by PostgreSQL stack
|
||
}
|
||
|
||
# Main execution
|
||
main() {
|
||
local stack_name=$1
|
||
|
||
if [ -z "$stack_name" ]; then
|
||
print_error "Usage: $0 <stack-name> [all]"
|
||
print_info "Available stacks: traefik, gitea, postgresql"
|
||
print_info "Use 'all' to deploy all stacks in correct order"
|
||
exit 1
|
||
fi
|
||
|
||
if [ "$stack_name" = "all" ]; then
|
||
print_info "Deploying all infrastructure stacks..."
|
||
create_networks
|
||
|
||
# Deploy in correct order
|
||
deploy_stack "traefik"
|
||
sleep 5
|
||
|
||
deploy_stack "postgresql"
|
||
sleep 5
|
||
|
||
deploy_stack "gitea"
|
||
|
||
print_success "All infrastructure stacks deployed successfully"
|
||
else
|
||
create_networks
|
||
deploy_stack "$stack_name"
|
||
fi
|
||
}
|
||
|
||
# Run main function
|
||
main "$@"
|
||
|