Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +80 -13
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# Dockerfile for Hugging Face Spaces deployment of Coral Server
|
| 2 |
FROM gradle:8.5-jdk21 AS build
|
| 3 |
|
| 4 |
# Set working directory
|
|
@@ -10,17 +10,30 @@ RUN git clone https://github.com/Coral-Protocol/coral-server.git .
|
|
| 10 |
# Build the application
|
| 11 |
RUN gradle build --no-daemon -x test
|
| 12 |
|
| 13 |
-
# Create
|
| 14 |
RUN mkdir -p /coral-config && \
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Runtime stage
|
| 18 |
FROM openjdk:21-jdk-slim
|
| 19 |
|
| 20 |
-
# Install required packages
|
| 21 |
RUN apt-get update && apt-get install -y \
|
| 22 |
curl \
|
| 23 |
git \
|
|
|
|
| 24 |
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
|
| 26 |
# Set working directory
|
|
@@ -28,16 +41,70 @@ WORKDIR /app
|
|
| 28 |
|
| 29 |
# Copy built application from build stage
|
| 30 |
COPY --from=build /app/build/libs/*.jar app.jar
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
# Create
|
| 36 |
-
RUN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Create non-root user (required by HF Spaces)
|
| 39 |
RUN useradd -m -u 1000 user && \
|
| 40 |
-
chown -R user:user /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
USER user
|
| 42 |
|
| 43 |
# Set environment variables for HF Spaces
|
|
@@ -50,9 +117,9 @@ ENV HOME=/home/user \
|
|
| 50 |
# HF Spaces expects port 7860
|
| 51 |
EXPOSE 7860
|
| 52 |
|
| 53 |
-
# Health check
|
| 54 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 55 |
-
CMD curl -f http://localhost:7860/ || exit 1
|
| 56 |
|
| 57 |
-
# Start
|
| 58 |
-
CMD ["
|
|
|
|
| 1 |
+
# MCP-Compliant Dockerfile for Hugging Face Spaces deployment of Coral Server
|
| 2 |
FROM gradle:8.5-jdk21 AS build
|
| 3 |
|
| 4 |
# Set working directory
|
|
|
|
| 10 |
# Build the application
|
| 11 |
RUN gradle build --no-daemon -x test
|
| 12 |
|
| 13 |
+
# Create configuration files if they don't exist
|
| 14 |
RUN mkdir -p /coral-config && \
|
| 15 |
+
if [ ! -f src/main/resources/application.yaml ]; then \
|
| 16 |
+
echo "server:" > /coral-config/application.yaml && \
|
| 17 |
+
echo " port: 7860" >> /coral-config/application.yaml && \
|
| 18 |
+
echo "mcp:" >> /coral-config/application.yaml && \
|
| 19 |
+
echo " transport: sse" >> /coral-config/application.yaml; \
|
| 20 |
+
else \
|
| 21 |
+
cp src/main/resources/application.yaml /coral-config/; \
|
| 22 |
+
fi && \
|
| 23 |
+
if [ ! -f src/main/resources/registry.toml ]; then \
|
| 24 |
+
touch /coral-config/registry.toml; \
|
| 25 |
+
else \
|
| 26 |
+
cp src/main/resources/registry.toml /coral-config/; \
|
| 27 |
+
fi
|
| 28 |
|
| 29 |
# Runtime stage
|
| 30 |
FROM openjdk:21-jdk-slim
|
| 31 |
|
| 32 |
+
# Install required packages including nginx for reverse proxy
|
| 33 |
RUN apt-get update && apt-get install -y \
|
| 34 |
curl \
|
| 35 |
git \
|
| 36 |
+
nginx \
|
| 37 |
&& rm -rf /var/lib/apt/lists/*
|
| 38 |
|
| 39 |
# Set working directory
|
|
|
|
| 41 |
|
| 42 |
# Copy built application from build stage
|
| 43 |
COPY --from=build /app/build/libs/*.jar app.jar
|
| 44 |
+
COPY --from=build /coral-config /app/coral-config
|
| 45 |
|
| 46 |
+
# Create nginx config for MCP proxying
|
| 47 |
+
RUN echo 'server {' > /etc/nginx/sites-available/mcp-proxy && \
|
| 48 |
+
echo ' listen 7860;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 49 |
+
echo ' server_name localhost;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 50 |
+
echo '' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 51 |
+
echo ' # MCP SSE endpoint' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 52 |
+
echo ' location /sse {' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 53 |
+
echo ' proxy_pass http://127.0.0.1:5555;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 54 |
+
echo ' proxy_http_version 1.1;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 55 |
+
echo ' proxy_set_header Upgrade $http_upgrade;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 56 |
+
echo ' proxy_set_header Connection "upgrade";' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 57 |
+
echo ' proxy_set_header Host $host;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 58 |
+
echo ' proxy_cache_bypass $http_upgrade;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 59 |
+
echo ' proxy_buffering off;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 60 |
+
echo ' proxy_read_timeout 86400;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 61 |
+
echo ' }' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 62 |
+
echo '' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 63 |
+
echo ' # Proxy all MCP requests to Coral Server' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 64 |
+
echo ' location / {' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 65 |
+
echo ' proxy_pass http://127.0.0.1:5555;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 66 |
+
echo ' proxy_http_version 1.1;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 67 |
+
echo ' proxy_set_header Upgrade $http_upgrade;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 68 |
+
echo ' proxy_set_header Connection "upgrade";' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 69 |
+
echo ' proxy_set_header Host $host;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 70 |
+
echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 71 |
+
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 72 |
+
echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 73 |
+
echo ' proxy_cache_bypass $http_upgrade;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 74 |
+
echo ' proxy_buffering off;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 75 |
+
echo ' proxy_read_timeout 86400;' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 76 |
+
echo ' }' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 77 |
+
echo '}' >> /etc/nginx/sites-available/mcp-proxy && \
|
| 78 |
+
ln -s /etc/nginx/sites-available/mcp-proxy /etc/nginx/sites-enabled/ && \
|
| 79 |
+
rm /etc/nginx/sites-enabled/default
|
| 80 |
|
| 81 |
+
# Create startup script
|
| 82 |
+
RUN echo '#!/bin/bash' > /app/start.sh && \
|
| 83 |
+
echo 'set -e' >> /app/start.sh && \
|
| 84 |
+
echo '' >> /app/start.sh && \
|
| 85 |
+
echo '# Start nginx in background' >> /app/start.sh && \
|
| 86 |
+
echo 'nginx -g "daemon off;" &' >> /app/start.sh && \
|
| 87 |
+
echo 'NGINX_PID=$!' >> /app/start.sh && \
|
| 88 |
+
echo '' >> /app/start.sh && \
|
| 89 |
+
echo '# Start Coral Server on port 5555' >> /app/start.sh && \
|
| 90 |
+
echo 'java -Xmx1g -Xms512m -jar app.jar --sse-server 5555 &' >> /app/start.sh && \
|
| 91 |
+
echo 'CORAL_PID=$!' >> /app/start.sh && \
|
| 92 |
+
echo '' >> /app/start.sh && \
|
| 93 |
+
echo '# Wait for either process to exit' >> /app/start.sh && \
|
| 94 |
+
echo 'wait -n $NGINX_PID $CORAL_PID' >> /app/start.sh && \
|
| 95 |
+
echo '' >> /app/start.sh && \
|
| 96 |
+
echo '# Kill both processes if one exits' >> /app/start.sh && \
|
| 97 |
+
echo 'kill $NGINX_PID $CORAL_PID 2>/dev/null || true' >> /app/start.sh && \
|
| 98 |
+
chmod +x /app/start.sh
|
| 99 |
|
| 100 |
# Create non-root user (required by HF Spaces)
|
| 101 |
RUN useradd -m -u 1000 user && \
|
| 102 |
+
chown -R user:user /app && \
|
| 103 |
+
chown -R user:user /var/log/nginx && \
|
| 104 |
+
chown -R user:user /var/lib/nginx && \
|
| 105 |
+
touch /var/run/nginx.pid && \
|
| 106 |
+
chown user:user /var/run/nginx.pid
|
| 107 |
+
|
| 108 |
USER user
|
| 109 |
|
| 110 |
# Set environment variables for HF Spaces
|
|
|
|
| 117 |
# HF Spaces expects port 7860
|
| 118 |
EXPOSE 7860
|
| 119 |
|
| 120 |
+
# Health check for the proxied service
|
| 121 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 122 |
+
CMD curl -f http://localhost:7860/devmode/exampleApplication/privkey/session1/sse || exit 1
|
| 123 |
|
| 124 |
+
# Start both nginx proxy and Coral Server
|
| 125 |
+
CMD ["/app/start.sh"]
|