File size: 2,664 Bytes
fa5a125
947c08e
 
 
 
 
 
 
694f978
947c08e
 
 
694f978
 
 
 
 
 
e8156a5
5a23da9
947c08e
 
694f978
 
 
 
 
947c08e
694f978
0433687
694f978
 
947c08e
7d7916a
ff55134
3b9b6f1
ff55134
694f978
ff55134
0433687
 
 
a19c976
 
694f978
947c08e
7d7916a
 
c4685d0
7d7916a
 
 
 
 
 
c4685d0
aae91f6
c4685d0
aae91f6
 
c2f6a7b
 
 
 
 
 
780bc15
fa5a125
 
 
 
aae91f6
58b20c3
d34638f
58b20c3
9ae455b
3601b10
9ae455b
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
# syntax=docker/dockerfile:1.3
ARG PYTHON_VERSION=3.12-slim-bullseye

FROM python:${PYTHON_VERSION}

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Install dependencies
RUN apt-get update && apt-get install -y \
    libpq-dev \
    gcc \
    g++ \
    wget \
    unzip \
    xvfb \
    libxi6 \
    libgconf-2-4 \
    gnupg \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Install Chrome
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
    && apt-get update \
    && apt-get install -y google-chrome-stable

# Install ChromeDriver
RUN CHROMEDRIVER_VERSION=$(curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE) \
    && wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip \
    && unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Install Python dependencies
COPY --chown=user requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir -r /tmp/requirements.txt

# Copy application code
COPY --chown=user . /code
WORKDIR /code

USER root
# Use secrets during build
RUN mkdir -p /secrets
RUN --mount=type=secret,id=HOST,required=true \
    --mount=type=secret,id=DJANGO_SECRET,required=true \
    --mount=type=secret,id=SECURE_TOKEN,required=true \
    --mount=type=secret,id=WORKER_TOKEN,required=true \
    --mount=type=secret,id=CLOUDFLARE_TURNSTILE_SECRET,required=true \
    --mount=type=secret,id=REDIS_URL,required=true \
    bash -c 'cp -r /run/secrets/* /secrets/'

RUN chown -R user:user /secrets
USER user

RUN bash -c 'export HOST=$(cat /secrets/HOST) && \
             export DJANGO_SECRET=$(cat /secrets/DJANGO_SECRET) && \
             export SECURE_TOKEN=$(cat /secrets/SECURE_TOKEN) && \
             export WORKER_TOKEN=$(cat /secrets/WORKER_TOKEN) && \
             export CLOUDFLARE_TURNSTILE_SECRET=$(cat /secrets/CLOUDFLARE_TURNSTILE_SECRET) && \
             export REDIS_URL=$(cat /secrets/REDIS_URL) && \
             python manage.py makemigrations && \
             python manage.py migrate --database=default && \
             python manage.py migrate --database=cache && \
             python manage.py migrate --database=DB1 && \
             python manage.py migrate --database=DB2'

USER root
RUN rm -rf /secrets
USER user

CMD ["uvicorn", "core.asgi:application", "--host", "0.0.0.0", "--port", "7860", "--log-level", "debug"]