-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (34 loc) · 1.42 KB
/
Dockerfile
File metadata and controls
48 lines (34 loc) · 1.42 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
# Base Stage
FROM python:3.12.7-alpine3.20@sha256:38e179a0f0436c97ecc76bcd378d7293ab3ee79e4b8c440fdc7113670cb6e204 AS base
WORKDIR /app
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
# Production Stage
FROM base AS production
# Copy the requirements file to the container
COPY requirements.txt /app/
# Install only production dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Create a non-root user named 'search-api-user' and group named 'search-api-group'
RUN addgroup -S search-api-group && \
adduser -S -D -G search-api-group -H -h /app search-api-user
# Set ownership of /app directory to the non-root user and group
RUN chown -R search-api-user:search-api-group /app
# Switch to the non-root user
USER search-api-user
# Only copy whats needed for production
COPY api /app/api
# Expose the port FastAPI will run on
EXPOSE 8000
# Start FastAPI server
CMD ["fastapi", "run", "/app/api/main.py", "--host", "0.0.0.0", "--port", "8000"]
# Testing Stage
FROM base AS test
# Copy the requirements file for the app & the test dependencies
COPY requirements.txt requirements-test.txt /app/
# Install both production and test dependencies
RUN pip install --no-cache-dir -r requirements.txt -r requirements-test.txt
# Copy everything in
COPY . /app
# Run tests using pytest as the default command for this stage, using the envs in pytest.ini
CMD ["pytest", "-c", "/app/test/pytest.ini", "--maxfail=1", "--disable-warnings", "-v"]