Spaces:
Running
Running
Jatin Mehra
commited on
Commit
·
bb151bf
1
Parent(s):
6c81e4d
Remove Docker image deployment workflow and update Dockerfile for improved setup and environment variable handling
Browse files- .github/workflows/deploy-image.yml +0 -44
- .github/workflows/sync_to_hf.yml +36 -0
- Dockerfile +43 -18
.github/workflows/deploy-image.yml
DELETED
@@ -1,44 +0,0 @@
|
|
1 |
-
name: Create and publish a Docker image
|
2 |
-
|
3 |
-
on: push
|
4 |
-
|
5 |
-
env:
|
6 |
-
REGISTRY: ghcr.io
|
7 |
-
IMAGE_NAME: ${{ github.repository }}
|
8 |
-
|
9 |
-
jobs:
|
10 |
-
build-and-push-image:
|
11 |
-
runs-on: ubuntu-latest
|
12 |
-
permissions:
|
13 |
-
contents: read
|
14 |
-
packages: write
|
15 |
-
|
16 |
-
steps:
|
17 |
-
- name: Checkout repository
|
18 |
-
uses: actions/checkout@v3
|
19 |
-
|
20 |
-
- name: Log in to the Container registry
|
21 |
-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
|
22 |
-
with:
|
23 |
-
registry: ${{ env.REGISTRY }}
|
24 |
-
username: ${{ github.actor }}
|
25 |
-
password: ${{ secrets.GITHUB_TOKEN }}
|
26 |
-
|
27 |
-
- name: Extract metadata (tags, labels) for Docker
|
28 |
-
id: meta
|
29 |
-
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
|
30 |
-
with:
|
31 |
-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
32 |
-
tags: |
|
33 |
-
type=ref,event=branch
|
34 |
-
type=sha
|
35 |
-
|
36 |
-
- name: Build and push Docker image
|
37 |
-
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
|
38 |
-
with:
|
39 |
-
context: .
|
40 |
-
push: true
|
41 |
-
tags: ${{ steps.meta.outputs.tags }}
|
42 |
-
labels: ${{ steps.meta.outputs.labels }}
|
43 |
-
build-args: |
|
44 |
-
SECRET_TOKEN=${{ secrets.GROQ_API_KEY }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.github/workflows/sync_to_hf.yml
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Sync to Hugging Face Space
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
permissions:
|
9 |
+
contents: write
|
10 |
+
|
11 |
+
jobs:
|
12 |
+
sync-to-space:
|
13 |
+
runs-on: ubuntu-latest
|
14 |
+
steps:
|
15 |
+
- uses: actions/checkout@v2
|
16 |
+
with:
|
17 |
+
fetch-depth: 0
|
18 |
+
|
19 |
+
- name: Prepare Hugging Face README
|
20 |
+
run: |
|
21 |
+
# Temporarily replace README.md for Hugging Face
|
22 |
+
mv README_hf.md README.md
|
23 |
+
|
24 |
+
- name: Push to Hugging Face Space
|
25 |
+
env:
|
26 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
27 |
+
HF_USERNAME: jatinmehra
|
28 |
+
HF_SPACE: PDF-Insight-PRO
|
29 |
+
run: |
|
30 |
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
31 |
+
git config --global user.name "github-actions[bot]"
|
32 |
+
git remote remove origin || true
|
33 |
+
git remote add origin "https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE}"
|
34 |
+
git add README.md
|
35 |
+
git commit -m "Update Hugging Face README" || true
|
36 |
+
git push origin main || (git branch -M main && git push -f origin main)
|
Dockerfile
CHANGED
@@ -1,29 +1,54 @@
|
|
1 |
-
|
2 |
-
FROM python:3.11-bullseye
|
3 |
|
4 |
-
# Set the working directory in the container
|
5 |
WORKDIR /app
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
RUN
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Accept the secret token as a build argument
|
17 |
-
ARG
|
|
|
18 |
|
19 |
-
#
|
20 |
-
RUN echo "[general]\nemail = \"[email protected]\"\n\n[api]\ntoken = \"$SECRET_TOKEN\"" > /app/.streamlit/secrets.toml
|
21 |
|
22 |
-
#
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
# Expose
|
26 |
-
EXPOSE
|
27 |
|
28 |
-
#
|
29 |
-
CMD ["
|
|
|
1 |
+
FROM python:3.12-slim
|
|
|
2 |
|
|
|
3 |
WORKDIR /app
|
4 |
|
5 |
+
# Install system dependencies for langchain
|
6 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
7 |
+
gcc \
|
8 |
+
python3-dev \
|
9 |
+
&& rm -rf /var/lib/apt/lists/*
|
10 |
|
11 |
+
# Create a non-root user and set up uploads directory
|
12 |
+
RUN useradd -m -s /bin/bash appuser && \
|
13 |
+
mkdir -p /app/uploads && \
|
14 |
+
chown appuser:appuser /app/uploads
|
15 |
|
16 |
+
# Copy application files and set permissions
|
17 |
+
COPY . .
|
18 |
+
RUN chown -R appuser:appuser /app && \
|
19 |
+
chmod -R u+rwx /app && \
|
20 |
+
chmod -R u+rwx /usr/local/lib/python3.12 /usr/local/bin
|
21 |
+
|
22 |
+
# Install dependencies and verify uvicorn
|
23 |
+
RUN python -m pip install --no-cache-dir -r requirements.txt && \
|
24 |
+
python -m pip install --no-cache-dir uvicorn && \
|
25 |
+
uvicorn --version
|
26 |
|
27 |
# Accept the secret token as a build argument
|
28 |
+
ARG GROQ_API_KEY
|
29 |
+
ARG TAVILY_API_KEY
|
30 |
|
31 |
+
# Docs: https://huggingface.co/docs/hub/en/spaces-sdks-docker#secrets-and-variables-management
|
|
|
32 |
|
33 |
+
# Expose the secret GROQ_API_KEY and OLLAMA_API_TOKEN at build time and set them as environment variables
|
34 |
+
RUN --mount=type=secret,id=GROQ_API_KEY,mode=0444,required=true \
|
35 |
+
export GROQ_API_KEY=$(cat /run/secrets/GROQ_API_KEY) && \
|
36 |
+
echo "GROQ_API_KEY is set."
|
37 |
+
|
38 |
+
RUN --mount=type=secret,id=TAVILY_API_KEY,mode=0444,required=true \
|
39 |
+
export TAVILY_API_KEY=$(cat /run/secrets/TAVILY_API_KEY) && \
|
40 |
+
echo "TAVILY_API_KEY is set."
|
41 |
+
|
42 |
+
|
43 |
+
# Set environment variables
|
44 |
+
ENV PYTHONPATH=/app \
|
45 |
+
PATH=/usr/local/bin:$PATH
|
46 |
+
|
47 |
+
# Switch to non-root user
|
48 |
+
USER appuser
|
49 |
|
50 |
+
# Expose Streamlit port
|
51 |
+
EXPOSE 7860
|
52 |
|
53 |
+
# Run the fastapi server
|
54 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|