File size: 2,643 Bytes
9770efd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d258cf
bb58a5a
 
9770efd
 
 
 
 
 
bd965a2
9770efd
 
 
 
bd965a2
 
 
9770efd
 
e2f9f2b
 
 
 
 
 
bd965a2
9770efd
 
 
 
 
 
 
d58f938
 
 
 
9770efd
d58f938
9770efd
 
 
 
d58f938
9770efd
 
 
 
 
 
bd965a2
 
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
# Declare build arguments globally before any FROM statement.
ARG PYTHON_VERSION=3.12.1

# ---------------------------
# Stage 1: Node build environment
# ---------------------------
FROM node:20-alpine3.16 AS node-builder

WORKDIR /app
# Copy the entire project from the build context.
COPY . .

# Install required Alpine packages.
RUN apk add --no-cache \
      font-noto font-noto-cjk font-noto-extra \
      gcompat libstdc++ libuuid \
      vips-dev build-base jpeg-dev pango-dev cairo-dev \
      imagemagick libssl1.1 && \
    ln -s /lib/libresolv.so.2 /usr/lib/libresolv.so.2

# Install Node dependencies and install ts-node globally.
RUN npm install && \
    npm install -g ts-node \
    npx playwright install-deps \ 
    npx playwright install

# ---------------------------
# Stage 2: Python runtime environment
# ---------------------------
FROM python:${PYTHON_VERSION}-slim

# Update apt and install system dependencies AND Node.
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
          fontconfig fonts-dejavu fonts-dejavu-core fonts-dejavu-extra \
          fonts-liberation fonts-noto \
          git curl gnupg && \
    curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
    apt-get install -y nodejs && \
    rm -rf /var/lib/apt/lists/*

ENV npm_config_cache=/tmp/.npm

# Make sure that directory exists and is writable
RUN mkdir -p /tmp/.npm && chmod -R 777 /tmp/.npm
RUN mkdir -p /tmp/cache_dir && chmod -R 777 /tmp/cache_dir

# Set environment variable.
ENV PORT=7860

WORKDIR /app
# Copy the entire project from the build context.
COPY . .

# If the environment variables are set, clone the private repository.
RUN --mount=type=secret,id=GITHUB_REPO,required=true \
    --mount=type=secret,id=GITHUB_USERNAME,required=true \
    --mount=type=secret,id=GITHUB_TOKEN,required=true \
    if [ -n "$(cat /run/secrets/GITHUB_USERNAME)" ] && [ -n "$(cat /run/secrets/GITHUB_TOKEN)" ] && [ -n "$(cat /run/secrets/GITHUB_REPO)" ]; then \
      echo "Cloning private repository into 'social_session'"; \
      git clone https://$(cat /run/secrets/GITHUB_USERNAME):$(cat /run/secrets/GITHUB_TOKEN)@github.com/$(cat /run/secrets/GITHUB_USERNAME)/$(cat /run/secrets/GITHUB_REPO).git social_session; \
    else \
      echo "Skipping git clone: GITHUB_USERNAME, TOKEN, or GITHUB_REPO not set"; \
    fi


# Expose the port used by the ASGI server.
EXPOSE 7860

# Install your Python dependencies from requirements.txt.
RUN pip install -r requirements.txt

# Start the server using hypercorn.
CMD ["python", "-m", "hypercorn", "main:app", "-b", "0.0.0.0:7860", "-w", "8", "--keep-alive", "600"]