Przeglądaj źródła

Add Docker support for containerized deployment

- Add multi-stage Dockerfile with Node.js 18 Alpine
- Add docker-compose.yml for easy deployment
- Add .dockerignore to optimize build context
- Enhance .env.example with detailed configuration comments
- Update README with comprehensive Docker setup and usage instructions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude (AgentBox) 9 miesięcy temu
rodzic
commit
ba26edc0f6
5 zmienionych plików z 221 dodań i 1 usunięć
  1. 46 0
      .dockerignore
  2. 9 1
      .env.example
  3. 52 0
      Dockerfile
  4. 74 0
      README.md
  5. 40 0
      docker-compose.yml

+ 46 - 0
.dockerignore

@@ -0,0 +1,46 @@
+# Node
+node_modules
+npm-debug.log
+yarn-error.log
+
+# Build output
+dist
+
+# Environment files
+.env
+.env.local
+.env.*.local
+
+# Git
+.git
+.gitignore
+.gitmodules
+
+# Documentation
+*.md
+docs-api
+
+# IDE
+.vscode
+.idea
+*.swp
+*.swo
+*~
+
+# OS
+.DS_Store
+Thumbs.db
+
+# Testing
+coverage
+.nyc_output
+
+# Docker
+Dockerfile
+.dockerignore
+docker-compose.yml
+
+# CI/CD
+.github
+.gitlab-ci.yml
+.travis.yml

+ 9 - 1
.env.example

@@ -1,3 +1,11 @@
-# Gogs Server Configuration
+# Gogs MCP Server Configuration
+
+# Required: URL of your Gogs server instance
 GOGS_SERVER_URL=https://your-gogs-server.com
+
+# Optional but recommended: Gogs access token for authenticated operations
+# Generate this from your Gogs instance: Settings → Applications → Generate New Token
 GOGS_ACCESS_TOKEN=your-access-token-here
+
+# Node environment (automatically set in Docker, but can override)
+# NODE_ENV=production

+ 52 - 0
Dockerfile

@@ -0,0 +1,52 @@
+# Multi-stage build for optimized image size
+FROM node:18-alpine AS builder
+
+WORKDIR /app
+
+# Copy package files
+COPY package*.json ./
+
+# Install dependencies
+RUN npm ci
+
+# Copy source files
+COPY tsconfig.json ./
+COPY src ./src
+
+# Build the project
+RUN npm run build
+
+# Production stage
+FROM node:18-alpine
+
+WORKDIR /app
+
+# Copy package files
+COPY package*.json ./
+
+# Install only production dependencies
+RUN npm ci --only=production && \
+    npm cache clean --force
+
+# Copy built files from builder stage
+COPY --from=builder /app/dist ./dist
+
+# Create a non-root user
+RUN addgroup -g 1001 -S nodejs && \
+    adduser -S nodejs -u 1001
+
+# Change ownership of the app directory
+RUN chown -R nodejs:nodejs /app
+
+# Switch to non-root user
+USER nodejs
+
+# Set environment variables
+ENV NODE_ENV=production
+
+# The server uses stdio transport, so it doesn't need a port
+# But we'll expose one in case needed for health checks or future features
+EXPOSE 3000
+
+# Start the server
+CMD ["node", "dist/index.js"]

+ 74 - 0
README.md

@@ -33,6 +33,10 @@ This MCP server provides tools to:
 - A Gogs server instance
 - Gogs access token (optional, but recommended for authenticated access)
 
+**OR**
+
+- Docker and Docker Compose (for containerized deployment)
+
 ### Setup
 
 1. Clone this repository:
@@ -51,6 +55,36 @@ This MCP server provides tools to:
    npm run build
    ```
 
+### Docker Setup
+
+1. Clone this repository:
+   ```bash
+   git clone ssh://git@207.154.220.231:10022/claude/gogs-mcp.git
+   cd gogs-mcp
+   ```
+
+2. Create a `.env` file from the example:
+   ```bash
+   cp .env.example .env
+   ```
+
+3. Edit `.env` and configure your Gogs server URL and access token:
+   ```bash
+   GOGS_SERVER_URL=https://your-gogs-server.com
+   GOGS_ACCESS_TOKEN=your-access-token-here
+   ```
+
+4. Build and run with Docker Compose:
+   ```bash
+   docker-compose up -d
+   ```
+
+   Or build the Docker image manually:
+   ```bash
+   docker build -t gogs-mcp-server .
+   docker run --env-file .env gogs-mcp-server
+   ```
+
 ## Configuration
 
 ### Generate Gogs Access Token
@@ -111,6 +145,46 @@ export GOGS_ACCESS_TOKEN=your-access-token-here
 npm start
 ```
 
+### With Docker
+
+You can use the Docker image with MCP clients by mounting it as a command:
+
+```json
+{
+  "mcpServers": {
+    "gogs": {
+      "command": "docker",
+      "args": [
+        "run",
+        "--rm",
+        "-i",
+        "-e", "GOGS_SERVER_URL=https://your-gogs-server.com",
+        "-e", "GOGS_ACCESS_TOKEN=your-access-token-here",
+        "gogs-mcp-server:latest"
+      ]
+    }
+  }
+}
+```
+
+Or using docker-compose:
+
+```json
+{
+  "mcpServers": {
+    "gogs": {
+      "command": "docker-compose",
+      "args": [
+        "-f", "/absolute/path/to/gogs-mcp-server/docker-compose.yml",
+        "run",
+        "--rm",
+        "gogs-mcp-server"
+      ]
+    }
+  }
+}
+```
+
 ## Available Tools
 
 ### User Tools

+ 40 - 0
docker-compose.yml

@@ -0,0 +1,40 @@
+version: '3.8'
+
+services:
+  gogs-mcp-server:
+    build:
+      context: .
+      dockerfile: Dockerfile
+    image: gogs-mcp-server:latest
+    container_name: gogs-mcp-server
+    environment:
+      - GOGS_SERVER_URL=${GOGS_SERVER_URL}
+      - GOGS_ACCESS_TOKEN=${GOGS_ACCESS_TOKEN}
+      - NODE_ENV=production
+    # Since this is an MCP server using stdio transport,
+    # it's typically run as a subprocess rather than a standalone service.
+    # However, you can keep it running for testing or health checks.
+    stdin_open: true
+    tty: true
+    restart: unless-stopped
+    # Uncomment if you need to expose a port for health checks
+    # ports:
+    #   - "3000:3000"
+    # Uncomment if you need to mount local files for development
+    # volumes:
+    #   - ./dist:/app/dist:ro
+
+  # Optional: Include a Gogs server for local development/testing
+  # Uncomment the section below if you want to run Gogs locally
+  # gogs:
+  #   image: gogs/gogs:latest
+  #   container_name: gogs-server
+  #   ports:
+  #     - "10022:22"
+  #     - "3000:3000"
+  #   volumes:
+  #     - gogs-data:/data
+  #   restart: unless-stopped
+
+# volumes:
+#   gogs-data: