Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (42 loc) · 2.06 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (42 loc) · 2.06 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
# Dockerfile for the USAspending Backend API
# When built with docker compose --profile usaspending build,
# it will be built and tagged with the name in the image: key of the docker compose services that use this default Dockerfile
# Since requirements are copied into the image at build-time, this MUST be rebuilt if Python requirements change
# See docker-compose.yml file and README.md for docker compose information
FROM python:3.12.11-slim-trixie
COPY --from=ghcr.io/astral-sh/uv:0.12.18 /uv /uvx /bin/
WORKDIR /usaspending-api
RUN apt update && apt install -y \
ca-certificates \
curl \
gcc \
libpq-dev \
openssl \
gnupg2 \
lsb-release
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg && \
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
apt update && \
apt install -y postgresql-16
RUN update-ca-certificates
##### The following ENV vars are optimizations from https://github.com/astral-sh/uv-docker-example/blob/main/Dockerfile
##### and https://docs.astral.sh/uv/guides/integration/docker/#optimizations
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy
# Use the system Python environment since the container is already isolated
ENV UV_PROJECT_ENVIRONMENT=/usr/local
ENV UV_SYSTEM_PYTHON=1
# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --extra server --extra ansible --extra awscli --extra spark --locked --no-install-project --no-dev
# Copy the project into the image
COPY . /usaspending-api
# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --extra server --extra ansible --extra awscli --extra spark --locked --no-dev
##### Ensure Python STDOUT gets sent to container logs
ENV PYTHONUNBUFFERED=1