Update Dockerfile for correct directory structure
Browse files- Dockerfile +36 -61
Dockerfile
CHANGED
@@ -4,101 +4,79 @@
|
|
4 |
FROM node:20.11-alpine3.19 AS base
|
5 |
|
6 |
# Configure build environment with optimized settings
|
7 |
-
ENV NODE_OPTIONS="--max_old_space_size=
|
8 |
NEXT_TELEMETRY_DISABLED=1 \
|
9 |
NODE_ENV=production \
|
10 |
PYTHONDONTWRITEBYTECODE=1 \
|
11 |
TZ=UTC
|
12 |
|
13 |
-
# Install base dependencies
|
14 |
-
RUN apk add --no-cache tzdata && \
|
15 |
-
ln -s /usr/share/zoneinfo/${TZ} /etc/localtime && \
|
16 |
-
echo ${TZ} > /etc/timezone
|
17 |
-
|
18 |
# ============================================
|
19 |
-
# Web builder stage
|
20 |
# ============================================
|
21 |
FROM base AS web-builder
|
22 |
|
23 |
-
WORKDIR /app
|
24 |
-
|
25 |
-
# Copy entire project first
|
26 |
-
COPY . .
|
27 |
-
|
28 |
-
# Navigate to web directory and install dependencies
|
29 |
WORKDIR /app/web
|
30 |
-
RUN yarn install --frozen-lockfile --production=false
|
31 |
|
32 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
RUN yarn build
|
34 |
|
35 |
# ============================================
|
36 |
-
# Python builder stage
|
37 |
# ============================================
|
38 |
FROM python:3.10-slim-bookworm AS python-builder
|
39 |
|
40 |
-
# Install build dependencies
|
41 |
RUN apt-get update && \
|
42 |
apt-get install -y --no-install-recommends \
|
43 |
-
gcc
|
44 |
-
|
45 |
-
&& rm -rf /var/lib/apt/lists/*
|
46 |
-
|
47 |
-
WORKDIR /app
|
48 |
|
49 |
-
|
50 |
-
COPY . .
|
51 |
-
|
52 |
-
# Install poetry with specific version
|
53 |
-
ENV POETRY_VERSION=1.8.3
|
54 |
-
RUN pip install --no-cache-dir poetry==${POETRY_VERSION}
|
55 |
|
56 |
-
#
|
57 |
-
|
58 |
-
POETRY_NO_INTERACTION=1 \
|
59 |
-
POETRY_VIRTUALENVS_IN_PROJECT=true \
|
60 |
-
POETRY_VIRTUALENVS_CREATE=true \
|
61 |
-
POETRY_REQUESTS_TIMEOUT=15
|
62 |
|
63 |
-
# Install
|
64 |
-
|
65 |
-
RUN poetry
|
|
|
66 |
|
67 |
# ============================================
|
68 |
-
# Final stage
|
69 |
# ============================================
|
70 |
FROM python:3.10-slim-bookworm
|
71 |
|
72 |
# Create non-root user
|
73 |
RUN useradd -m -u 1000 user
|
74 |
|
75 |
-
# Install runtime
|
76 |
RUN apt-get update && \
|
77 |
apt-get install -y --no-install-recommends \
|
78 |
-
|
79 |
-
|
80 |
-
&& apt-get update \
|
81 |
-
&& apt-get install -y --no-install-recommends \
|
82 |
-
expat=2.6.3-2 libldap-2.5-0=2.5.18+dfsg-3+b1 \
|
83 |
-
perl=5.40.0-6 libsqlite3-0=3.46.1-1 \
|
84 |
-
zlib1g=1:1.3.dfsg+really1.3.1-1+b1 \
|
85 |
-
fonts-noto-cjk \
|
86 |
-
&& apt-get autoremove -y \
|
87 |
-
&& rm -rf /var/lib/apt/lists/*
|
88 |
|
89 |
# Set up directory structure
|
90 |
WORKDIR /app
|
91 |
RUN mkdir -p api web && chown -R user:user /app
|
92 |
|
93 |
-
# Copy
|
94 |
-
|
95 |
-
COPY --from=python-builder /app/api/.venv ${VIRTUAL_ENV}
|
96 |
-
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
|
97 |
-
|
98 |
-
# Download NLTK data
|
99 |
-
RUN python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger')"
|
100 |
-
|
101 |
-
# Copy application files
|
102 |
COPY --chown=user api/ /app/api/
|
103 |
COPY --from=web-builder --chown=user /app/web/.next/standalone /app/web
|
104 |
COPY --from=web-builder --chown=user /app/web/.next/static /app/web/.next/static
|
@@ -129,7 +107,4 @@ RUN chmod +x /app/entrypoint.sh
|
|
129 |
|
130 |
WORKDIR /app
|
131 |
|
132 |
-
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
133 |
-
CMD curl -f http://localhost:7860/health || exit 1
|
134 |
-
|
135 |
CMD ["./entrypoint.sh"]
|
|
|
4 |
FROM node:20.11-alpine3.19 AS base
|
5 |
|
6 |
# Configure build environment with optimized settings
|
7 |
+
ENV NODE_OPTIONS="--max_old_space_size=2048" \
|
8 |
NEXT_TELEMETRY_DISABLED=1 \
|
9 |
NODE_ENV=production \
|
10 |
PYTHONDONTWRITEBYTECODE=1 \
|
11 |
TZ=UTC
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
# ============================================
|
14 |
+
# Web builder stage - optimized
|
15 |
# ============================================
|
16 |
FROM base AS web-builder
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
WORKDIR /app/web
|
|
|
19 |
|
20 |
+
# Copy only necessary files for build
|
21 |
+
COPY web/package.json web/yarn.lock ./
|
22 |
+
COPY web/next.config.js ./
|
23 |
+
COPY web/postcss.config.js ./
|
24 |
+
COPY web/tailwind.config.js ./
|
25 |
+
COPY web/tsconfig.json ./
|
26 |
+
COPY web/app ./app
|
27 |
+
COPY web/public ./public
|
28 |
+
|
29 |
+
# Install only production dependencies
|
30 |
+
RUN yarn config set network-timeout 300000 && \
|
31 |
+
yarn install --frozen-lockfile --production=true && \
|
32 |
+
yarn add --dev autoprefixer postcss tailwindcss code-inspector-plugin && \
|
33 |
+
yarn cache clean
|
34 |
+
|
35 |
+
# Build with reduced memory usage
|
36 |
+
ENV NODE_ENV=production
|
37 |
RUN yarn build
|
38 |
|
39 |
# ============================================
|
40 |
+
# Python builder stage - optimized
|
41 |
# ============================================
|
42 |
FROM python:3.10-slim-bookworm AS python-builder
|
43 |
|
44 |
+
# Install minimal build dependencies
|
45 |
RUN apt-get update && \
|
46 |
apt-get install -y --no-install-recommends \
|
47 |
+
gcc libffi-dev && \
|
48 |
+
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
49 |
|
50 |
+
WORKDIR /app/api
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
# Install poetry
|
53 |
+
RUN pip install --no-cache-dir poetry==1.8.3
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
# Install only production dependencies
|
56 |
+
COPY api/pyproject.toml api/poetry.lock ./
|
57 |
+
RUN poetry config virtualenvs.create false && \
|
58 |
+
poetry install --no-dev --no-interaction --no-ansi
|
59 |
|
60 |
# ============================================
|
61 |
+
# Final stage - minimal
|
62 |
# ============================================
|
63 |
FROM python:3.10-slim-bookworm
|
64 |
|
65 |
# Create non-root user
|
66 |
RUN useradd -m -u 1000 user
|
67 |
|
68 |
+
# Install only essential runtime packages
|
69 |
RUN apt-get update && \
|
70 |
apt-get install -y --no-install-recommends \
|
71 |
+
nodejs npm curl && \
|
72 |
+
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# Set up directory structure
|
75 |
WORKDIR /app
|
76 |
RUN mkdir -p api web && chown -R user:user /app
|
77 |
|
78 |
+
# Copy only necessary files
|
79 |
+
COPY --from=python-builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
COPY --chown=user api/ /app/api/
|
81 |
COPY --from=web-builder --chown=user /app/web/.next/standalone /app/web
|
82 |
COPY --from=web-builder --chown=user /app/web/.next/static /app/web/.next/static
|
|
|
107 |
|
108 |
WORKDIR /app
|
109 |
|
|
|
|
|
|
|
110 |
CMD ["./entrypoint.sh"]
|