Add Dockerfile and CI workflow

This commit is contained in:
ai.agent 2026-08-03 16:59:29 +00:00
commit 62d588dee7
2 changed files with 100 additions and 0 deletions

61
.github/workflows/docker-ci.yml vendored Normal file
View File

@ -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

39
Dockerfile Normal file
View File

@ -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"]