Spaces:
Build error

n8n / Dockerfile
subham
Sync local n8n deployment: refactor to single Dockerfile, add runners, sandbox, cleanup legacy compose/nginx
4c98a98
Raw History Blame Contribute Delete
4.87 kB
# Single-container n8n 2.39.8 for Hugging Face Spaces (Alpine, official image)
# HOSTS: n8n + postgres + external task-runner (co-hosted) + self-hosted sandbox (rootless)
ARG N8N_VERSION=2.39.8
FROM n8nio/runners:${N8N_VERSION} AS runners
FROM docker.n8n.io/n8nio/n8n:${N8N_VERSION}
ARG N8N_VERSION
ENV N8N_VERSION=${N8N_VERSION}
USER root
# n8nio/base:29 does `apk del apk-tools` — reinstall it before apk add (Alpine 3.24 uses apk-tools-static 3.0.8)
RUN set -e; \
if ! command -v apk >/dev/null 2>&1; then \
echo "reinstalling apk-tools for 3.24"; \
wget -qO /tmp/apk-tools-static.apk https://dl-cdn.alpinelinux.org/alpine/v3.24/main/x86_64/apk-tools-static-3.0.8-r0.apk 2>&1 || \
busybox wget -qO /tmp/apk-tools-static.apk https://dl-cdn.alpinelinux.org/alpine/v3.24/main/x86_64/apk-tools-static-3.0.8-r0.apk 2>&1 || true; \
echo "downloaded static:"; ls -lh /tmp/apk-tools-static.apk 2>&1 || echo "no file"; \
if [ -f /tmp/apk-tools-static.apk ]; then tar -xz -C / -f /tmp/apk-tools-static.apk 2>&1 || tar -xzf /tmp/apk-tools-static.apk -C / 2>&1 || true; rm -f /tmp/apk-tools-static.apk; fi; \
if [ -f /sbin/apk.static ]; then ln -sf /sbin/apk.static /sbin/apk; ln -sf /sbin/apk.static /bin/apk 2>/dev/null || true; fi; \
ls -l /sbin/apk* /bin/apk* 2>&1 | head; apk --version 2>&1 || apk.static --version 2>&1 || echo "apk still missing"; \
fi; \
apk --version 2>&1 || apk.static --version 2>&1 || echo "apk bootstrap done"
# Install system packages (apk-packages.txt is 1 pkg/line)
COPY apk-packages.txt /tmp/apk-packages.txt
RUN set -e; \
apk update; \
# filter comments/empty
pkgs=$(grep -v '^#' /tmp/apk-packages.txt | grep -v '^$' | tr '\n' ' '); \
echo "Installing: $pkgs"; \
apk add --no-cache $pkgs; \
apk add --no-cache unzip 2>/dev/null || true
# Copy runners (JS + Python venv + launcher + uv + libpython) into this image
COPY --from=runners /opt/runners /opt/runners
COPY --from=runners /usr/local/bin/task-runner-launcher /usr/local/bin/task-runner-launcher
COPY --from=runners /usr/local/bin/uv /usr/local/bin/uv
COPY --from=runners /usr/local/bin/python3.13 /usr/local/bin/python3.13
COPY --from=runners /usr/local/lib/libpython3.13.so* /usr/local/lib/
COPY --from=runners /usr/local/lib/python3.13 /usr/local/lib/python3.13
# Ensure runner user exists (runners image creates it; ensure here too)
RUN addgroup -g 1001 -S runner 2>/dev/null || addgroup runner 2>/dev/null || true; \
adduser -u 1001 -S -G runner -h /home/runner -D runner 2>/dev/null || adduser -D -h /home/runner -G runner runner 2>/dev/null || true; \
mkdir -p /home/runner /opt/runners && chown -R runner:runner /home/runner /opt/runners 2>/dev/null || true; \
id runner 2>&1 | head
# Python extra libs (runner venv via uv) — allow building opencv etc.
COPY requirements.txt requirements.runner.txt /tmp/
RUN set -e; \
if [ -f /tmp/requirements.txt ]; then \
grep -v '^#' /tmp/requirements.txt | grep -v '^$' > /tmp/runner-req1.txt || true; \
if [ -s /tmp/runner-req1.txt ]; then \
echo "Installing requirements.txt into runner venv via uv"; \
/usr/local/bin/uv pip install --no-cache --python /opt/runners/task-runner-python/.venv/bin/python -r /tmp/runner-req1.txt 2>&1 | tail -30 || true; \
fi; \
fi; \
if [ -f /tmp/requirements.runner.txt ]; then \
grep -v '^#' /tmp/requirements.runner.txt | grep -v '^$' > /tmp/runner-req2.txt || true; \
if [ -s /tmp/runner-req2.txt ]; then \
echo "Installing requirements.runner.txt via uv"; \
/usr/local/bin/uv pip install --no-cache --python /opt/runners/task-runner-python/.venv/bin/python -r /tmp/runner-req2.txt 2>&1 | tail -30 || true; \
else echo "No runner extra reqs"; fi; \
fi
# Binaries drop-in + duckdb download
COPY binaries/ /tmp/binaries/
RUN chmod +x /tmp/binaries/install.sh && /tmp/binaries/install.sh
# n8n / postgres / sandbox filesystem
RUN mkdir -p /data/postgres /data/n8n /data/sandbox /var/log/supervisor /var/run/postgresql /home/node/.n8n && \
chown -R node:node /home/node 2>/dev/null || true; \
chown -R postgres:postgres /var/run/postgresql 2>/dev/null || true; \
chmod 777 /data 2>/dev/null || true
# Configs
COPY runners/n8n-task-runners.json /etc/n8n-task-runners.json
COPY supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY scripts/ /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh 2>/dev/null || true; \
chmod +x /usr/local/bin/sandbox-*.js 2>/dev/null || true
# Ensure postgres owns its future PGDATA
RUN mkdir -p /data/postgres && chown postgres:postgres /data/postgres 2>/dev/null || true
EXPOSE 7860
HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
CMD curl -f http://127.0.0.1:7860/healthz || exit 1
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]