-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDockerfile.recidiviz-base
More file actions
85 lines (69 loc) · 3.13 KB
/
Dockerfile.recidiviz-base
File metadata and controls
85 lines (69 loc) · 3.13 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
85
FROM ubuntu:noble
ENV DEBIAN_FRONTEND noninteractive
# NOTE: It is is extremely important that we do not delete this
# variable. One of our dependencies, dateparser, seems to require
# that TZ is defined (to be truly anything) in order to parse dates
# properly. If it is not defined, our date parsing will silently
# return None in a large set of circumstances which is of course,
# unideal.
ENV TZ America/New_York
RUN apt update -y && apt upgrade -y && \
apt install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
apt install -y \
locales \
git \
libxml2-dev libxslt1-dev \
default-jre \
libpq-dev \
build-essential \
python3.11-dev \
curl && \
rm -rf /var/lib/apt/lists/* && \
apt-get clean
RUN locale-gen en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LC_CTYPE en_US.UTF-8
ENV LANG en_US.UTF-8
# Postgres pulls in tzdata which must have these set to stay noninteractive.
RUN ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
# Make stdout/stderr unbuffered. This prevents delay between output and cloud
# logging collection.
ENV PYTHONUNBUFFERED 1
# If DEV_MODE="True", then install dependencies required for running tests
ARG DEV_MODE="False"
# Install postgres to be used by tests that need to write to a database from multiple threads.
RUN if [ "$DEV_MODE" = "True" ]; \
then \
apt-get update && \
apt-get install lsb-release wget -y && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install postgresql-13 -y && \
rm -rf /var/lib/apt/lists/* && \
apt-get clean; \
fi
# Add all the postgres tools installed above to the path, so that we can use pg_ctl, etc. in tests.
# Uses variable substitution to set PATH_PREFIX to '/usr/lib/postgresql/13/bin/' in DEV_MODE and otherwise leave it
# blank. Docker doesn't support setting environment variables within conditions, so we can't do this above.
ENV PATH_PREFIX=${DEV_MODE:+/usr/lib/postgresql/13/bin/:}
# Then prepend our path with whatever is in PATH_PREFIX.
ENV PATH="$PATH_PREFIX$PATH"
RUN adduser recidiviz && mkdir /app && chown recidiviz /app/
USER recidiviz
RUN curl -s https://bootstrap.pypa.io/get-pip.py 2>&1 | python3.11
ENV PATH=/home/recidiviz/.local/bin:$PATH
RUN pip install uv --user
# Add only the pyproject.toml/uv.lock first to ensure we cache `uv sync` when application code is updated but not the lock file
COPY --chown=recidiviz pyproject.toml /app/
COPY --chown=recidiviz uv.lock /app/
WORKDIR /app
# --frozen ensures we use exactly what's in the lock file without updating it
# --no-install-project avoids installing the project itself (source code isn't copied yet)
# --python specifies Python 3.11 since the system default may be different
RUN uv sync --frozen --no-install-project --python python3.11 $(if [ "$DEV_MODE" = "True" ]; then echo "--all-extras"; fi)
# Add the current commit SHA as an env variable
ARG CURRENT_GIT_SHA=""
ENV CURRENT_GIT_SHA=${CURRENT_GIT_SHA}
EXPOSE 8080