-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile
More file actions
42 lines (31 loc) · 1.21 KB
/
Dockerfile
File metadata and controls
42 lines (31 loc) · 1.21 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
# Use the smaller 'slim' version of Python to reduce image size
FROM python:3.12-slim@sha256:e97cf9a2e84d604941d9902f00616db7466ff302af4b1c3c67fb7c522efa8ed9
# Set environment variables for better Cloud Run compatibility
ENV PYTHONUNBUFFERED=True
ENV APP_HOME=/app
ENV PORT=8080
WORKDIR ${APP_HOME}
# Create a non-root user
RUN adduser --system --group app
# Install system dependencies for ssdeep and tlsh
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libfuzzy-dev \
ssdeep \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy only essential files first to leverage Docker's caching
COPY requirements.txt ./
# Install dependencies efficiently
RUN pip install --no-cache-dir --upgrade pip==25.0.1 && \
pip install --no-cache-dir -r requirements.txt
# Copy the rest of the app source code
COPY . ./
# Change ownership of the app directory to the non-root user
RUN chown -R app:app ${APP_HOME}
# Switch to non-root user
USER app
# Expose the port for Cloud Run
EXPOSE ${PORT}
# Use environment variable for port and dynamic worker allocation
CMD exec uvicorn main:app --host 0.0.0.0 --port ${PORT} --workers $(nproc) --limit-concurrency 60 --timeout-keep-alive 120 --log-level info