forked from WordPress/openverse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
81 lines (60 loc) · 2.19 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1
# Automatically build image using Python version specified in the `Pipfile`.
ARG INGESTION_PY_VERSION
##################
# Python builder #
##################
FROM docker.io/python:${INGESTION_PY_VERSION} as builder
# Container optimizations
ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1
ENV PIP_NO_COLOR=1
# Activate the virtualenv
ENV PATH="/venv/bin:$PATH"
# - Install system packages needed for building Python dependencies
# - Create a virtualenv inside `/venv`
# - Install Pipenv to install Python dependencies
RUN apt-get update \
&& apt-get install -y python3-dev \
&& rm -rf /var/lib/apt/lists/* \
&& python -m venv /venv \
&& pip install --upgrade pipenv
# Copy the Pipenv files into the container
COPY Pipfile Pipfile.lock ./
# Install Python dependencies system-wide (uses the active virtualenv)
RUN pipenv install --system --deploy --dev
####################
# Ingestion server #
####################
FROM docker.io/python:${INGESTION_PY_VERSION}-slim as ing
LABEL org.opencontainers.image.source="https://github.com/WordPress/openverse"
# Container optimizations
ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1
ENV PIP_NO_COLOR=1
# Activate the virtualenv
ENV PATH="/venv/bin:$PATH"
ENV PYTHONPATH="$PYTHONPATH:/ingestion_server/"
# TLDEXTRACT fails to cache in /home/supervisord, set its cache to /tmp instead
ENV TLDEXTRACT_CACHE="/tmp/python-tldextract"
WORKDIR /ingestion_server
# Copy virtualenv from the builder image
COPY --from=builder /venv /venv
# - Install system packages needed for running Python dependencies
# - libpq-dev: required by `psycopg2`
# - Create directory for holding worker state
RUN apt-get update \
&& apt-get install -y curl libpq-dev libc-bin=2.36-9+deb12u3 libc6=2.36-9+deb12u3 \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir /worker_state
# Create a non-root user
RUN useradd ingestionu
RUN chown ingestionu /worker_state
USER ingestionu
# Copy code into the final image
COPY --chown=ingestionu . /ingestion_server/
# Exposes
# - 8001: Gunicorn server for `ingestion_server` Falcon app
# - 8002: Gunicorn server for `indexer_worker` Falcon app
EXPOSE 8001 8002
CMD ["gunicorn", "--bind", "0.0.0.0:8001", "api:api"]