Spaces:
Running
Running
| # ============================================== | |
| # Full-Stack Dev Environment for Hugging Face Spaces | |
| # Python 3.12 + Node.js + code-server + Auto Backup | |
| # ============================================== | |
| FROM ubuntu:22.04 | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # ----------------------------- | |
| # Core tools + essentials | |
| # ----------------------------- | |
| RUN apt-get update && apt-get install -y software-properties-common \ | |
| && add-apt-repository -y ppa:apt-fast/stable \ | |
| && apt-get update && apt-get -y install apt-fast \ | |
| && echo "DOWNLOADBEFORE=true" | tee -a /etc/apt-fast.conf \ | |
| && echo "MAXNUM=10" | tee -a /etc/apt-fast.conf \ | |
| && echo "USE_PIGZ=1" | tee -a /etc/apt-fast.conf \ | |
| && echo "APTFAST_PARA_OPTS=(--max-connection-per-server=12 --split=5)" | tee -a /etc/apt-fast.conf | |
| RUN apt-fast update && apt-fast install -y \ | |
| curl wget git git-lfs unzip sudo nano bash apt-fast \ | |
| ca-certificates gnupg build-essential jq sqlite3 rsync pigz \ | |
| net-tools iputils-ping htop tree && rm -rf /var/lib/apt/lists/* | |
| RUN git lfs install | |
| # ----------------------------- | |
| # Python 3.12 | |
| # ----------------------------- | |
| RUN add-apt-repository ppa:deadsnakes/ppa -y && apt-fast update \ | |
| && apt-fast install -y python3.12 python3.12-venv python3.12-dev \ | |
| && curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12 \ | |
| && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 \ | |
| && update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.12 1 \ | |
| && update-alternatives --set python3 /usr/bin/python3.12 | |
| # ----------------------------- | |
| # Node.js + Yarn + PNPM | |
| # ----------------------------- | |
| RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ | |
| && apt-fast install -y nodejs \ | |
| && npm install -g yarn pnpm typescript ts-node nodemon \ | |
| && npm cache clean --force && rm -rf /var/lib/apt/lists/* | |
| # ----------------------------- | |
| # PHP + Composer (optional) | |
| # ----------------------------- | |
| RUN apt-fast update && apt-fast install -y php-cli unzip \ | |
| && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # ----------------------------- | |
| # VS Code Server | |
| # ----------------------------- | |
| RUN curl -fsSL https://code-server.dev/install.sh | sh | |
| # ----------------------------- | |
| # Workspace setup | |
| # ----------------------------- | |
| WORKDIR /home/vscode | |
| RUN mkdir -p /home/vscode/workspace | |
| COPY --chmod=755 app.py /app.py | |
| COPY --chmod=755 backup.py /backup.py | |
| COPY --chmod=755 restore.py /restore.py | |
| RUN sudo chmod -R 777 /home/vscode | |
| # ----------------------------- | |
| # Python packages | |
| # ----------------------------- | |
| RUN pip install --upgrade pip setuptools wheel && \ | |
| pip install --ignore-installed blinker && \ | |
| pip install --no-cache-dir \ | |
| huggingface_hub hf_transfer flask fastapi django uvicorn requests | |
| # ----------------------------- | |
| # Locale + database clients | |
| # ----------------------------- | |
| RUN apt-fast update && apt-fast install -y locales mysql-client postgresql-client redis-tools \ | |
| && locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8 && rm -rf /var/lib/apt/lists/* | |
| ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 | |
| # MongoDB tools | |
| RUN wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb.gpg \ | |
| && echo "deb [signed-by=/usr/share/keyrings/mongodb.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" \ | |
| | tee /etc/apt/sources.list.d/mongodb-org-7.0.list \ | |
| && apt-fast update && apt-fast install -y mongodb-database-tools && rm -rf /var/lib/apt/lists/* | |
| # ----------------------------- | |
| # Productivity tools | |
| # ----------------------------- | |
| RUN apt-fast update && apt-fast install -y tmux screen neovim httpie shellcheck man-db manpages-dev && rm -rf /var/lib/apt/lists/* | |
| # ----------------------------- | |
| # User setup | |
| # ----------------------------- | |
| RUN useradd -ms /bin/bash vscode && echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers | |
| USER vscode | |
| ENV PATH=$PATH:/home/vscode/.local/bin | |
| # ----------------------------- | |
| # Environment defaults | |
| # ----------------------------- | |
| ENV PORT=7860 \ | |
| BACKUP_INTERVAL=5 \ | |
| CONFIG_BACKUP_INTERVAL=60 \ | |
| CONFIG_KEEP_LIMIT=5 \ | |
| HF_HUB_ENABLE_HF_TRANSFER=1 \ | |
| PASSWORD=${PASSWORD:-dev12345} | |
| # ----------------------------- | |
| # Entrypoint | |
| # ----------------------------- | |
| VOLUME /home/vscode/workspace | |
| ENTRYPOINT ["python3", "/app.py"] | |