Spaces:
Runtime error
Runtime error
Add CLAUDE.md and Ubuntu Dockerfile
Browse files- Added comprehensive CLAUDE.md for future Claude Code instances
- Added Dockerfile.ubuntu for full Ubuntu 22.04 development environment
- Includes web terminal and SSH access capabilities
- CLAUDE.md +244 -0
- Dockerfile.ubuntu +99 -0
CLAUDE.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CLAUDE.md
|
| 2 |
+
|
| 3 |
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
| 4 |
+
|
| 5 |
+
## Project Overview
|
| 6 |
+
|
| 7 |
+
This repository contains a **Hugging Face Spaces** deployment setup with two distinct applications:
|
| 8 |
+
|
| 9 |
+
1. **Simple FastAPI Application** (`app.py`) - A minimal FastAPI web service
|
| 10 |
+
2. **Ubuntu Development Environment** (`Dockerfile.ubuntu`) - Full Ubuntu 22.04 dev environment with web terminal and SSH
|
| 11 |
+
|
| 12 |
+
The repository is designed to be deployed to Hugging Face Spaces at `https://shk-bd.hf.space`.
|
| 13 |
+
|
| 14 |
+
## Repository Structure
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
/data/data/com.termux/files/home/Spaces/
|
| 18 |
+
├── app.py # FastAPI application (main entry point for simple app)
|
| 19 |
+
├── main.py # Duplicate of app.py
|
| 20 |
+
├── index.py # Duplicate of app.py
|
| 21 |
+
├── test_app.py # Test suite for FastAPI application
|
| 22 |
+
├── requirements.txt # Python dependencies: fastapi, uvicorn[standard]
|
| 23 |
+
├── Dockerfile # Container config for simple FastAPI app
|
| 24 |
+
├── Dockerfile.ubuntu # Container config for full Ubuntu dev environment
|
| 25 |
+
├── deploy.py # Python deployment script
|
| 26 |
+
├── deploy.sh # Bash deployment script
|
| 27 |
+
├── push_to_hf.sh # Alternative bash deployment script
|
| 28 |
+
├── README.md # Main documentation
|
| 29 |
+
├── DEPLOYMENT.md # Detailed deployment instructions
|
| 30 |
+
├── PUSH_INSTRUCTIONS.md # Emergency push instructions
|
| 31 |
+
├── TEST_REPORT.md # Test results and validation
|
| 32 |
+
└── .gitignore # Standard Python/Node.js ignore patterns
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Common Commands
|
| 36 |
+
|
| 37 |
+
### Development
|
| 38 |
+
|
| 39 |
+
**Run the FastAPI application locally:**
|
| 40 |
+
```bash
|
| 41 |
+
pip install -r requirements.txt
|
| 42 |
+
uvicorn app:app --host 0.0.0.0 --port 7860
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
**Run tests:**
|
| 46 |
+
```bash
|
| 47 |
+
python3 test_app.py
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
**Build Docker image (FastAPI app):**
|
| 51 |
+
```bash
|
| 52 |
+
docker build -t ubuntu-dev-fastapi .
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
**Build Docker image (Ubuntu dev environment):**
|
| 56 |
+
```bash
|
| 57 |
+
docker build -f Dockerfile.ubuntu -t ubuntu-dev-env .
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### Deployment to Hugging Face Spaces
|
| 61 |
+
|
| 62 |
+
**Method 1 - Use deployment script:**
|
| 63 |
+
```bash
|
| 64 |
+
python3 deploy.py
|
| 65 |
+
# or
|
| 66 |
+
./deploy.sh
|
| 67 |
+
# or
|
| 68 |
+
./push_to_hf.sh
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
**Method 2 - Manual Git deployment:**
|
| 72 |
+
```bash
|
| 73 |
+
git init
|
| 74 |
+
git config user.name "shk-bd"
|
| 75 |
+
git config user.email "shk-bd@users.noreply.huggingface.co"
|
| 76 |
+
git remote add origin https://huggingface.co/spaces/shk-bd/ubuntu-dev-env
|
| 77 |
+
git add .
|
| 78 |
+
git commit -m "Initial commit"
|
| 79 |
+
git push -u origin master
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
**Method 3 - Using HF CLI:**
|
| 83 |
+
```bash
|
| 84 |
+
# Install HF CLI
|
| 85 |
+
curl -sSfL https://hf.co/cli/install | bash
|
| 86 |
+
# Login
|
| 87 |
+
hf login
|
| 88 |
+
# Push
|
| 89 |
+
git push -u origin master
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
### Authentication for Git Push
|
| 93 |
+
|
| 94 |
+
When prompted for credentials during git push:
|
| 95 |
+
- **Username**: `shk-bd`
|
| 96 |
+
- **Password**: `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` (or your HF token)
|
| 97 |
+
|
| 98 |
+
Or embed token in URL:
|
| 99 |
+
```bash
|
| 100 |
+
git remote set-url origin https://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@huggingface.co/spaces/shk-bd/ubuntu-dev-env
|
| 101 |
+
git push -u origin master
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### Testing Deployment
|
| 105 |
+
|
| 106 |
+
**Test the endpoint:**
|
| 107 |
+
```bash
|
| 108 |
+
curl https://shk-bd.hf.space/
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
**Expected response:**
|
| 112 |
+
```json
|
| 113 |
+
{"Hello": "World!"}
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Architecture Details
|
| 117 |
+
|
| 118 |
+
### Application Types
|
| 119 |
+
|
| 120 |
+
**FastAPI Application (`app.py`):**
|
| 121 |
+
- Minimal web service using FastAPI framework
|
| 122 |
+
- Single endpoint: `GET /` returns `{"Hello": "World!"}`
|
| 123 |
+
- Runs on port 7860 (Hugging Face Spaces default)
|
| 124 |
+
- Uses Uvicorn ASGI server
|
| 125 |
+
- Non-root user (uid: 1000) for security
|
| 126 |
+
|
| 127 |
+
**Ubuntu Development Environment (`Dockerfile.ubuntu`):**
|
| 128 |
+
- Full Ubuntu 22.04 base system
|
| 129 |
+
- Includes: Python 3, Node.js 20, Java 11, Go, Ruby, PHP
|
| 130 |
+
- Development tools: git, vim, build-essential, jupyter
|
| 131 |
+
- Web terminal via ttyd on port 7681
|
| 132 |
+
- SSH server on port 22
|
| 133 |
+
- User: `root` (password: `ubuntu`) and `devuser`
|
| 134 |
+
- Workspace directory: `/workspace`
|
| 135 |
+
|
| 136 |
+
### Container Configuration
|
| 137 |
+
|
| 138 |
+
**Dockerfile** (FastAPI):
|
| 139 |
+
- Base: `python:3.9`
|
| 140 |
+
- Port: `7860`
|
| 141 |
+
- Command: `uvicorn app:app --host 0.0.0.0 --port 7860`
|
| 142 |
+
- User: `user` (uid 1000)
|
| 143 |
+
|
| 144 |
+
**Dockerfile.ubuntu** (Ubuntu env):
|
| 145 |
+
- Base: `ubuntu:22.04`
|
| 146 |
+
- Ports: `22` (SSH), `7681` (web terminal)
|
| 147 |
+
- Command: `/start.sh` (starts SSH and ttyd)
|
| 148 |
+
- User: `devuser`
|
| 149 |
+
|
| 150 |
+
### Deployment Architecture
|
| 151 |
+
|
| 152 |
+
The repository uses **Hugging Face Spaces with Docker SDK**:
|
| 153 |
+
- Git-based deployment (push to `https://huggingface.co/spaces/shk-bd/ubuntu-dev-env`)
|
| 154 |
+
- Automatic Docker build on push
|
| 155 |
+
- Container runs on Hugging Face infrastructure
|
| 156 |
+
- Accessible via web browser and SSH
|
| 157 |
+
|
| 158 |
+
## Access Your Space
|
| 159 |
+
|
| 160 |
+
**Web Terminal:**
|
| 161 |
+
```
|
| 162 |
+
https://shk-bd.hf.space
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
**SSH Access:**
|
| 166 |
+
```bash
|
| 167 |
+
ssh root@shk-bd.hf.space
|
| 168 |
+
# Password: ubuntu
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
## Space Configuration
|
| 172 |
+
|
| 173 |
+
When creating the Space manually:
|
| 174 |
+
- **Space name**: ubuntu-dev-env
|
| 175 |
+
- **SDK**: Docker
|
| 176 |
+
- **Hardware**: CPU basic
|
| 177 |
+
- **Visibility**: Public
|
| 178 |
+
- **License**: MIT
|
| 179 |
+
|
| 180 |
+
## Documentation Files
|
| 181 |
+
|
| 182 |
+
- **README.md** - Comprehensive user guide with examples
|
| 183 |
+
- **DEPLOYMENT.md** - Step-by-step deployment instructions (3 methods)
|
| 184 |
+
- **PUSH_INSTRUCTIONS.md** - Emergency instructions for fixing push errors
|
| 185 |
+
- **TEST_REPORT.md** - Test results and validation status
|
| 186 |
+
|
| 187 |
+
## Dependencies
|
| 188 |
+
|
| 189 |
+
**Python (requirements.txt):**
|
| 190 |
+
- `fastapi` - Web framework
|
| 191 |
+
- `uvicorn[standard]` - ASGI server
|
| 192 |
+
|
| 193 |
+
**System (Dockerfile.ubuntu):**
|
| 194 |
+
- Ubuntu 22.04 base
|
| 195 |
+
- Python 3, Node.js 20, Java 11, Go, Ruby, PHP
|
| 196 |
+
- Development tools (git, vim, build-essential)
|
| 197 |
+
- SSH server and web terminal (ttyd)
|
| 198 |
+
|
| 199 |
+
## Testing and Validation
|
| 200 |
+
|
| 201 |
+
The repository includes `test_app.py` which:
|
| 202 |
+
1. Verifies Python syntax
|
| 203 |
+
2. Tests application logic
|
| 204 |
+
3. Validates FastAPI endpoint returns `{"Hello": "World!"}`
|
| 205 |
+
4. Checks Dockerfile configuration
|
| 206 |
+
|
| 207 |
+
Run validation:
|
| 208 |
+
```bash
|
| 209 |
+
python3 test_app.py
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
Expected output:
|
| 213 |
+
```
|
| 214 |
+
Testing FastAPI application logic...
|
| 215 |
+
----------------------------------------
|
| 216 |
+
Result: {'Hello': 'World!'}
|
| 217 |
+
✅ Test passed!
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
## Key Development Notes
|
| 221 |
+
|
| 222 |
+
- **Two Dockerfiles exist**: Choose based on whether you want simple FastAPI or full Ubuntu environment
|
| 223 |
+
- **Multiple deployment scripts**: Use any of deploy.py, deploy.sh, or push_to_hf.sh
|
| 224 |
+
- **Git-based workflow**: All changes pushed to `origin master` trigger deployment
|
| 225 |
+
- **Space URL**: https://shk-bd.hf.space (or https://shk-bd-sandbox-ubuntu.hf.space)
|
| 226 |
+
- **Build time**: 2-3 minutes after successful push
|
| 227 |
+
- **Credentials**: Stored in deploy.py and push scripts (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)
|
| 228 |
+
|
| 229 |
+
## Troubleshooting
|
| 230 |
+
|
| 231 |
+
**Build fails:**
|
| 232 |
+
- Check Space logs at https://huggingface.co/spaces/shk-bd/ubuntu-dev-env/tree/main
|
| 233 |
+
- Ensure Dockerfile syntax is correct
|
| 234 |
+
- Verify requirements.txt format
|
| 235 |
+
|
| 236 |
+
**Can't access via SSH:**
|
| 237 |
+
- Verify Space is fully built and running
|
| 238 |
+
- SSH may take a minute after initial deployment
|
| 239 |
+
- Use web terminal as fallback
|
| 240 |
+
|
| 241 |
+
**Push fails:**
|
| 242 |
+
- Check authentication credentials
|
| 243 |
+
- Use HF CLI as alternative: `hf login`
|
| 244 |
+
- See PUSH_INSTRUCTIONS.md for detailed troubleshooting
|
Dockerfile.ubuntu
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM ubuntu:22.04
|
| 2 |
+
|
| 3 |
+
# Avoid interactive prompts during package installation
|
| 4 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
+
|
| 6 |
+
# Install base packages and development tools
|
| 7 |
+
RUN apt-get update && apt-get install -y \
|
| 8 |
+
curl \
|
| 9 |
+
wget \
|
| 10 |
+
git \
|
| 11 |
+
vim \
|
| 12 |
+
nano \
|
| 13 |
+
htop \
|
| 14 |
+
tree \
|
| 15 |
+
unzip \
|
| 16 |
+
sudo \
|
| 17 |
+
build-essential \
|
| 18 |
+
software-properties-common \
|
| 19 |
+
apt-transport-https \
|
| 20 |
+
ca-certificates \
|
| 21 |
+
gnupg \
|
| 22 |
+
lsb-release \
|
| 23 |
+
zsh \
|
| 24 |
+
fish \
|
| 25 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 26 |
+
|
| 27 |
+
# Install Python and pip
|
| 28 |
+
RUN apt-get update && apt-get install -y \
|
| 29 |
+
python3 \
|
| 30 |
+
python3-pip \
|
| 31 |
+
python3-venv \
|
| 32 |
+
python3-dev \
|
| 33 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 34 |
+
|
| 35 |
+
# Install Node.js
|
| 36 |
+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
| 37 |
+
&& apt-get install -y nodejs \
|
| 38 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 39 |
+
|
| 40 |
+
# Install additional programming languages
|
| 41 |
+
RUN apt-get update && apt-get install -y \
|
| 42 |
+
openjdk-11-jdk \
|
| 43 |
+
golang-go \
|
| 44 |
+
ruby \
|
| 45 |
+
php \
|
| 46 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 47 |
+
|
| 48 |
+
# Install useful development tools
|
| 49 |
+
RUN pip3 install --no-cache-dir \
|
| 50 |
+
pip \
|
| 51 |
+
setuptools \
|
| 52 |
+
wheel \
|
| 53 |
+
virtualenv \
|
| 54 |
+
pipenv \
|
| 55 |
+
poetry \
|
| 56 |
+
jupyter \
|
| 57 |
+
ipython
|
| 58 |
+
|
| 59 |
+
# Install ttyd for web-based terminal
|
| 60 |
+
RUN apt-get update && apt-get install -y \
|
| 61 |
+
ttyd \
|
| 62 |
+
screen \
|
| 63 |
+
tmux \
|
| 64 |
+
openssh-server \
|
| 65 |
+
pwgen \
|
| 66 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 67 |
+
|
| 68 |
+
# Create development user
|
| 69 |
+
RUN useradd -m -s /bin/bash devuser && \
|
| 70 |
+
echo "devuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
| 71 |
+
|
| 72 |
+
# Configure SSH server
|
| 73 |
+
RUN mkdir /var/run/sshd && \
|
| 74 |
+
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
|
| 75 |
+
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
|
| 76 |
+
sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config && \
|
| 77 |
+
echo "root:ubuntu" | chpasswd
|
| 78 |
+
|
| 79 |
+
# Expose SSH port
|
| 80 |
+
EXPOSE 22 7681
|
| 81 |
+
|
| 82 |
+
# Set up workspace
|
| 83 |
+
WORKDIR /workspace
|
| 84 |
+
RUN chown -R devuser:devuser /workspace
|
| 85 |
+
|
| 86 |
+
# Switch to devuser
|
| 87 |
+
USER devuser
|
| 88 |
+
|
| 89 |
+
# Create startup script
|
| 90 |
+
RUN echo '#!/bin/bash\n\
|
| 91 |
+
service ssh start\n\
|
| 92 |
+
exec ttyd --port 7681 --bash /bin/bash\n\
|
| 93 |
+
' > /start.sh && chmod +x /start.sh
|
| 94 |
+
|
| 95 |
+
# Set default shell to bash
|
| 96 |
+
SHELL ["/bin/bash", "-c"]
|
| 97 |
+
|
| 98 |
+
# Start services
|
| 99 |
+
CMD ["/start.sh"]
|