From 4cd75361d60ae99682f527b184eafa2913b818ea Mon Sep 17 00:00:00 2001 From: vsoch Date: Thu, 15 Jan 2026 12:33:30 -0800 Subject: [PATCH] ci: docker build This adds a Dockerfile and automation to deploy alongside the repository in GitHub packages. We can next create Kubernetes manifests and test on premises with podman, etc. Although I am not sure I want to do that. Signed-off-by: vsoch --- .github/workflows/build-deploy.yaml | 76 +++++++++++++++++++++++++++++ Dockerfile | 24 +++++++++ Makefile | 39 +++++++++++++++ README.md | 21 +++++++- mcpserver/cli/start.py | 2 +- mcpserver/version.py | 2 +- 6 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build-deploy.yaml create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml new file mode 100644 index 0000000..41cde99 --- /dev/null +++ b/.github/workflows/build-deploy.yaml @@ -0,0 +1,76 @@ +name: build-deploy mcpserver + +on: + pull_request: {} + release: + types: [published] + push: + branches: + - main + +jobs: + build-arm: + if: (github.event_name != 'pull_request') + runs-on: ubuntu-latest + name: make and build arm + env: + container: ghcr.io/converged-computing/mcp-server + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: GHCR Login + if: (github.event_name != 'pull_request') + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Add custom buildx ARM builder + run: | + docker buildx create --name armbuilder + docker buildx use armbuilder + docker buildx inspect --bootstrap + + - name: Build Container + run: make arm + + - name: Tag Release Image + if: (github.event_name == 'release') + run: | + tag=${GITHUB_REF#refs/tags/} + echo "Tagging and releasing ${{ env.container }}:${tag}" + docker tag ${{ env.container }}:latest ${{ env.container }}:${tag} + + - name: Deploy Container + run: make push + + build: + permissions: + packages: write + runs-on: ubuntu-latest + name: build + env: + container: ghcr.io/converged-computing/mcp-server + steps: + - uses: actions/checkout@v4 + - name: Build Container + run: make + - name: Tag Release Image + if: (github.event_name == 'release') + run: | + tag=${GITHUB_REF#refs/tags/} + echo "Tagging and releasing ${{ env.container }}:${tag}" + docker tag ${{ env.container }}:latest ${{ env.container }}:${tag} + + - name: GHCR Login + if: (github.event_name != 'pull_request') + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy Container + if: (github.event_name != 'pull_request') + run: make push diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d63241 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM python:3.12-slim + +# Install system-level dependencies for HPC introspection +RUN apt-get update && apt-get install -y --no-install-recommends \ + hwloc \ + libhwloc-dev \ + gcc \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PYTHONPATH=/code + +WORKDIR /code +COPY . /code +RUN pip install --no-cache-dir . +EXPOSE 8089 +ENTRYPOINT ["mcpserver", "start"] + +# Default command if no arguments are provided. +# We bind to 0.0.0.0 so the server is reachable outside the container. +CMD ["-t", "http", "--host", "0.0.0.0", "--port", "8089"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f564c40 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +IMAGE_NAME ?= ghcr.io/converged-computing/mcp-server +IMAGE_TAG ?= latest +FULL_IMAGE_NAME = $(IMAGE_NAME):$(IMAGE_TAG) +FULL_ARM_IMAGE = $(IMAGE_NAME):arm +DOCKERFILE_PATH = Dockerfile +BUILD_CONTEXT = . + +# Default target: builds the Docker image +all: build + +# Build the Docker image +build: + @echo "Building Docker image $(FULL_IMAGE_NAME)..." + docker build \ + -f $(DOCKERFILE_PATH) \ + -t $(FULL_IMAGE_NAME) \ + . + @echo "Docker image $(FULL_IMAGE_NAME) built successfully." + +# Push the docker image +push: + @echo "Pushing image $(FULL_IMAGE_NAME)..." + docker push $(IMAGE_NAME) --all-tags + +# Remove the image (clean with rmi) +clean: + @echo "Removing Docker image $(FULL_IMAGE_NAME)..." + docker rmi $(FULL_IMAGE_NAME) || true + @echo "Docker image $(FULL_IMAGE_NAME) removed (if it existed)." + +arm: + @echo "Building arm Docker image $(FULL_IMAGE_NAME)..." + docker build \ + -f $(DOCKERFILE_PATH) \ + -t $(FULL_ARM_IMAGE) \ + . + @echo "Docker image $(FULL_ARM_IMAGE) built successfully." + +.PHONY: all build push clean arm diff --git a/README.md b/README.md index 6895ba3..b9124f6 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,26 @@ It is recommended to open in VSCode container. Then install: pip install --break-system-packages -e . ``` +### Docker + +To build the Docker container: + +```bash +make +``` + +To run a dummy example: + +```bash +docker run -p 8089:8089 -it ghcr.io/converged-computing/mcp-server:latest +``` + +And then interact from the outside: + +```bash +python3 ./examples/echo/test_echo.py +``` + ### Environment The following variables can be set in the environment. @@ -68,7 +88,6 @@ The following variables can be set in the environment. ## Examples - ### Simple Echo Start the server in one terminal. Export `MCPSERVER_TOKEN` if you want some client to use simple token auth. diff --git a/mcpserver/cli/start.py b/mcpserver/cli/start.py index 754e7f3..442b6c7 100644 --- a/mcpserver/cli/start.py +++ b/mcpserver/cli/start.py @@ -56,7 +56,7 @@ def main(args, extra, **kwargs): # stdio does not! else: - mcp.run(transport=cfg.transport) + mcp.run(transport=cfg.server.transport) # For testing we usually control+C, let's not make it ugly except KeyboardInterrupt: diff --git a/mcpserver/version.py b/mcpserver/version.py index 222c295..c31f7a2 100644 --- a/mcpserver/version.py +++ b/mcpserver/version.py @@ -1,7 +1,7 @@ __version__ = "0.0.1" AUTHOR = "Vanessa Sochat" AUTHOR_EMAIL = "vsoch@users.noreply.github.com" -NAME = "mcp-node" +NAME = "mcp-serve" PACKAGE_URL = "https://github.com/converged-computing/mcp-server" KEYWORDS = "cluster, orchestration, mcp, server, agents" DESCRIPTION = "Agentic server to support MCP tools for science"