180 lines
4.3 KiB
Bash
Executable File
180 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Turmli Bar Calendar Tool - Simple Docker Deployment Script
|
||
# For internal use - no nginx, no SSL, just the calendar app
|
||
|
||
set -e # Exit on error
|
||
|
||
# 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="turmli-calendar"
|
||
IMAGE_NAME="turmli-calendar:latest"
|
||
CONTAINER_NAME="turmli-calendar"
|
||
DEFAULT_PORT=8000
|
||
|
||
# Functions
|
||
print_header() {
|
||
echo -e "${BLUE}================================${NC}"
|
||
echo -e "${BLUE} Turmli Bar Calendar Deployment${NC}"
|
||
echo -e "${BLUE}================================${NC}"
|
||
echo ""
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✓${NC} $1"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}✗${NC} $1"
|
||
}
|
||
|
||
print_info() {
|
||
echo -e "${BLUE}ℹ${NC} $1"
|
||
}
|
||
|
||
check_docker() {
|
||
if ! command -v docker &> /dev/null; then
|
||
print_error "Docker is not installed. Please install Docker first."
|
||
exit 1
|
||
fi
|
||
print_success "Docker is installed"
|
||
}
|
||
|
||
build() {
|
||
print_info "Building Docker image..."
|
||
docker build -t ${IMAGE_NAME} . || {
|
||
print_error "Failed to build Docker image"
|
||
exit 1
|
||
}
|
||
print_success "Docker image built successfully"
|
||
}
|
||
|
||
start() {
|
||
print_info "Starting calendar application..."
|
||
|
||
# Check if container already exists
|
||
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||
print_info "Container already exists, removing it..."
|
||
docker rm -f ${CONTAINER_NAME}
|
||
fi
|
||
|
||
# Get port from environment or use default
|
||
PORT="${PORT:-$DEFAULT_PORT}"
|
||
|
||
# Run container
|
||
docker run -d \
|
||
--name ${CONTAINER_NAME} \
|
||
-p ${PORT}:8000 \
|
||
-v $(pwd)/calendar_cache.json:/app/calendar_cache.json \
|
||
-e TZ=Europe/Berlin \
|
||
--restart unless-stopped \
|
||
${IMAGE_NAME}
|
||
|
||
print_success "Application started on port ${PORT}"
|
||
print_info "Access the calendar at: http://localhost:${PORT}"
|
||
}
|
||
|
||
stop() {
|
||
print_info "Stopping calendar application..."
|
||
docker stop ${CONTAINER_NAME} 2>/dev/null || true
|
||
docker rm ${CONTAINER_NAME} 2>/dev/null || true
|
||
print_success "Application stopped"
|
||
}
|
||
|
||
restart() {
|
||
stop
|
||
start
|
||
}
|
||
|
||
logs() {
|
||
docker logs -f ${CONTAINER_NAME}
|
||
}
|
||
|
||
status() {
|
||
echo -e "${BLUE}Container Status:${NC}"
|
||
if docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -q ${CONTAINER_NAME}; then
|
||
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "NAMES|${CONTAINER_NAME}"
|
||
echo ""
|
||
print_info "Testing application..."
|
||
if curl -s -f http://localhost:${PORT:-$DEFAULT_PORT}/api/events > /dev/null 2>&1; then
|
||
print_success "Application is healthy and responding"
|
||
else
|
||
print_error "Application is not responding"
|
||
fi
|
||
else
|
||
print_info "Container is not running"
|
||
fi
|
||
}
|
||
|
||
update() {
|
||
print_info "Updating application..."
|
||
|
||
# Pull latest changes if using git
|
||
if [ -d .git ]; then
|
||
print_info "Pulling latest changes..."
|
||
git pull
|
||
fi
|
||
|
||
# Rebuild and restart
|
||
build
|
||
restart
|
||
print_success "Application updated"
|
||
}
|
||
|
||
# Parse command
|
||
print_header
|
||
|
||
case "$1" in
|
||
build)
|
||
check_docker
|
||
build
|
||
;;
|
||
start)
|
||
check_docker
|
||
build
|
||
start
|
||
;;
|
||
stop)
|
||
stop
|
||
;;
|
||
restart)
|
||
check_docker
|
||
restart
|
||
;;
|
||
logs)
|
||
logs
|
||
;;
|
||
status)
|
||
status
|
||
;;
|
||
update)
|
||
check_docker
|
||
update
|
||
;;
|
||
*)
|
||
echo "Usage: $0 {build|start|stop|restart|logs|status|update}"
|
||
echo ""
|
||
echo "Commands:"
|
||
echo " build - Build Docker image"
|
||
echo " start - Build and start the application"
|
||
echo " stop - Stop the application"
|
||
echo " restart - Restart the application"
|
||
echo " logs - View application logs"
|
||
echo " status - Check application status"
|
||
echo " update - Update and restart application"
|
||
echo ""
|
||
echo "Environment variables:"
|
||
echo " PORT - Port to expose (default: 8000)"
|
||
echo ""
|
||
echo "Example:"
|
||
echo " $0 start # Start on port 8000"
|
||
echo " PORT=8080 $0 start # Start on port 8080"
|
||
exit 1
|
||
;;
|
||
esac |