-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (65 loc) · 2.58 KB
/
Copy pathDockerfile
File metadata and controls
84 lines (65 loc) · 2.58 KB
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
# Stage 1: Build stage
FROM python:3.11-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Stage 2: Runtime stage
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
LOG_DIR=/app/logs \
LOG_LEVEL=INFO
WORKDIR /app
# Install docker-cli with all required dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
curl \
gosu \
gpg \
lsb-release \
apt-transport-https \
ca-certificates \
openssh-client \
&& curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list \
&& apt-get update \
&& apt-get install -y docker-ce-cli \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
RUN mkdir -p /app/logs && \
chmod 777 /app/logs
COPY . .
# Create non-root user and docker group
RUN groupadd -g 999 docker && \
useradd -m appuser && \
usermod -aG docker appuser && \
chown -R appuser:appuser /app && \
chmod -R 755 /app
# Set up SSH configuration for the appuser (key paths will be configured at runtime)
RUN mkdir -p /home/appuser/.ssh && \
echo "Host *" > /home/appuser/.ssh/config && \
echo " IdentitiesOnly yes" >> /home/appuser/.ssh/config && \
echo " StrictHostKeyChecking no" >> /home/appuser/.ssh/config && \
echo " UserKnownHostsFile /dev/null" >> /home/appuser/.ssh/config && \
chmod 600 /home/appuser/.ssh/config && \
chown -R appuser:appuser /home/appuser/.ssh
USER appuser
RUN git config --global user.email "appbuilder@synergiqai.com" && \
git config --global user.name "AppBuilder"
USER root
# Copy and set up entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Expose port
EXPOSE 8005
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# Command to run the application - disable access logging to stop health check spam
CMD ["uvicorn", "app.app:app", "--host", "0.0.0.0", "--port", "8005", "--workers", "2", "--no-access-log"]