File size: 3,424 Bytes
6d0c9ea
 
 
 
 
 
 
 
 
2606287
6d0c9ea
 
6439a6b
63c0c95
6439a6b
58baa70
 
 
 
 
6439a6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63367a7
6d0c9ea
 
6439a6b
 
 
c019a87
 
560d306
c019a87
6439a6b
 
 
63c0c95
 
6439a6b
 
 
63367a7
6439a6b
6d0c9ea
 
6439a6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Build tangle-ui from GitHub
FROM node:22 as ui_builder
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /app

RUN git clone https://github.com/TangleML/tangle-ui.git . && git checkout stable_huggingface

RUN npm install
RUN echo VITE_GIT_COMMIT="$(git rev-parse --short HEAD | tr -d "\n")" >.env
RUN echo VITE_COMPONENT_LIBRARY_URL_DEFAULT_VALUE="https://raw.githubusercontent.com/Cloud-Pipelines/pipeline_components/refs/heads/stable_huggingface/pipeline_component_library.with_texts.yaml" >>.env
RUN npm run build:hf

# Use a Python image with uv pre-installed
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim

# HuggingFace dev mode requires wget, git
RUN apt-get update && \
    apt-get install -y bash curl wget procps git git-lfs && \
    rm -rf /var/lib/apt/lists/*

# Creating the /data directory and giving full access to users to avoid the errors:
# --> RUN mkdir -p /data
# mkdir: cannot create directory ‘/data’: Permission denied
RUN mkdir -p /data
RUN chmod 777 /data

# # Setup a non-root user
# RUN groupadd --system --gid 999 nonroot \
#  && useradd --system --gid 999 --uid 999 --create-home nonroot

# The two following lines are requirements for the Dev Mode to be functional
# Learn more about the Dev Mode at https://huggingface.co/dev-mode-explorers
RUN useradd -m -u 1000 user
USER user

# Install the project into `/app`
WORKDIR /app/backend

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

# Ensure installed tools can be executed out of the box
ENV UV_TOOL_BIN_DIR=/usr/local/bin

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=backend/uv.lock,target=uv.lock \
    --mount=type=bind,source=backend/pyproject.toml,target=pyproject.toml \
    uv sync --locked --no-install-project --no-dev

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
# COPY backend /app/backend
# COPY --chown=user . /app
COPY --chown=user backend /app/backend
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked --no-dev


# Installing HuggingFace. Needs to be done after uv sync
RUN uv pip install huggingface_hub[oauth]

# Place executables in the environment at the front of the path
ENV PATH="/app/backend/.venv/bin:$PATH"

# Adding HF-only experimental files
COPY huggingface_overlay /app/backend


# Copy frontend build
# COPY frontend_build /app/frontend_build

COPY --from=ui_builder /app/dist /app/frontend_build

# Put Tangle data into persistent storage
RUN mkdir -p /data
RUN ln -s /data/tangle/data /app/backend/data


# Reset the entrypoint, don't invoke `uv`
ENTRYPOINT []

# # Use the non-root user to run our application
# USER nonroot

# Run the FastAPI application by default
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
# Uses `--host 0.0.0.0` to allow access from outside the container
# Note in production, you should use `fastapi run` instead

# WORKDIR /app
# CMD ["fastapi", "dev", "--host", "0.0.0.0", "/app/backend/start_local.py"]

# WORKDIR /app/backend
# CMD ["fastapi", "dev", "--host", "0.0.0.0", "/app/start_HuggingFace.py"]

WORKDIR /app/backend
CMD ["fastapi", "dev", "--host", "0.0.0.0", "--port", "7860", "/app/backend/start_HuggingFace.py"]