Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +47 -33
Dockerfile
CHANGED
|
@@ -1,48 +1,62 @@
|
|
| 1 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
-
# SocialCrypt Server β Dockerfile
|
| 3 |
-
#
|
| 4 |
-
# Build & Run locally:
|
| 5 |
-
# docker build -t socialcrypt .
|
| 6 |
-
# docker run -d -p 3000:3000 -v data:/app/data socialcrypt
|
| 7 |
#
|
| 8 |
# Deploy to HuggingFace Spaces:
|
| 9 |
-
# 1.
|
| 10 |
-
# 2.
|
| 11 |
-
# 3.
|
| 12 |
-
# 4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
#
|
| 14 |
-
#
|
| 15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 17 |
|
| 18 |
-
|
| 19 |
-
FROM node:20-alpine AS base
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
RUN apk add --no-cache tini
|
| 23 |
|
| 24 |
WORKDIR /app
|
| 25 |
|
| 26 |
-
# ββ Stage 2: Runtime ββββββββββββββββββββββββββββββββββββ
|
| 27 |
-
FROM base AS release
|
| 28 |
-
|
| 29 |
-
# Copy only the server script (no npm dependencies β it's pure Node.js stdlib!)
|
| 30 |
-
COPY server.js .
|
| 31 |
-
|
| 32 |
-
# Create the data volume mount point
|
| 33 |
-
RUN mkdir -p /app/data
|
| 34 |
|
| 35 |
-
#
|
| 36 |
RUN addgroup -g 1001 -S appgroup && \
|
| 37 |
adduser -S appuser -u 1001 -G appgroup && \
|
| 38 |
chown -R appuser:appgroup /app
|
| 39 |
-
USER appuser
|
| 40 |
-
|
| 41 |
-
# Expose the port (default 3000, override with PORT env var)
|
| 42 |
-
EXPOSE 3000
|
| 43 |
-
|
| 44 |
-
# Use tini as PID 1 for proper signal handling
|
| 45 |
-
ENTRYPOINT ["/sbin/tini", "--"]
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
# SocialCrypt Server β HuggingFace Spaces Dockerfile
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
#
|
| 4 |
# Deploy to HuggingFace Spaces:
|
| 5 |
+
# 1. Go to https://huggingface.co/spaces β New Space
|
| 6 |
+
# 2. Choose "Docker" as Space SDK
|
| 7 |
+
# 3. Name your space (e.g., "socialcrypt-server")
|
| 8 |
+
# 4. Push this repo:
|
| 9 |
+
# git init
|
| 10 |
+
# git add server_hf.js Dockerfile.hf .dockerignore
|
| 11 |
+
# git commit -m "SocialCrypt HF deploy"
|
| 12 |
+
# git remote add space https://huggingface.co/spaces/YOUR_USER/socialcrypt-server
|
| 13 |
+
# git push space main
|
| 14 |
+
# 5. β
Done! (Port 7860 is the default)
|
| 15 |
#
|
| 16 |
+
# Your endpoint:
|
| 17 |
+
# Read: https://YOUR_USER-socialcrypt-server.hf.space/blobs.jsonl
|
| 18 |
+
# Write: https://YOUR_USER-socialcrypt-server.hf.space/submit
|
| 19 |
+
# Web: https://YOUR_USER-socialcrypt-server.hf.space/
|
| 20 |
+
#
|
| 21 |
+
# β οΈ HuggingFace Spaces mounts the /data persistent volume
|
| 22 |
+
# at RUNTIME, and it comes in owned by root. The entrypoint
|
| 23 |
+
# script runs as root first, fixes ownership, then drops
|
| 24 |
+
# privileges to a non-root user for security.
|
| 25 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 26 |
|
| 27 |
+
FROM node:20-alpine
|
|
|
|
| 28 |
|
| 29 |
+
# Install tini + su-exec (drop privileges tool)
|
| 30 |
+
RUN apk add --no-cache tini su-exec
|
| 31 |
|
| 32 |
WORKDIR /app
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Create a non-root user for the app to run as
|
| 36 |
RUN addgroup -g 1001 -S appgroup && \
|
| 37 |
adduser -S appuser -u 1001 -G appgroup && \
|
| 38 |
chown -R appuser:appgroup /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# Pre-create /data so the volume mount point exists
|
| 41 |
+
RUN mkdir -p /data
|
| 42 |
+
|
| 43 |
+
# βββ Entrypoint script ββββββββββββββββββββββββββββββββββ
|
| 44 |
+
# This runs as ROOT (no USER directive before ENTRYPOINT).
|
| 45 |
+
# It fixes /data ownership, THEN drops to appuser.
|
| 46 |
+
RUN echo '#!/bin/sh\n\
|
| 47 |
+
set -e\n\
|
| 48 |
+
\n\
|
| 49 |
+
# HuggingFace mounts /data at runtime, owned by root.\n\
|
| 50 |
+
# Fix ownership so the non-root app can write to it.\n\
|
| 51 |
+
chown -R appuser:appgroup /data\n\
|
| 52 |
+
\n\
|
| 53 |
+
# Drop privileges and run the app\n\
|
| 54 |
+
exec su-exec appuser:appgroup node /app/server.js "$@"\n\
|
| 55 |
+
' > /entrypoint.sh && chmod +x /entrypoint.sh
|
| 56 |
+
|
| 57 |
+
# NO "USER appuser" HERE β the entrypoint runs as root,
|
| 58 |
+
# then drops privileges via su-exec internally.
|
| 59 |
+
|
| 60 |
+
EXPOSE 7860
|
| 61 |
+
|
| 62 |
+
ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"]
|