#!/bin/bash
# Script to build and run the Looker MCP Docker container using docker-compose
# Determine action and mode
ACTION=${1:-run} # Default action is run
MODE=${2:-stdio} # Default mode is stdio (if action is run)
if [ "$ACTION" = "build" ]; then
MODE="build-only" # Set mode to skip run step later
elif [ "$ACTION" = "run" ]; then
MODE=${1:-stdio} # If first arg is run, use second arg for mode or default
elif [ "$ACTION" = "sse" ] || [ "$ACTION" = "stdio" ]; then
# Allow specifying mode as the first argument if action is omitted
MODE=$ACTION
ACTION="run"
elif [ -z "$1" ]; then
# No arguments, default to run stdio
ACTION="run"
MODE="stdio"
else
echo "Usage: $0 [build|run|stdio|sse] [stdio|sse]"
echo " build: Only build the image."
echo " run [stdio|sse]: Build and run (default mode stdio)."
echo " [stdio|sse]: Build and run specified mode."
exit 1
fi
# Load environment variables from .env
if [ -f .env ]; then
echo "Loading environment variables from .env"
export $(grep -v '^#' .env | xargs)
else
echo "Warning: .env file not found. Make sure to provide environment variables directly."
fi
# Check required environment variables
if [ -z "$LOOKER_BASE_URL" ] || [ -z "$LOOKER_CLIENT_ID" ] || [ -z "$LOOKER_CLIENT_SECRET" ]; then
echo "Error: Missing required environment variables."
echo "Please make sure LOOKER_BASE_URL, LOOKER_CLIENT_ID, and LOOKER_CLIENT_SECRET are set."
exit 1
fi
# Stop any running containers
echo "Stopping any existing looker-mcp containers..."
docker-compose down
docker stop $(docker ps -q --filter ancestor=looker-mcp) 2>/dev/null || true
# Build the Docker image
echo "Building Docker images using docker-compose..."
docker-compose build
# Clean up dangling images
echo "Cleaning up any dangling images..."
docker image prune -f
# Exit if only build was requested
if [ "$MODE" = "build-only" ]; then
echo "Build completed. Exiting as requested."
exit 0
fi
# Run container based on mode (only if action wasn't build)
echo "Action: run, Mode: $MODE"
if [ "$MODE" = "sse" ]; then
echo "Running container in SSE mode on port 8000..."
docker-compose up looker-mcp-sse
else # Default to stdio
echo "Running container in stdio mode..."
# Use run --rm for stdio to mimic ephemeral nature
docker-compose run --rm looker-mcp-stdio
fi