-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
60 lines (45 loc) · 1.51 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
# syntax=docker/dockerfile:1
# Build stage for React app
FROM node:16 as react-build
WORKDIR /tmp/reactapp/
COPY reactapp/package.json reactapp/yarn.lock ./
RUN yarn install
COPY reactapp/public/ ./public/
COPY reactapp/src/ ./src/
RUN yarn build
# Build and runtime stage for Python app
FROM python:3.9-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user
RUN useradd -m appuser
# Set up the working directory
WORKDIR /srv/namubufferi/
# Install pipenv temporarily to generate requirements.txt
RUN pip install --no-cache-dir pipenv
# Copy Pipfile and Pipfile.lock
COPY Pipfile Pipfile.lock ./
# Generate requirements.txt from Pipfile and replace psycopg2 with psycopg2-binary
RUN pipenv requirements > requirements.txt && \
sed -i 's/psycopg2==2.9.10/psycopg2-binary==2.9.10/' requirements.txt
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Remove pipenv as it's no longer needed
RUN pip uninstall -y pipenv
# Copy application code
COPY . .
# Copy React build files
COPY --from=react-build /tmp/reactapp/static/ ./reactapp/static/
# Update entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Set ownership to non-root user
RUN chown -R appuser:appuser /srv/namubufferi/
# Switch to non-root user
USER appuser
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["gunicorn", "namubufferi.wsgi"]