Spaces:
Sleeping
Sleeping
Gleb Tsyganov commited on
Commit ·
4d06c04
1
Parent(s): 311a95b
add docker + deploy
Browse files- .dockerignore +9 -0
- .github/workflows/sync-to-hf-space.yml +43 -0
- Dockerfile +59 -0
- README.md +19 -0
.dockerignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.git
|
| 2 |
+
.github
|
| 3 |
+
.venv
|
| 4 |
+
__pycache__/
|
| 5 |
+
*.py[cod]
|
| 6 |
+
*.egg-info/
|
| 7 |
+
outputs/
|
| 8 |
+
.env
|
| 9 |
+
.env.*
|
.github/workflows/sync-to-hf-space.yml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face Space
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [main]
|
| 6 |
+
workflow_dispatch:
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
deploy:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
steps:
|
| 12 |
+
- name: Checkout
|
| 13 |
+
uses: actions/checkout@v4
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
lfs: true
|
| 17 |
+
|
| 18 |
+
- name: Push to Hugging Face Space
|
| 19 |
+
env:
|
| 20 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 21 |
+
HF_USERNAME: ${{ vars.HF_USERNAME }}
|
| 22 |
+
HF_SPACE_REPO_ID: ${{ vars.HF_SPACE_REPO_ID }}
|
| 23 |
+
run: |
|
| 24 |
+
set -euo pipefail
|
| 25 |
+
|
| 26 |
+
if [ -z "${HF_TOKEN:-}" ]; then
|
| 27 |
+
echo "Missing GitHub secret HF_TOKEN."
|
| 28 |
+
exit 1
|
| 29 |
+
fi
|
| 30 |
+
if [ -z "${HF_USERNAME:-}" ]; then
|
| 31 |
+
echo "Missing GitHub variable HF_USERNAME."
|
| 32 |
+
exit 1
|
| 33 |
+
fi
|
| 34 |
+
if [ -z "${HF_SPACE_REPO_ID:-}" ]; then
|
| 35 |
+
echo "Missing GitHub variable HF_SPACE_REPO_ID (format: user-or-org/space-name)."
|
| 36 |
+
exit 1
|
| 37 |
+
fi
|
| 38 |
+
|
| 39 |
+
git config --global user.email "actions@github.com"
|
| 40 |
+
git config --global user.name "github-actions[bot]"
|
| 41 |
+
|
| 42 |
+
git remote add hf-space "https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_SPACE_REPO_ID}"
|
| 43 |
+
git push --force hf-space HEAD:main
|
Dockerfile
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the BSD-style license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
|
| 7 |
+
# Root Dockerfile used by Hugging Face Docker Spaces builds.
|
| 8 |
+
# Keep this in sync with server/Dockerfile for local and remote parity.
|
| 9 |
+
|
| 10 |
+
ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
|
| 11 |
+
FROM ${BASE_IMAGE} AS builder
|
| 12 |
+
|
| 13 |
+
WORKDIR /app
|
| 14 |
+
|
| 15 |
+
RUN apt-get update && \
|
| 16 |
+
apt-get install -y --no-install-recommends git && \
|
| 17 |
+
rm -rf /var/lib/apt/lists/*
|
| 18 |
+
|
| 19 |
+
ARG BUILD_MODE=in-repo
|
| 20 |
+
ARG ENV_NAME=clothing_brand_ctr_env
|
| 21 |
+
|
| 22 |
+
COPY . /app/env
|
| 23 |
+
WORKDIR /app/env
|
| 24 |
+
|
| 25 |
+
RUN if ! command -v uv >/dev/null 2>&1; then \
|
| 26 |
+
curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
| 27 |
+
mv /root/.local/bin/uv /usr/local/bin/uv && \
|
| 28 |
+
mv /root/.local/bin/uvx /usr/local/bin/uvx; \
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
| 32 |
+
if [ -f uv.lock ]; then \
|
| 33 |
+
uv sync --frozen --no-install-project --no-editable; \
|
| 34 |
+
else \
|
| 35 |
+
uv sync --no-install-project --no-editable; \
|
| 36 |
+
fi
|
| 37 |
+
|
| 38 |
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
| 39 |
+
if [ -f uv.lock ]; then \
|
| 40 |
+
uv sync --frozen --no-editable; \
|
| 41 |
+
else \
|
| 42 |
+
uv sync --no-editable; \
|
| 43 |
+
fi
|
| 44 |
+
|
| 45 |
+
FROM ${BASE_IMAGE}
|
| 46 |
+
|
| 47 |
+
WORKDIR /app
|
| 48 |
+
|
| 49 |
+
COPY --from=builder /app/env/.venv /app/.venv
|
| 50 |
+
COPY --from=builder /app/env /app/env
|
| 51 |
+
|
| 52 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
| 53 |
+
ENV PYTHONPATH="/app/env:$PYTHONPATH"
|
| 54 |
+
|
| 55 |
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 56 |
+
CMD curl -f http://localhost:8000/health || exit 1
|
| 57 |
+
|
| 58 |
+
EXPOSE 8000
|
| 59 |
+
CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"]
|
README.md
CHANGED
|
@@ -107,6 +107,25 @@ openenv push --private
|
|
| 107 |
openenv push --repo-id my-org/my-env --base-image custom-base:latest --private
|
| 108 |
```
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
After deployment, your space will be available at:
|
| 111 |
`https://huggingface.co/spaces/<repo-id>`
|
| 112 |
|
|
|
|
| 107 |
openenv push --repo-id my-org/my-env --base-image custom-base:latest --private
|
| 108 |
```
|
| 109 |
|
| 110 |
+
### Deploy from GitHub (recommended for continuous updates)
|
| 111 |
+
|
| 112 |
+
This repository now includes a GitHub Actions workflow at:
|
| 113 |
+
`.github/workflows/sync-to-hf-space.yml`
|
| 114 |
+
|
| 115 |
+
It pushes `main` to your Hugging Face Space after each commit.
|
| 116 |
+
|
| 117 |
+
Set these in your GitHub repository settings:
|
| 118 |
+
|
| 119 |
+
- **Secret**: `HF_TOKEN`
|
| 120 |
+
- **Variable**: `HF_USERNAME` (your Hugging Face username)
|
| 121 |
+
- **Variable**: `HF_SPACE_REPO_ID` (format: `user-or-org/space-name`)
|
| 122 |
+
|
| 123 |
+
Then push to `main` and the workflow will deploy automatically.
|
| 124 |
+
|
| 125 |
+
Note: for Docker Spaces, a root-level `Dockerfile` is required. This repo includes one.
|
| 126 |
+
If your app needs authenticated Hugging Face Hub access at runtime, also set `HF_TOKEN` in your
|
| 127 |
+
Space settings under **Settings -> Variables and secrets -> Secrets**.
|
| 128 |
+
|
| 129 |
After deployment, your space will be available at:
|
| 130 |
`https://huggingface.co/spaces/<repo-id>`
|
| 131 |
|