1- FROM python:3.10-alpine AS python-base
2-
3- # install linux libraries necessary to compile some python packages
4- RUN apk update && \
5- apk add --no-cache bash build-base libffi-dev libressl-dev musl-dev zlib-dev gcompat
6-
7- # BUILD STAGE ---------------------------------------
8- # split this stage to save time and reduce image size
9- # ---------------------------------------------------
10- FROM python-base AS build
11-
12- WORKDIR /app
13-
14- # install python deps
15- RUN pip install --upgrade pip
16-
17- COPY requirements.txt requirements.txt
18- RUN pip install --user -r requirements.txt
19-
20- COPY horizon setup.py MANIFEST.in ./
21- RUN python setup.py install --user
22-
231# OPA BUILD STAGE -----------------------------------
242# build opa from source or download precompiled binary
253# ---------------------------------------------------
@@ -51,30 +29,32 @@ RUN if [ -f /custom/custom_opa.tar.gz ]; \
5129# MAIN IMAGE ----------------------------------------
5230# most of the time only this image should be built
5331# ---------------------------------------------------
54- FROM python-base
32+ FROM python:3.10-alpine
5533
5634WORKDIR /app
5735
5836RUN addgroup -S permit -g 1001
5937RUN adduser -S -s /bin/bash -u 1000 -G permit -h /home/permit permit
6038
61- # copy libraries from build stage
62- RUN mkdir /home/permit/.local
63- RUN mkdir /app/bin
64- COPY --from=build /root/.local /home/permit/.local
39+ # install linux libraries necessary to compile some python packages
40+ RUN apk update && \
41+ apk add --no-cache bash build-base libffi-dev libressl-dev musl-dev zlib-dev gcompat
6542
43+ # Copy custom opa binary
44+ RUN mkdir /app/bin
45+ RUN chown -R permit:permit /app/bin
6646COPY --from=opa_build --chmod=755 /opa /app/bin/opa
6747
6848# bash is needed for ./start/sh script
6949COPY scripts ./
7050
7151RUN mkdir -p /config
72- RUN chown -R permit:permit /app/bin
7352RUN chown -R permit:permit /config
7453
7554# copy wait-for-it (use only for development! e.g: docker compose)
7655COPY scripts/wait-for-it.sh /usr/wait-for-it.sh
7756RUN chmod +x /usr/wait-for-it.sh
57+
7858# copy startup script
7959COPY ./scripts/start.sh ./start.sh
8060RUN chmod +x ./start.sh
@@ -85,14 +65,18 @@ USER permit
8565
8666# copy Kong route-to-resource translation table
8767COPY kong_routes.json /config/kong_routes.json
88- # install sidecar package
8968
9069# copy gunicorn_config
9170COPY ./scripts/gunicorn_conf.py ./gunicorn_conf.py
92- # copy app code
93- COPY . ./
9471
95- RUN pip uninstall -y pip setuptools
72+ # install python dependencies
73+ COPY ./requirements.txt ./requirements.txt
74+ RUN pip install -r requirements.txt
75+ RUN python -m pip uninstall -y pip setuptools
76+ RUN rm -r /usr/local/lib/python3.10/ensurepip
77+
78+ # copy app code
79+ COPY ./horizon ./horizon
9680
9781# Make sure scripts in .local are usable:
9882ENV PATH="/:/app/bin:/home/permit/.local/bin:$PATH"
0 commit comments