Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +92 -62
Dockerfile
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 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
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
# Clone the Coral Server repository
|
|
@@ -10,11 +9,11 @@ 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 configuration files
|
| 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:
|
| 18 |
echo "mcp:" >> /coral-config/application.yaml && \
|
| 19 |
echo " transport: sse" >> /coral-config/application.yaml; \
|
| 20 |
else \
|
|
@@ -29,97 +28,128 @@ RUN mkdir -p /coral-config && \
|
|
| 29 |
# Runtime stage
|
| 30 |
FROM openjdk:21-jdk-slim
|
| 31 |
|
| 32 |
-
# Install required packages
|
| 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
|
| 40 |
WORKDIR /app
|
| 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 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
echo '
|
| 59 |
-
echo '
|
| 60 |
-
echo '
|
| 61 |
-
echo '
|
| 62 |
-
echo '' >> /etc/nginx/
|
| 63 |
-
echo '
|
| 64 |
-
echo '
|
| 65 |
-
echo '
|
| 66 |
-
echo '
|
| 67 |
-
echo '
|
| 68 |
-
echo '
|
| 69 |
-
echo '
|
| 70 |
-
echo '
|
| 71 |
-
echo '
|
| 72 |
-
echo '
|
| 73 |
-
echo '
|
| 74 |
-
echo '
|
| 75 |
-
echo '
|
| 76 |
-
echo '
|
| 77 |
-
echo '
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 '
|
| 86 |
-
echo '
|
| 87 |
-
echo 'NGINX_PID=$!' >> /app/start.sh && \
|
| 88 |
echo '' >> /app/start.sh && \
|
| 89 |
-
echo '# Start Coral Server
|
| 90 |
-
echo '
|
| 91 |
echo 'CORAL_PID=$!' >> /app/start.sh && \
|
| 92 |
echo '' >> /app/start.sh && \
|
| 93 |
-
echo '# Wait for
|
| 94 |
-
echo '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
echo '' >> /app/start.sh && \
|
| 96 |
-
echo '
|
| 97 |
-
echo '
|
| 98 |
chmod +x /app/start.sh
|
| 99 |
|
| 100 |
-
#
|
| 101 |
-
RUN
|
| 102 |
-
chown -R user:user /
|
| 103 |
-
|
| 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
|
| 111 |
ENV HOME=/home/user \
|
| 112 |
PATH=/home/user/.local/bin:$PATH \
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
CONFIG_PATH=/app/coral-config/
|
| 116 |
|
| 117 |
# HF Spaces expects port 7860
|
| 118 |
EXPOSE 7860
|
| 119 |
|
| 120 |
-
# Health check
|
| 121 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 122 |
-
CMD curl -f http://localhost:7860/
|
| 123 |
|
| 124 |
# Start both nginx proxy and Coral Server
|
| 125 |
CMD ["/app/start.sh"]
|
|
|
|
| 1 |
# MCP-Compliant Dockerfile for Hugging Face Spaces deployment of Coral Server
|
| 2 |
FROM gradle:8.5-jdk21 AS build
|
| 3 |
|
|
|
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
# Clone the Coral Server repository
|
|
|
|
| 9 |
# Build the application
|
| 10 |
RUN gradle build --no-daemon -x test
|
| 11 |
|
| 12 |
+
# Create configuration files
|
| 13 |
RUN mkdir -p /coral-config && \
|
| 14 |
if [ ! -f src/main/resources/application.yaml ]; then \
|
| 15 |
echo "server:" > /coral-config/application.yaml && \
|
| 16 |
+
echo " port: 5555" >> /coral-config/application.yaml && \
|
| 17 |
echo "mcp:" >> /coral-config/application.yaml && \
|
| 18 |
echo " transport: sse" >> /coral-config/application.yaml; \
|
| 19 |
else \
|
|
|
|
| 28 |
# Runtime stage
|
| 29 |
FROM openjdk:21-jdk-slim
|
| 30 |
|
| 31 |
+
# Install required packages
|
| 32 |
RUN apt-get update && apt-get install -y \
|
| 33 |
curl \
|
| 34 |
git \
|
| 35 |
nginx \
|
| 36 |
&& rm -rf /var/lib/apt/lists/*
|
| 37 |
|
|
|
|
| 38 |
WORKDIR /app
|
| 39 |
|
| 40 |
# Copy built application from build stage
|
| 41 |
COPY --from=build /app/build/libs/*.jar app.jar
|
| 42 |
+
COPY --from=build /app/build /app/build
|
| 43 |
COPY --from=build /coral-config /app/coral-config
|
| 44 |
+
COPY --from=build /app/gradlew /app/gradlew
|
| 45 |
+
COPY --from=build /app/gradle /app/gradle
|
| 46 |
+
|
| 47 |
+
# Create user first (before modifying files)
|
| 48 |
+
RUN useradd -m -u 1000 user
|
| 49 |
+
|
| 50 |
+
# Configure nginx for non-root operation
|
| 51 |
+
RUN mkdir -p /var/cache/nginx /var/log/nginx /var/lib/nginx /var/run && \
|
| 52 |
+
chown -R user:user /var/cache/nginx /var/log/nginx /var/lib/nginx /var/run && \
|
| 53 |
+
chmod -R 755 /var/cache/nginx /var/log/nginx /var/lib/nginx /var/run
|
| 54 |
+
|
| 55 |
+
# Create nginx config that works with non-root user
|
| 56 |
+
RUN echo 'daemon off;' > /etc/nginx/nginx.conf && \
|
| 57 |
+
echo 'user user;' >> /etc/nginx/nginx.conf && \
|
| 58 |
+
echo 'worker_processes 1;' >> /etc/nginx/nginx.conf && \
|
| 59 |
+
echo 'error_log /var/log/nginx/error.log warn;' >> /etc/nginx/nginx.conf && \
|
| 60 |
+
echo 'pid /var/run/nginx.pid;' >> /etc/nginx/nginx.conf && \
|
| 61 |
+
echo '' >> /etc/nginx/nginx.conf && \
|
| 62 |
+
echo 'events {' >> /etc/nginx/nginx.conf && \
|
| 63 |
+
echo ' worker_connections 1024;' >> /etc/nginx/nginx.conf && \
|
| 64 |
+
echo '}' >> /etc/nginx/nginx.conf && \
|
| 65 |
+
echo '' >> /etc/nginx/nginx.conf && \
|
| 66 |
+
echo 'http {' >> /etc/nginx/nginx.conf && \
|
| 67 |
+
echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf && \
|
| 68 |
+
echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf && \
|
| 69 |
+
echo ' sendfile on;' >> /etc/nginx/nginx.conf && \
|
| 70 |
+
echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf && \
|
| 71 |
+
echo '' >> /etc/nginx/nginx.conf && \
|
| 72 |
+
echo ' server {' >> /etc/nginx/nginx.conf && \
|
| 73 |
+
echo ' listen 7860;' >> /etc/nginx/nginx.conf && \
|
| 74 |
+
echo ' server_name _;' >> /etc/nginx/nginx.conf && \
|
| 75 |
+
echo '' >> /etc/nginx/nginx.conf && \
|
| 76 |
+
echo ' # Root endpoint' >> /etc/nginx/nginx.conf && \
|
| 77 |
+
echo ' location = / {' >> /etc/nginx/nginx.conf && \
|
| 78 |
+
echo ' return 200 "Coral Server is running";' >> /etc/nginx/nginx.conf && \
|
| 79 |
+
echo ' add_header Content-Type text/plain;' >> /etc/nginx/nginx.conf && \
|
| 80 |
+
echo ' }' >> /etc/nginx/nginx.conf && \
|
| 81 |
+
echo '' >> /etc/nginx/nginx.conf && \
|
| 82 |
+
echo ' # SSE endpoint for MCP' >> /etc/nginx/nginx.conf && \
|
| 83 |
+
echo ' location /devmode/ {' >> /etc/nginx/nginx.conf && \
|
| 84 |
+
echo ' proxy_pass http://127.0.0.1:5555;' >> /etc/nginx/nginx.conf && \
|
| 85 |
+
echo ' proxy_http_version 1.1;' >> /etc/nginx/nginx.conf && \
|
| 86 |
+
echo ' proxy_set_header Upgrade $http_upgrade;' >> /etc/nginx/nginx.conf && \
|
| 87 |
+
echo ' proxy_set_header Connection "";' >> /etc/nginx/nginx.conf && \
|
| 88 |
+
echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \
|
| 89 |
+
echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \
|
| 90 |
+
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \
|
| 91 |
+
echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \
|
| 92 |
+
echo ' proxy_buffering off;' >> /etc/nginx/nginx.conf && \
|
| 93 |
+
echo ' proxy_cache off;' >> /etc/nginx/nginx.conf && \
|
| 94 |
+
echo ' proxy_read_timeout 86400;' >> /etc/nginx/nginx.conf && \
|
| 95 |
+
echo ' chunked_transfer_encoding off;' >> /etc/nginx/nginx.conf && \
|
| 96 |
+
echo ' }' >> /etc/nginx/nginx.conf && \
|
| 97 |
+
echo '' >> /etc/nginx/nginx.conf && \
|
| 98 |
+
echo ' # General proxy for other endpoints' >> /etc/nginx/nginx.conf && \
|
| 99 |
+
echo ' location / {' >> /etc/nginx/nginx.conf && \
|
| 100 |
+
echo ' proxy_pass http://127.0.0.1:5555;' >> /etc/nginx/nginx.conf && \
|
| 101 |
+
echo ' proxy_http_version 1.1;' >> /etc/nginx/nginx.conf && \
|
| 102 |
+
echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \
|
| 103 |
+
echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \
|
| 104 |
+
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \
|
| 105 |
+
echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \
|
| 106 |
+
echo ' }' >> /etc/nginx/nginx.conf && \
|
| 107 |
+
echo ' }' >> /etc/nginx/nginx.conf && \
|
| 108 |
+
echo '}' >> /etc/nginx/nginx.conf
|
| 109 |
|
| 110 |
# Create startup script
|
| 111 |
RUN echo '#!/bin/bash' > /app/start.sh && \
|
| 112 |
echo 'set -e' >> /app/start.sh && \
|
| 113 |
echo '' >> /app/start.sh && \
|
| 114 |
+
echo 'echo "Starting Coral Server on port 5555..."' >> /app/start.sh && \
|
| 115 |
+
echo 'cd /app' >> /app/start.sh && \
|
|
|
|
| 116 |
echo '' >> /app/start.sh && \
|
| 117 |
+
echo '# Start Coral Server with Gradle (using SSE Ktor server)' >> /app/start.sh && \
|
| 118 |
+
echo './gradlew run --args="--sse-server-ktor 5555" &' >> /app/start.sh && \
|
| 119 |
echo 'CORAL_PID=$!' >> /app/start.sh && \
|
| 120 |
echo '' >> /app/start.sh && \
|
| 121 |
+
echo '# Wait for Coral Server to start' >> /app/start.sh && \
|
| 122 |
+
echo 'sleep 10' >> /app/start.sh && \
|
| 123 |
+
echo '' >> /app/start.sh && \
|
| 124 |
+
echo '# Check if Coral Server is running' >> /app/start.sh && \
|
| 125 |
+
echo 'if ! ps -p $CORAL_PID > /dev/null; then' >> /app/start.sh && \
|
| 126 |
+
echo ' echo "Coral Server failed to start"' >> /app/start.sh && \
|
| 127 |
+
echo ' exit 1' >> /app/start.sh && \
|
| 128 |
+
echo 'fi' >> /app/start.sh && \
|
| 129 |
echo '' >> /app/start.sh && \
|
| 130 |
+
echo 'echo "Starting nginx on port 7860..."' >> /app/start.sh && \
|
| 131 |
+
echo 'nginx' >> /app/start.sh && \
|
| 132 |
chmod +x /app/start.sh
|
| 133 |
|
| 134 |
+
# Set ownership
|
| 135 |
+
RUN chown -R user:user /app && \
|
| 136 |
+
chown -R user:user /etc/nginx && \
|
| 137 |
+
chmod -R 755 /app
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
USER user
|
| 140 |
|
| 141 |
+
# Set environment variables
|
| 142 |
ENV HOME=/home/user \
|
| 143 |
PATH=/home/user/.local/bin:$PATH \
|
| 144 |
+
CONFIG_PATH=/app/coral-config/ \
|
| 145 |
+
GRADLE_USER_HOME=/home/user/.gradle
|
|
|
|
| 146 |
|
| 147 |
# HF Spaces expects port 7860
|
| 148 |
EXPOSE 7860
|
| 149 |
|
| 150 |
+
# Health check
|
| 151 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 152 |
+
CMD curl -f http://localhost:7860/ || exit 1
|
| 153 |
|
| 154 |
# Start both nginx proxy and Coral Server
|
| 155 |
CMD ["/app/start.sh"]
|