Skip to content

Commit d517ee4

Browse files
authored
Lpcox/slim serena image (#544)
2 parents ce87222 + 6e0bdcd commit d517ee4

3 files changed

Lines changed: 27 additions & 47 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ test/serena-mcp-tests/results-gateway/
5454
test/serena-mcp-tests/**/__pycache__/
5555
test/serena-mcp-tests/**/*.pyc
5656
scripts/rebase-github-difc.sh
57+
58+
# Serena cache directories
59+
.serena/
Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
# Serena MCP Server Container Image
2-
# Provides AI-powered code intelligence with support for Python, Java, JavaScript/TypeScript, and Go
1+
# Serena MCP Server Container Image (Slim)
2+
# Optimized for Python, Go, and TypeScript support with minimal image size
33

4+
# Stage 1: Build gopls
5+
FROM golang:1.24-alpine AS gopls-builder
6+
# Pin to gopls v0.17.1 which is compatible with Go 1.24
7+
RUN go install golang.org/x/tools/gopls@v0.17.1
8+
9+
# Stage 2: Final image
410
FROM python:3.11-slim
511

612
# OCI labels for GitHub Container Registry
713
LABEL org.opencontainers.image.title="Serena MCP Server"
8-
LABEL org.opencontainers.image.description="A containerized MCP server with semantic code analysis for Python, Java, JavaScript/TypeScript, and Go"
14+
LABEL org.opencontainers.image.description="A containerized MCP server with semantic code analysis for Python, Go, and TypeScript"
915
LABEL org.opencontainers.image.source="https://github.com/githubnext/gh-aw-mcpg/tree/main/containers/serena-mcp-server"
1016
LABEL org.opencontainers.image.documentation="https://github.com/githubnext/gh-aw-mcpg/blob/main/containers/serena-mcp-server/README.md"
1117
LABEL org.opencontainers.image.url="https://github.com/githubnext/gh-aw-mcpg/pkgs/container/serena-mcp-server"
@@ -14,53 +20,29 @@ LABEL org.opencontainers.image.vendor="GitHub"
1420
# Set working directory
1521
WORKDIR /app
1622

17-
# Install system dependencies required for language servers and build tools
23+
# Install minimal system dependencies
24+
# - git: required for some Serena operations
25+
# - nodejs/npm: for TypeScript language server
26+
# - ca-certificates: for HTTPS
1827
RUN apt-get update && apt-get install -y --no-install-recommends \
19-
# Build essentials
20-
build-essential \
2128
git \
22-
curl \
23-
wget \
24-
# Java Development Kit (for Java language support and compilation)
25-
default-jdk \
26-
# Node.js (for JavaScript/TypeScript language support)
2729
nodejs \
2830
npm \
29-
# Go runtime (for Go language support)
30-
golang-go \
31-
# Additional utilities
3231
ca-certificates \
3332
&& rm -rf /var/lib/apt/lists/* \
34-
&& update-ca-certificates
33+
&& apt-get clean
3534

36-
# Set environment variables for language runtimes
37-
ENV JAVA_HOME=/usr/lib/jvm/default-java
38-
ENV PATH="${JAVA_HOME}/bin:${PATH}"
39-
ENV GOPATH=/go
40-
ENV PATH="${GOPATH}/bin:${PATH}"
35+
# Copy pre-built gopls from builder stage
36+
COPY --from=gopls-builder /go/bin/gopls /usr/local/bin/gopls
4137

42-
# Install Serena MCP server from GitHub using pip
43-
# Serena is a Python package, so we can install it directly
44-
# Try GitHub first, then fall back to PyPI package name if available
38+
# Install Serena MCP server from GitHub
4539
RUN pip install --no-cache-dir git+https://github.com/oraios/serena.git || \
4640
(echo "GitHub installation failed, trying PyPI..." && \
4741
pip install --no-cache-dir serena-agent)
4842

49-
# Install common language servers that Serena may need
50-
# These are installed globally to be available to Serena
51-
RUN npm install -g \
52-
typescript \
53-
typescript-language-server \
54-
&& rm -rf /root/.npm
55-
56-
# Install Python language server (pyright is included in Serena dependencies)
57-
# Additional Python tools
58-
RUN pip install --no-cache-dir \
59-
python-lsp-server \
60-
pylsp-mypy
61-
62-
# Install gopls (Go language server)
63-
RUN go install golang.org/x/tools/gopls@latest
43+
# Install TypeScript language server (minimal)
44+
RUN npm install -g typescript typescript-language-server && \
45+
rm -rf /root/.npm /tmp/*
6446

6547
# Create directories for Serena configuration and caching
6648
RUN mkdir -p /workspace /tmp/serena-cache /root/.serena
@@ -70,30 +52,25 @@ ENV SERENA_WORKSPACE=/workspace
7052
ENV SERENA_CACHE_DIR=/tmp/serena-cache
7153

7254
# Create a dummy project to pre-warm Serena's LSP cache
73-
# This initializes the language servers and caches so they're ready at runtime
74-
# Focus on Python, Go, and TypeScript which are the primary languages for codex context
55+
# Focus on Python, Go, and TypeScript for codex context
7556
RUN mkdir -p /tmp/dummy-project && \
7657
echo 'def hello(): pass' > /tmp/dummy-project/main.py && \
7758
echo 'package main\nfunc main() {}' > /tmp/dummy-project/main.go && \
7859
echo 'export function hello() {}' > /tmp/dummy-project/index.ts
7960

80-
# Pre-index the dummy project to warm up the LSP caches
81-
# Use --language to specify languages non-interactively and --index to index after creation
82-
# This ensures pyright, gopls, and typescript-language-server are initialized
61+
# Pre-index to warm up LSP caches
8362
RUN serena project create /tmp/dummy-project --name dummy \
8463
--language python --language go --language typescript \
8564
--index --log-level INFO --timeout 120 || \
8665
echo "Pre-indexing completed (some warnings may be expected)"
8766

88-
# Clean up the dummy project but keep the caches
67+
# Clean up
8968
RUN rm -rf /tmp/dummy-project
9069

9170
# Expose the workspace directory as a volume mount point
9271
VOLUME ["/workspace"]
9372

9473
# Set default entrypoint to run Serena MCP server
95-
# This will start the MCP server on stdio transport
9674
ENTRYPOINT ["serena-mcp-server"]
9775

98-
# Default arguments (can be overridden)
9976
CMD []

containers/serena-mcp-server/test-startup-time.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export MCP_GATEWAY_API_KEY=$(openssl rand -base64 45 | tr -d '/+=')
3838
export WORKSPACE="${WORKSPACE_ARG:-${PWD}}"
3939

4040
GATEWAY_IMAGE="ghcr.io/githubnext/gh-aw-mcpg:v0.0.84"
41-
SERENA_IMAGE="serena-mcp-server:test"
41+
SERENA_IMAGE="${SERENA_IMAGE:-serena-mcp-server:slim}"
4242

4343
echo "=== Serena Startup Time Test ==="
4444
echo "Gateway image: ${GATEWAY_IMAGE}"

0 commit comments

Comments
 (0)