Spaces:
Paused
Paused
Create Dockerfile
Browse files- Dockerfile +114 -0
Dockerfile
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ARG CODE_SERVER_VERSION=4.128.0
|
| 2 |
+
ARG UV_VERSION=0.11.29
|
| 3 |
+
|
| 4 |
+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
|
| 5 |
+
FROM ghcr.io/coder/code-server:${CODE_SERVER_VERSION}
|
| 6 |
+
|
| 7 |
+
USER root
|
| 8 |
+
|
| 9 |
+
# install build tools, uv, python 3.12, claude code cli, ngrok
|
| 10 |
+
RUN apt-get update \
|
| 11 |
+
&& apt-get install -y --no-install-recommends \
|
| 12 |
+
build-essential \
|
| 13 |
+
ca-certificates \
|
| 14 |
+
curl \
|
| 15 |
+
jq \
|
| 16 |
+
pkg-config \
|
| 17 |
+
ripgrep \
|
| 18 |
+
unzip \
|
| 19 |
+
&& install -d -m 0755 /etc/apt/keyrings \
|
| 20 |
+
&& curl -fsSL https://downloads.claude.ai/keys/claude-code.asc \
|
| 21 |
+
-o /etc/apt/keyrings/claude-code.asc \
|
| 22 |
+
&& printf '%s\n' \
|
| 23 |
+
'deb [signed-by=/etc/apt/keyrings/claude-code.asc] https://downloads.claude.ai/claude-code/apt/stable stable main' \
|
| 24 |
+
> /etc/apt/sources.list.d/claude-code.list \
|
| 25 |
+
&& curl -fsSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
|
| 26 |
+
-o /etc/apt/keyrings/ngrok.asc \
|
| 27 |
+
&& printf '%s\n' \
|
| 28 |
+
'deb [signed-by=/etc/apt/keyrings/ngrok.asc] https://ngrok-agent.s3.amazonaws.com buster main' \
|
| 29 |
+
> /etc/apt/sources.list.d/ngrok.list \
|
| 30 |
+
&& apt-get update \
|
| 31 |
+
&& apt-get install -y --no-install-recommends \
|
| 32 |
+
claude-code \
|
| 33 |
+
ngrok \
|
| 34 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 35 |
+
|
| 36 |
+
# install uv and uvx from official image
|
| 37 |
+
COPY --from=uv /uv /uvx /usr/local/bin/
|
| 38 |
+
|
| 39 |
+
ENV HOME=/home/coder \
|
| 40 |
+
PORT=7860 \
|
| 41 |
+
WORKSPACE=/home/coder/workspace \
|
| 42 |
+
VIRTUAL_ENV=/home/coder/workspace/.venv \
|
| 43 |
+
UV_PYTHON_INSTALL_DIR=/opt/uv/python \
|
| 44 |
+
UV_LINK_MODE=copy \
|
| 45 |
+
UV_COMPILE_BYTECODE=1 \
|
| 46 |
+
PATH="/home/coder/workspace/.venv/bin:/home/coder/.local/bin:${PATH}" \
|
| 47 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 48 |
+
PYTHONUNBUFFERED=1 \
|
| 49 |
+
CS_DISABLE_GETTING_STARTED_OVERRIDE=true
|
| 50 |
+
|
| 51 |
+
# /data is mounted only at runtime on Hugging Face Spaces. Build all seed
|
| 52 |
+
# artifacts elsewhere, then restore them into /data from entrypoint.d.
|
| 53 |
+
RUN install -d -o coder -g coder \
|
| 54 |
+
/opt/bootstrap \
|
| 55 |
+
/opt/bootstrap/extensions \
|
| 56 |
+
/opt/bootstrap/workspace-src \
|
| 57 |
+
/opt/uv/python \
|
| 58 |
+
/home/coder/entrypoint.d \
|
| 59 |
+
/home/coder/workspace
|
| 60 |
+
|
| 61 |
+
# resolve the project from pyproject.toml, install python 3.12,
|
| 62 |
+
# and archive the ready-to-use .venv. uv also creates the lockfile here.
|
| 63 |
+
COPY --chown=coder:coder pyproject.toml /tmp/workspace-deps/pyproject.toml
|
| 64 |
+
|
| 65 |
+
USER coder
|
| 66 |
+
|
| 67 |
+
RUN set -eux; \
|
| 68 |
+
cp /tmp/workspace-deps/pyproject.toml /home/coder/workspace/pyproject.toml; \
|
| 69 |
+
cd /home/coder/workspace; \
|
| 70 |
+
uv python install 3.12; \
|
| 71 |
+
uv sync --python 3.12 --no-install-project; \
|
| 72 |
+
cp uv.lock /opt/bootstrap/uv.lock; \
|
| 73 |
+
tar -C /home/coder/workspace -czf /opt/bootstrap/venv.tar.gz .venv; \
|
| 74 |
+
rm -rf /home/coder/workspace /tmp/workspace-deps; \
|
| 75 |
+
uv cache clean
|
| 76 |
+
|
| 77 |
+
# preinstall the official Claude Code extension and Python support.
|
| 78 |
+
# copy to the persistent extension directory on container startup.
|
| 79 |
+
RUN code-server \
|
| 80 |
+
--user-data-dir /tmp/code-server-user-data \
|
| 81 |
+
--extensions-dir /opt/bootstrap/extensions \
|
| 82 |
+
--install-extension Anthropic.claude-code \
|
| 83 |
+
&& code-server \
|
| 84 |
+
--user-data-dir /tmp/code-server-user-data \
|
| 85 |
+
--extensions-dir /opt/bootstrap/extensions \
|
| 86 |
+
--install-extension ms-python.python \
|
| 87 |
+
&& code-server \
|
| 88 |
+
--extensions-dir /opt/bootstrap/extensions \
|
| 89 |
+
--list-extensions \
|
| 90 |
+
&& rm -rf /tmp/code-server-user-data
|
| 91 |
+
|
| 92 |
+
# seed the Space repository into a new persistent workspace
|
| 93 |
+
# include uv.lock even though it is not required in the git repo
|
| 94 |
+
COPY --chown=coder:coder . /opt/bootstrap/workspace-src/
|
| 95 |
+
|
| 96 |
+
RUN set -eux; \
|
| 97 |
+
cp /opt/bootstrap/uv.lock /opt/bootstrap/workspace-src/uv.lock; \
|
| 98 |
+
tar -C /opt/bootstrap/workspace-src -czf /opt/bootstrap/workspace-seed.tar.gz .; \
|
| 99 |
+
rm -rf /opt/bootstrap/workspace-src
|
| 100 |
+
|
| 101 |
+
USER root
|
| 102 |
+
|
| 103 |
+
# the official image runs executable files in $ENTRYPOINTD before code-server
|
| 104 |
+
COPY --chown=coder:coder --chmod=0755 scripts/10-init-persistent-data.sh \
|
| 105 |
+
/home/coder/entrypoint.d/10-init-persistent-data.sh
|
| 106 |
+
COPY --chown=root:root --chmod=0755 scripts/start-code-server.sh \
|
| 107 |
+
/usr/local/bin/start-code-server
|
| 108 |
+
|
| 109 |
+
USER coder
|
| 110 |
+
WORKDIR /home/coder
|
| 111 |
+
|
| 112 |
+
EXPOSE 7860
|
| 113 |
+
|
| 114 |
+
ENTRYPOINT ["/usr/local/bin/start-code-server"]
|