Severian commited on
Commit
1f54115
·
1 Parent(s): 45ac7d0

Update Dockerfile for correct directory structure

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -46
Dockerfile CHANGED
@@ -10,38 +10,27 @@ ENV NODE_OPTIONS="--max_old_space_size=3072" \
10
  PYTHONDONTWRITEBYTECODE=1
11
 
12
  # ============================================
13
- # Dependencies stage - caches node_modules
14
  # ============================================
15
- FROM base AS deps
16
 
17
  WORKDIR /app/web
18
 
19
- # Copy only package files for better caching
20
- COPY web/package.json web/yarn.lock ./
21
 
22
- # Use yarn with cache for faster installs
23
- RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \
24
- yarn config set cache-folder /usr/local/share/.cache/yarn && \
25
- yarn install --frozen-lockfile --network-timeout 300000
26
 
27
- # ============================================
28
- # Builder stage - builds Next.js application
29
- # ============================================
30
- FROM deps AS web-builder
31
-
32
- WORKDIR /app/web
33
 
34
- # Copy web source files
35
- COPY web/ .
36
-
37
- # Install dev dependencies needed for build
38
- RUN yarn add --dev autoprefixer postcss tailwindcss code-inspector-plugin
39
-
40
- # Build with standalone output
41
- RUN yarn build
42
 
43
  # ============================================
44
- # Python builder stage - builds Python deps
45
  # ============================================
46
  FROM python:3.10-slim-bookworm AS python-builder
47
 
@@ -53,24 +42,25 @@ RUN apt-get update && \
53
 
54
  WORKDIR /app/api
55
 
56
- # Use BuildKit's cache mount for pip
57
- RUN --mount=type=cache,target=/root/.cache/pip \
58
- pip install --no-cache-dir poetry
59
 
60
- # Copy and install Python dependencies
61
- COPY api/pyproject.toml api/poetry.lock ./
 
 
62
  RUN poetry config virtualenvs.create false && \
63
  poetry install --no-dev --no-interaction --no-ansi
64
 
65
  # ============================================
66
- # Final stage - minimal production image
67
  # ============================================
68
  FROM python:3.10-slim-bookworm
69
 
70
- # Create non-root user for HF security
71
  RUN useradd -m -u 1000 user
72
 
73
- # Install only required runtime packages
74
  RUN apt-get update && \
75
  apt-get install -y --no-install-recommends \
76
  nodejs \
@@ -78,27 +68,27 @@ RUN apt-get update && \
78
  curl \
79
  && rm -rf /var/lib/apt/lists/*
80
 
81
- # Set up directory structure
82
  WORKDIR /app
83
  RUN mkdir -p api web && chown -R user:user /app
84
 
85
- # Install core Python packages
86
- RUN --mount=type=cache,target=/root/.cache/pip \
87
- pip install --no-cache-dir \
88
  gunicorn \
89
  gevent \
90
  flask \
91
  cloudscraper \
92
  transformers
93
 
94
- # Copy built files from previous stages
95
  COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
96
- COPY --chown=user api/ /app/api/
97
 
98
- # Copy Next.js standalone build
99
- COPY --from=web-builder --chown=user /app/web/.next/standalone /app/web
100
- COPY --from=web-builder --chown=user /app/web/.next/static /app/web/.next/static
101
  COPY --from=web-builder --chown=user /app/web/public /app/web/public
 
 
102
 
103
  # Set environment variables
104
  ENV FLASK_APP=app.py \
@@ -115,19 +105,15 @@ ENV FLASK_APP=app.py \
115
  MAIL_TYPE=resend \
116
  MAIL_RESEND_API_KEY=null
117
 
118
- # Switch to non-root user
119
  USER user
120
-
121
- # Expose HF Spaces port
122
  EXPOSE 7860
123
 
124
- # Copy and set up entrypoint
125
- COPY --chown=user docker/entrypoint.sh /app/entrypoint.sh
126
  RUN chmod +x /app/entrypoint.sh
127
 
128
  WORKDIR /app
129
 
130
- # Add healthcheck
131
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
132
  CMD curl -f http://localhost:7860/health || exit 1
133
 
 
10
  PYTHONDONTWRITEBYTECODE=1
11
 
12
  # ============================================
13
+ # Web builder stage
14
  # ============================================
15
+ FROM base AS web-builder
16
 
17
  WORKDIR /app/web
18
 
19
+ # First copy package files
20
+ COPY ./web/package.json ./web/yarn.lock ./
21
 
22
+ # Install dependencies
23
+ RUN yarn install --frozen-lockfile --network-timeout 300000
 
 
24
 
25
+ # Copy web source
26
+ COPY ./web .
 
 
 
 
27
 
28
+ # Add required packages and build
29
+ RUN yarn add --dev autoprefixer postcss tailwindcss code-inspector-plugin && \
30
+ yarn build
 
 
 
 
 
31
 
32
  # ============================================
33
+ # Python builder stage
34
  # ============================================
35
  FROM python:3.10-slim-bookworm AS python-builder
36
 
 
42
 
43
  WORKDIR /app/api
44
 
45
+ # Install poetry
46
+ RUN pip install --no-cache-dir poetry
 
47
 
48
+ # Copy Python files
49
+ COPY ./api/pyproject.toml ./api/poetry.lock ./
50
+
51
+ # Install dependencies
52
  RUN poetry config virtualenvs.create false && \
53
  poetry install --no-dev --no-interaction --no-ansi
54
 
55
  # ============================================
56
+ # Final stage
57
  # ============================================
58
  FROM python:3.10-slim-bookworm
59
 
60
+ # Create non-root user
61
  RUN useradd -m -u 1000 user
62
 
63
+ # Install runtime dependencies
64
  RUN apt-get update && \
65
  apt-get install -y --no-install-recommends \
66
  nodejs \
 
68
  curl \
69
  && rm -rf /var/lib/apt/lists/*
70
 
71
+ # Create directories
72
  WORKDIR /app
73
  RUN mkdir -p api web && chown -R user:user /app
74
 
75
+ # Install Python packages
76
+ RUN pip install --no-cache-dir \
 
77
  gunicorn \
78
  gevent \
79
  flask \
80
  cloudscraper \
81
  transformers
82
 
83
+ # Copy Python files
84
  COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
85
+ COPY --chown=user ./api /app/api/
86
 
87
+ # Copy web files
88
+ COPY --from=web-builder --chown=user /app/web/.next /app/web/.next
 
89
  COPY --from=web-builder --chown=user /app/web/public /app/web/public
90
+ COPY --from=web-builder --chown=user /app/web/node_modules /app/web/node_modules
91
+ COPY --from=web-builder --chown=user /app/web/package.json /app/web/package.json
92
 
93
  # Set environment variables
94
  ENV FLASK_APP=app.py \
 
105
  MAIL_TYPE=resend \
106
  MAIL_RESEND_API_KEY=null
107
 
 
108
  USER user
 
 
109
  EXPOSE 7860
110
 
111
+ # Copy entrypoint
112
+ COPY --chown=user ./docker/entrypoint.sh /app/entrypoint.sh
113
  RUN chmod +x /app/entrypoint.sh
114
 
115
  WORKDIR /app
116
 
 
117
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
118
  CMD curl -f http://localhost:7860/health || exit 1
119