From 62d588dee71fba42104b69bb0d643031c978216e Mon Sep 17 00:00:00 2001 From: "ai.agent" Date: Mon, 3 Aug 2026 16:59:29 +0000 Subject: [PATCH] Add Dockerfile and CI workflow --- .github/workflows/docker-ci.yml | 61 +++++++++++++++++++++++++++++++++ Dockerfile | 39 +++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .github/workflows/docker-ci.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml new file mode 100644 index 0000000..66b403f --- /dev/null +++ b/.github/workflows/docker-ci.yml @@ -0,0 +1,61 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools + pip install poetry + poetry config virtualenvs.create false + if [ -f poetry.lock ]; then poetry install --no-dev; else pip install .; fi + pip install flake8 mypy + + - name: Lint with flake8 + run: flake8 . + + - name: Static analysis with mypy + run: mypy . + + - name: Run tests + run: | + pip install pytest + pytest -q + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Docker image + run: | + IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/${{ github.repository_name }}:$(git rev-parse --short HEAD) + docker build -t $IMAGE_TAG . + + - name: Push Docker image + if: success() + run: | + IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/${{ github.repository_name }}:$(git rev-parse --short HEAD) + docker push $IMAGE_TAG diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f702853 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# Dockerfile for MCP server +# Uses Python 3.12 slim image, installs the application and its dependencies + +FROM python:3.12-slim AS base + +# Install system dependencies (if any) +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Create a non-root user +ARG USERNAME=appuser +ARG UID=1000 +RUN adduser --uid ${UID} --disabled-password --gecos "" ${USERNAME} + +# Set working directory +WORKDIR /app + +# Copy only requirements first for caching layers +COPY pyproject.toml poetry.lock* /app/ || true + +# Install poetry (or pip) and dependencies +RUN pip install --upgrade pip setuptools && \ + pip install poetry && \ + poetry config virtualenvs.create false && \ + if [ -f poetry.lock ]; then poetry install --no-dev; else pip install .; fi + +# Copy the rest of the source code +COPY . /app + +# Switch to non-root user +USER ${USERNAME} + +# Expose the service port (adjust if needed) +EXPOSE 8000 + +# Default command – run the FastAPI server (adjust entrypoint as needed) +CMD ["uvicorn", "mcp_server.main:app", "--host", "0.0.0.0", "--port", "8000"]