Created
February 28, 2025 18:25
-
-
Save codebanesr/607777adca47cfb6750fab8d41748482 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
# ------------------------------- | |
# 1. Verify Required Environment Variables | |
# ------------------------------- | |
REQUIRED_VARS=("OPENAI_API_KEY" "ANTHROPIC_API_KEY") | |
for VAR in "${REQUIRED_VARS[@]}"; do | |
if [ -z "${!VAR:-}" ]; then | |
echo "Error: Required environment variable '$VAR' is not set." | |
exit 1 | |
fi | |
done | |
echo "All required environment variables are set." | |
# ------------------------------- | |
# 2. Detect Operating System | |
# ------------------------------- | |
uname_out="$(uname -s)" | |
case "${uname_out}" in | |
Linux*) machine=Linux;; | |
Darwin*) machine=Mac;; | |
CYGWIN*|MINGW*|MSYS*) | |
echo "Error: Windows detected. Please contribute or contact [email protected] to support Windows." | |
exit 1;; | |
*) | |
echo "Error: Unsupported OS: ${uname_out}" | |
exit 1;; | |
esac | |
echo "Detected OS: ${machine}" | |
# ------------------------------- | |
# 3. Check for Docker and Its Daemon | |
# ------------------------------- | |
if ! command -v docker &>/dev/null; then | |
echo "Error: Docker is not installed. Please install Docker." | |
exit 1 | |
fi | |
if ! docker info &>/dev/null; then | |
echo "Error: Docker does not appear to be running. Please start the Docker daemon." | |
exit 1 | |
fi | |
echo "Docker is installed and running." | |
# ------------------------------- | |
# 4. Function to Install Docker Compose | |
# ------------------------------- | |
install_docker_compose() { | |
COMPOSE_VERSION="v2.20.2" # Specify the desired version | |
OS=$(uname -s) | |
ARCH=$(uname -m) | |
DOWNLOAD_URL="https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-${OS}-${ARCH}" | |
echo "Downloading docker-compose from ${DOWNLOAD_URL}..." | |
# Use sudo if not running as root | |
if [ "$EUID" -ne 0 ]; then | |
if command -v sudo &>/dev/null; then | |
SUDO="sudo" | |
else | |
echo "Error: Root privileges are required to install docker-compose. Please run as root." | |
exit 1 | |
fi | |
else | |
SUDO="" | |
fi | |
$SUDO curl -L "$DOWNLOAD_URL" -o /usr/local/bin/docker-compose || { echo "Download failed"; exit 1; } | |
$SUDO chmod +x /usr/local/bin/docker-compose || { echo "Failed to set execute permissions"; exit 1; } | |
echo "docker-compose installed successfully." | |
} | |
# ------------------------------- | |
# 5. Determine Docker Compose Command or Install if Missing | |
# ------------------------------- | |
if command -v docker-compose &>/dev/null; then | |
COMPOSE_CMD="docker-compose" | |
elif docker compose version &>/dev/null; then | |
COMPOSE_CMD="docker compose" | |
else | |
echo "Neither 'docker-compose' nor 'docker compose' command is available." | |
echo "Attempting to install docker-compose..." | |
install_docker_compose | |
if command -v docker-compose &>/dev/null; then | |
COMPOSE_CMD="docker-compose" | |
else | |
echo "Error: docker-compose installation failed." | |
exit 1 | |
fi | |
fi | |
echo "Using compose command: ${COMPOSE_CMD}" | |
# ------------------------------- | |
# 6. Create docker-compose.yml if Missing | |
# ------------------------------- | |
if [ ! -f docker-compose.yml ]; then | |
echo "docker-compose.yml not found. Creating a default docker-compose.yml file..." | |
cat > docker-compose.yml << 'EOF' | |
services: | |
chrome-desktop-playwright: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
image: shanurcsenitap/chrome-desktop-playwright | |
container_name: chrome-desktop-playwright | |
hostname: chrome-desktop-playwright | |
ports: | |
- "3000:3000" # Internal service port; SWAG will proxy HTTPS traffic | |
- "5901:5901" # VNC port | |
- "6901:6901" # noVNC port | |
environment: | |
- VNC_RESOLUTION=${WIDTH:-1024}x${HEIGHT:-768} | |
- PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=${PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH:-/usr/bin/chromium} | |
- LOG_LEVEL=${LOG_LEVEL:-debug} | |
- RABBITMQ_QUEUE=${RABBITMQ_QUEUE:-browser_tasks} | |
- OPENAI_API_KEY=${OPENAI_API_KEY} | |
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} | |
- PORT=${PORT:-3000} | |
- RABBITMQ_USER=${RABBITMQ_USER:-admin} | |
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD:-admin} | |
- RABBITMQ_HOST=${RABBITMQ_HOST:-rabbitmq} | |
- RABBITMQ_PORT=${RABBITMQ_PORT:-5672} | |
networks: | |
- web | |
rabbitmq: | |
image: rabbitmq:3-management | |
container_name: rabbitmq | |
environment: | |
- RABBITMQ_DEFAULT_USER=${RABBITMQ_USER} | |
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASSWORD} | |
volumes: | |
- rabbitmq-data:/var/lib/rabbitmq | |
networks: | |
- web | |
restart: unless-stopped | |
# swag: | |
# image: linuxserver/swag | |
# container_name: swag | |
# cap_add: | |
# - NET_ADMIN | |
# environment: | |
# - PUID=1000 # Adjust as needed | |
# - PGID=1000 # Adjust as needed | |
# - TZ=Etc/UTC # Adjust your timezone if needed | |
# - URL=bua.tryiris.dev # Your primary domain | |
# - SUBDOMAINS=www,rabbitmq # Subdomains to be covered by the cert | |
# - VALIDATION=http # Using HTTP validation (or use dns if preferred) | |
# - DISABLE_IPV6=true # Disable IPv6 validation | |
# volumes: | |
# - ./config:/config # Mount your SWAG configuration directory | |
# ports: | |
# - "80:80" | |
# - "443:443" | |
# networks: | |
# - web | |
volumes: | |
rabbitmq-data: | |
networks: | |
web: | |
driver: bridge | |
EOF | |
echo "docker-compose.yml file created." | |
else | |
echo "Found existing docker-compose.yml file. Skipping file creation." | |
fi | |
# ------------------------------- | |
# 7. Start the Application | |
# ------------------------------- | |
echo "Starting the application using '$COMPOSE_CMD up -d'..." | |
$COMPOSE_CMD up -d | |
echo "Application started successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment