docker-build.sh•3.67 kB
#!/bin/bash
# CodeCompass MCP Docker Build Script
# Based on patterns from OpenRouter MCP repository
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
# Default values
IMAGE_NAME="codecompass-mcp"
TAG="latest"
DOCKERFILE="Dockerfile"
PUSH_TO_REGISTRY=false
REGISTRY=""
BUILD_ARGS=""
# Function to display usage
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -t, --tag TAG Set image tag (default: latest)"
echo " -f, --file FILE Dockerfile to use (default: Dockerfile)"
echo " -p, --push Push to registry after build"
echo " -r, --registry REG Registry to push to"
echo " --build-arg KEY=VALUE Build argument"
echo " --dev Use development Dockerfile"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Build with default settings"
echo " $0 --dev # Build development image"
echo " $0 -t v1.0.0 --push # Build and push v1.0.0"
echo " $0 --build-arg NODE_ENV=production"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--tag)
TAG="$2"
shift 2
;;
-f|--file)
DOCKERFILE="$2"
shift 2
;;
-p|--push)
PUSH_TO_REGISTRY=true
shift
;;
-r|--registry)
REGISTRY="$2"
shift 2
;;
--build-arg)
BUILD_ARGS="$BUILD_ARGS --build-arg $2"
shift 2
;;
--dev)
DOCKERFILE="Dockerfile.dev"
TAG="dev"
shift
;;
-h|--help)
show_usage
exit 0
;;
*)
echo "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Construct full image name
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
if [ -n "$REGISTRY" ]; then
FULL_IMAGE_NAME="${REGISTRY}/${FULL_IMAGE_NAME}"
fi
echo -e "${BLUE}CodeCompass MCP Docker Build${NC}"
echo -e "${BLUE}=============================${NC}"
echo "Image: $FULL_IMAGE_NAME"
echo "Dockerfile: $DOCKERFILE"
echo "Build args: $BUILD_ARGS"
echo ""
# Check if Dockerfile exists
if [ ! -f "$DOCKERFILE" ]; then
echo -e "${RED}Error: Dockerfile '$DOCKERFILE' not found${NC}"
exit 1
fi
# Build the image
echo -e "${YELLOW}Building Docker image...${NC}"
docker build \
-t "$FULL_IMAGE_NAME" \
-f "$DOCKERFILE" \
$BUILD_ARGS \
.
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Build successful${NC}"
# Show image info
echo -e "${BLUE}Image information:${NC}"
docker images "$FULL_IMAGE_NAME"
# Push to registry if requested
if [ "$PUSH_TO_REGISTRY" = true ]; then
echo -e "${YELLOW}Pushing to registry...${NC}"
docker push "$FULL_IMAGE_NAME"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Push successful${NC}"
else
echo -e "${RED}✗ Push failed${NC}"
exit 1
fi
fi
echo -e "${GREEN}✓ Docker build completed successfully${NC}"
echo ""
echo "To run the container:"
echo " docker run -d --name codecompass-mcp $FULL_IMAGE_NAME"
echo ""
echo "To run with environment variables:"
echo " docker run -d --name codecompass-mcp \\"
echo " -e GITHUB_TOKEN=your_token \\"
echo " -e OPENROUTER_API_KEY=your_key \\"
echo " $FULL_IMAGE_NAME"
else
echo -e "${RED}✗ Build failed${NC}"
exit 1
fi