-
-
Notifications
You must be signed in to change notification settings - Fork 76
Backend deployment #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backend deployment #106
Changes from all commits
533b118
56804b6
7d5eaf0
bff2d65
b02db47
0712a25
2f3400e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: 🚀 Deploy Backend to HF Space | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main # or your primary branch | ||
| paths: | ||
| - "backend/**" # only trigger when anything under backend/ changes | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: 👉 Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: 🔒 Install HF CLI | ||
| run: pip install huggingface_hub | ||
|
|
||
| - name: 🔑 HF login | ||
| env: | ||
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
| run: huggingface-cli login --token "$HF_TOKEN" | ||
|
|
||
| - name: 📂 Prepare Space repo | ||
| env: | ||
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
| run: | | ||
| rm -rf space-backend | ||
| git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend | ||
|
|
||
| - name: 📦 Install rsync | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y rsync | ||
|
|
||
| - name: 📤 Sync backend code | ||
| env: | ||
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
| run: | | ||
| cd space-backend | ||
|
|
||
| # Only remove tracked files (preserve .git and config) | ||
| git rm -r . || true | ||
| cd .. | ||
|
|
||
| # Copy new backend files in | ||
| cp -R backend/. space-backend/ | ||
|
|
||
| # Push new code to HF Space | ||
| cd space-backend | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add --all | ||
| git commit -m "Auto‑deploy backend: ${{ github.sha }}" || echo "No changes to commit" | ||
| git push origin main | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /.venv | ||
| */.env |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| FROM python:3.13-slim-bookworm | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:0.7.12 /uv /bin/uv | ||
|
|
||
| # Install OS dependencies | ||
| RUN apt-get update && apt-get install -y curl build-essential | ||
|
|
||
| # Create app dir and set it as working directory | ||
| WORKDIR /app | ||
|
|
||
| # Create a writable cache dir & change ownership to a non-root user | ||
| ENV UV_CACHE_DIR=/app/.uv-cache | ||
| RUN mkdir -p /app/.uv-cache && \ | ||
| adduser --disabled-password --gecos "" appuser && \ | ||
| chown -R appuser:appuser /app | ||
|
|
||
| # Copy project code | ||
| COPY . /app | ||
|
|
||
| # Switch to non-root user | ||
| USER appuser | ||
|
|
||
| # Install dependencies | ||
| RUN uv sync --locked --no-cache | ||
|
|
||
| # Expose the port Hugging Face looks for | ||
| EXPOSE 7860 | ||
|
|
||
| # Start the app | ||
| CMD ["uv", "run", "main.py"] |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||
| --- | ||||||||
| title: Perspective API 🧠 | ||||||||
| emoji: 🧠 | ||||||||
| colorFrom: green | ||||||||
| colorTo: blue | ||||||||
| sdk: docker | ||||||||
| sdk_version: "0.100.0" | ||||||||
| app_file: Dockerfile | ||||||||
| pinned: false | ||||||||
| --- | ||||||||
|
|
||||||||
|
|
||||||||
| # Perspective Backend | ||||||||
|
|
||||||||
|
|
||||||||
| Welcome to the **Perspective** backend! 🚀 | ||||||||
|
|
||||||||
| This backend is built with FastAPI and managed using **uv**, a handy Python project tool that simplifies dependency management and running the app. | ||||||||
|
|
||||||||
| --- | ||||||||
|
|
||||||||
| ## Getting Started | ||||||||
|
|
||||||||
| ### 1. Clone the repo & jump into backend folder | ||||||||
|
|
||||||||
| ```bash | ||||||||
| git clone https://github.com/AOSSIE-Org/Perspective.git | ||||||||
| cd new-backend | ||||||||
| ```` | ||||||||
|
Comment on lines
+28
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct directory name in the quick-start step The repo places this README under -cd new-backend
+cd backend📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| ### 2. Add new modules easily | ||||||||
|
|
||||||||
| To add any new Python package/module, just run: | ||||||||
|
|
||||||||
| ```bash | ||||||||
| uv add <module_name> | ||||||||
| ``` | ||||||||
|
|
||||||||
| Example: | ||||||||
|
|
||||||||
| ```bash | ||||||||
| uv add fastapi requests | ||||||||
| ``` | ||||||||
|
|
||||||||
| This will automatically update your `pyproject.toml` and install the package for you. | ||||||||
|
|
||||||||
| *No need to manually create or activate virtual environments — uv handles it for you!* | ||||||||
|
|
||||||||
| ### 3. Run the server | ||||||||
|
|
||||||||
| Start the backend server with: | ||||||||
|
|
||||||||
| ```bash | ||||||||
| uv run main.py | ||||||||
| ``` | ||||||||
|
|
||||||||
| The server will be available at: | ||||||||
|
|
||||||||
| ``` | ||||||||
| http://localhost:8000/api/ | ||||||||
| ``` | ||||||||
|
|
||||||||
| --- | ||||||||
|
|
||||||||
| ## Important Notes | ||||||||
|
|
||||||||
| * All dependencies are tracked in `pyproject.toml`. | ||||||||
| * No manual setup of venv or conda environments is required. | ||||||||
| * For full documentation on **uv**, visit: | ||||||||
| [https://docs.astral.sh/uv/](https://docs.astral.sh/uv/) | ||||||||
|
|
||||||||
| --- | ||||||||
|
|
||||||||
| ## Project Structure (brief) | ||||||||
|
|
||||||||
| ``` | ||||||||
| new-backend/ | ||||||||
| ├── main.py # App entry point | ||||||||
| ├── pyproject.toml # Dependency & project config | ||||||||
| ├── uv.lock # .loc file like package-lock.json | ||||||||
| ├── .python-version # Python version used by the backend | ||||||||
| └── app/ | ||||||||
| ├── routes/ # API route handlers | ||||||||
| ├── components/ # Business logic components | ||||||||
| ├── db/ # Database related code | ||||||||
| └── utils/ # Utility functions | ||||||||
| ``` | ||||||||
|
|
||||||||
| --- | ||||||||
|
|
||||||||
| If you hit any issues or want to contribute, feel free to open an issue or PR. | ||||||||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the shellcheck warning by adding quotes around the variable.
The static analysis tool flagged a potential issue with unquoted variable usage that could lead to word splitting.
Apply this diff to fix the shellcheck warning:
📝 Committable suggestion
🧰 Tools
🪛 actionlint (1.7.7)
30-30: shellcheck reported issue in this script: SC2086:info:2:31: Double quote to prevent globbing and word splitting
(shellcheck)
🤖 Prompt for AI Agents