Skip to content

Conversation

@imprvhub
Copy link
Owner

This PR introduces comprehensive support for deploying the mcp-domain-availability server to Google Cloud Run. Previously, running the server in a containerized environment or on serverless platforms required manual configuration. This enhancement provides a streamlined, zero-clone deployment process for Cloud Run, leveraging Docker for containerization and a dedicated deployment script.

Changes Made

  1. Google Cloud Run Integration:
    • Implemented necessary configurations to make the application compatible with Google Cloud Run's serverless environment.
    • Ensured the application can dynamically bind to the port provided by the Cloud Run environment variable (PORT).
  2. Docker Containerization:
    • Updated the Dockerfile to create a production-ready Docker image for the mcp-domain-availability server.
    • Defined a clear ENTRYPOINT to execute the application within the container.
  3. Automated Deployment Script:
    • Introduced a deploy.sh script to automate the build and deployment process to Google Cloud Run, simplifying the user experience.
  4. Documentation Updates:
    • Modified README.md to include detailed instructions for building the Docker image and deploying the application to Google Cloud Run.

Technical Implementation

The core of this implementation revolves around adapting the application for containerized serverless deployment and providing an automated deployment mechanism.

1. Dynamic Port Binding (src/mcp_domain_availability/main.py):
The application now retrieves the listening port from the PORT environment variable, defaulting to 8080 if not set. This is crucial for Cloud Run, which assigns a dynamic port to containers.

import os
# ... other imports and application setup

# In main.py, where the server is initialized:
port = int(os.getenv("PORT", 8080))

# Example of how the port might be used (actual implementation may vary):
# if __name__ == "__main__":
#     app.run(host="0.0.0.0", port=port)

2. Dockerfile for Cloud Run:
The Dockerfile is configured to build a lightweight image, install dependencies, and set the entry point for the application.

# Use a slim Python base image for smaller size
FROM python:3.9-slim-buster

# Set the working directory inside the container
WORKDIR /app

# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code
COPY . .

# Expose the port that the application will listen on.
# Cloud Run will map external traffic to this port.
EXPOSE 8080

# Command to run the application when the container starts
ENTRYPOINT ["python", "src/mcp_domain_availability/main.py"]

3. Google Cloud Run Deployment Script (deploy.sh):
The deploy.sh script automates the container image build, tagging, and deployment to Google Cloud Run.

#!/bin/bash

# Exit immediately if a command exits with a non-zero status.
set -e

# --- Configuration ---
PROJECT_ID="your-gcp-project-id" # <<< IMPORTANT: Replace with your GCP Project ID
SERVICE_NAME="mcp-domain-availability"
REGION="us-central1" # Choose your desired GCP region (e.g., us-central1, europe-west1)
# --- End Configuration ---

echo "Authenticating Docker to Google Container Registry..."
gcloud auth configure-docker

echo "Building Docker image: gcr.io/${PROJECT_ID}/${SERVICE_NAME}..."
docker build -t gcr.io/${PROJECT_ID}/${SERVICE_NAME} .

echo "Pushing Docker image to Google Container Registry..."
docker push gcr.io/${PROJECT_ID}/${SERVICE_NAME}

echo "Deploying service '${SERVICE_NAME}' to Google Cloud Run in region '${REGION}'..."
gcloud run deploy ${SERVICE_NAME} \
  --image gcr.io/${PROJECT_ID}/${SERVICE_NAME} \
  --platform managed \
  --region ${REGION} \
  --allow-unauthenticated \
  --project ${PROJECT_ID} \
  --port 8080 # The port your container listens on (matches EXPOSE in Dockerfile)

echo "Deployment complete!"

Breaking Changes / Important Notes

  • This PR introduces new deployment mechanisms but does not alter the core functionality or API of the mcp-domain-availability server. Existing methods of running the server (e.g., locally via uvx) remain unaffected.
  • Users deploying to Google Cloud Run will need a Google Cloud Platform account, a project, and the gcloud CLI installed and configured.
  • The deploy.sh script requires modification of the PROJECT_ID and REGION variables to match the user's GCP setup.
  • Ensure the Cloud Run API and Container Registry API are enabled in your GCP project before deployment.

Testing

To test these changes, follow these steps:

  1. Prerequisites:
    • Ensure you have Docker installed and running.
    • Install and configure the gcloud CLI, authenticating to your Google Cloud project.
    • Enable the Cloud Run API and Container Registry API in your GCP project.
  2. Build Docker Image Locally:
    docker build -t mcp-domain-availability .
  3. Run Docker Image Locally (Optional):
    docker run -p 8080:8080 mcp-domain-availability
    Verify the server is accessible at http://localhost:8080 by sending a test request.
  4. Deploy to Google Cloud Run:
    • Edit the deploy.sh script and replace your-gcp-project-id with your actual GCP project ID. Adjust the REGION variable if desired.
    • Make the script executable: chmod +x deploy.sh
    • Execute the deployment script:
      ./deploy.sh
    • Follow any prompts from the gcloud CLI during the deployment process.
  5. Verify Deployment:
    • Once deployed, the gcloud CLI will output the service URL (e.g., https://mcp-domain-availability-xxxxxx-uc.a.run.app).
    • Access the provided URL in your browser or via curl to confirm the mcp-domain-availability server is running and responsive.
    • Test domain availability checks through the Cloud Run endpoint to ensure full functionality.

Impact

This enhancement significantly broadens the deployment options for mcp-domain-availability, making it easier for users to host a highly available and scalable instance without managing underlying infrastructure. By leveraging Google Cloud Run, users benefit from:

  • Serverless Scalability: Automatic scaling up and down based on traffic, including scaling to zero when idle, optimizing resource usage.
  • Managed Environment: Reduced operational burden as Google manages the underlying infrastructure, allowing users to focus on the application.
  • Simplified Deployment: The deploy.sh script provides a one-command deployment experience after initial setup, streamlining the CI/CD process.

Co-authored-by: nilsreichardt nilsreichardt@users.noreply.github.com
Original implementation and GCP deploy process by @nilsreichardt (see referenced commits)

…, dynamic port, and deployment script

Co-authored-by: nilsreichardt <nilsreichardt@users.noreply.github.com>
Original implementation and GCP deploy process by @nilsreichardt (see referenced commits)
@imprvhub imprvhub self-assigned this Oct 29, 2025
@imprvhub imprvhub added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 29, 2025
@imprvhub imprvhub linked an issue Oct 29, 2025 that may be closed by this pull request
@imprvhub imprvhub merged commit 0366b8c into main Oct 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docker documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instructions for running this in Docker

2 participants