-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
95 lines (73 loc) · 2.41 KB
/
Dockerfile
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
86
87
88
89
90
91
92
93
94
95
# Set the Python version as a build-time argument
# with Python 3.12 as the default
ARG PYTHON_VERSION=3.12-slim-bullseye
FROM python:${PYTHON_VERSION}
# Create a virtual environment
RUN python -m venv /opt/venv
# Set the virtual environment as the current location
ENV PATH=/opt/venv/bin:$PATH
# Upgrade pip
RUN pip install --upgrade pip
# Set Python-related environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Install system dependencies
RUN apt-get update && apt-get install -y \
# for postgres
libpq-dev \
# for Pillow
libjpeg-dev \
# for CairoSVG
libcairo2 \
# other
gcc \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js and npm
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y nodejs && \
npm install -g npm@latest
# Create the application directory
RUN mkdir -p /code
# Set the working directory
WORKDIR /code
# Copy Python dependencies
COPY requirements.txt /tmp/requirements.txt
# Copy Node.js dependencies
COPY package.json package-lock.json /code/
# Copy Tailwind Config file
COPY tailwind.config.js /code
# Copy the application code
COPY ./src /code/src
# Install Python and Node.js dependencies
RUN pip install -r /tmp/requirements.txt
RUN npm ci
# Set environment variables for Django
ARG DJANGO_SECRET_KEY
ENV DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
ARG DJANGO_DEBUG=0
ENV DJANGO_DEBUG=${DJANGO_DEBUG}
# Static files collection
RUN npm run tailwind:build
RUN cd ./src && python manage.py collectstatic --noinput
# Set the working directory on /code/src
WORKDIR /code/src
# Set the default project name
ARG PROJ_NAME="home"
# Create a bash script to run the Django project
# this script will execute at runtime when
# the container starts and the database is available
RUN printf "#!/bin/bash\n" > ./paracord_runner.sh && \
printf "RUN_PORT=\"\${PORT:-8000}\"\n\n" >> ./paracord_runner.sh && \
printf "python manage.py migrate --no-input\n" >> ./paracord_runner.sh && \
printf "gunicorn ${PROJ_NAME}.wsgi:application --bind \"0.0.0.0:\$RUN_PORT\"\n" >> ./paracord_runner.sh
# Make the script executable
RUN chmod +x paracord_runner.sh
# Clean up apt cache to reduce image size
RUN apt-get remove --purge -y \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Run the Django project via the runtime script
# when the container starts
CMD ./paracord_runner.sh