File size: 2,294 Bytes
0c0d5e5
 
7ce37bf
0c0d5e5
 
 
 
 
 
 
 
7ce37bf
0c0d5e5
 
 
 
7e4b3da
0c0d5e5
 
4680b44
7511c3d
7ce37bf
0c0d5e5
7ce37bf
7e4b3da
7ce37bf
0c0d5e5
 
 
4680b44
 
0c0d5e5
 
 
 
 
 
 
4680b44
0c0d5e5
 
 
4680b44
0c0d5e5
 
 
a4bef0b
496ca32
4680b44
 
0c0d5e5
a4bef0b
 
0c0d5e5
496ca32
 
 
0c0d5e5
 
a4bef0b
 
0c0d5e5
7ce37bf
 
 
efc5df0
a4bef0b
 
7ce37bf
 
 
 
 
 
 
 
a4bef0b
 
 
 
0c0d5e5
a4bef0b
 
 
 
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
# Base stage with shared configuration
FROM node:20.11-alpine3.19 AS base

# Configure build environment
ENV NODE_OPTIONS="--max_old_space_size=2048" \
    NEXT_TELEMETRY_DISABLED=1 \
    NODE_ENV=production \
    PYTHONDONTWRITEBYTECODE=1 \
    POETRY_NO_INTERACTION=1 \
    POETRY_VIRTUALENVS_CREATE=false \
    POETRY_CACHE_DIR=/cache/poetry

# Web builder stage
FROM base AS web-builder

WORKDIR /app/web

# Copy package files and install dependencies
COPY web/package.json web/yarn.lock ./
RUN yarn install --frozen-lockfile --network-timeout 300000 && \
    yarn add code-inspector-plugin

# Copy source and build
COPY web/ .
RUN yarn build

# Python builder stage
FROM python:3.10-slim-bookworm AS python-builder

# Install build dependencies in a single layer
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app/api

# Install and configure poetry
RUN pip install --no-cache-dir poetry

# Copy Python files and install dependencies
COPY api/pyproject.toml api/poetry.lock ./
RUN poetry config virtualenvs.create false && \
    poetry install --no-dev --no-interaction --no-ansi

# Final stage
FROM python:3.10-slim-bookworm

# Install runtime dependencies in a single layer
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    nodejs \
    npm \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy Python environment
COPY --from=python-builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY api/ /app/api/

# Copy web build artifacts
COPY --from=web-builder /app/web/.next /app/web/.next
COPY --from=web-builder /app/web/public /app/web/public
COPY --from=web-builder /app/web/node_modules /app/web/node_modules
COPY --from=web-builder /app/web/package.json /app/web/package.json

# Set environment variables
ENV FLASK_APP=app.py \
    EDITION=SELF_HOSTED \
    DEPLOY_ENV=PRODUCTION \
    CONSOLE_API_URL=http://127.0.0.1:5001 \
    CONSOLE_WEB_URL=http://127.0.0.1:3000 \
    SERVICE_API_URL=http://127.0.0.1:5001 \
    APP_WEB_URL=http://127.0.0.1:3000 \
    NODE_ENV=production

# Expose ports
EXPOSE 3000 5001

# Setup entrypoint
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

CMD ["/entrypoint.sh"]