-
Notifications
You must be signed in to change notification settings - Fork 213
/
Dockerfile
91 lines (68 loc) · 2.35 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
82
83
84
85
86
87
88
89
90
91
# syntax=docker/dockerfile:1
# check=skip=InvalidDefaultArgInFrom
# 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 -yqq --no-install-recommends \
python3-dev \
&& apt-get autoremove -y \
&& 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="/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 -yqq --no-install-recommends \
curl \
libpq-dev \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir /worker_state
# Create a non-root user
RUN useradd ov_user \
&& chown ov_user /worker_state
USER ov_user
# Copy code into the final image
COPY --chown=ov_user . /ingestion_server/
# Exposes
# - 8001: Gunicorn server for `ingestion_server` Falcon app
# - 8002: Gunicorn server for `indexer_worker` Falcon app
EXPOSE 8001 8002
ARG SEMANTIC_VERSION
ENV SENTRY_RELEASE=$SEMANTIC_VERSION
CMD ["gunicorn", "--bind", "0.0.0.0:8001", "api:api"]