|
1 |
| -FROM ubuntu:22.04 |
| 1 | +FROM ubuntu:24.04 AS build-image |
2 | 2 |
|
3 |
| -RUN apt-get update && apt-get upgrade -y && apt-get install python3-pip tini -y && apt-get clean |
| 3 | +RUN apt-get update && \ |
| 4 | + apt-get upgrade -y && \ |
| 5 | + apt-get install python3-venv python3-dev gcc git -y && \ |
| 6 | + rm -rf /var/lib/apt/lists/* |
4 | 7 |
|
5 |
| -COPY ./requirements.txt /opt/os-capacity/requirements.txt |
6 |
| -RUN pip install -U -r /opt/os-capacity/requirements.txt |
| 8 | +# build into a venv we can copy across |
| 9 | +RUN python3 -m venv /opt/venv |
| 10 | +ENV PATH="/opt/venv/bin:$PATH" |
7 | 11 |
|
8 |
| -COPY ./os_capacity/prometheus.py /opt/os-capacity/prometheus.py |
| 12 | +COPY ./requirements.txt /os-capacity/requirements.txt |
| 13 | +RUN pip install -U pip setuptools |
| 14 | +RUN pip install --requirement /os-capacity/requirements.txt |
| 15 | + |
| 16 | +COPY . /os-capacity |
| 17 | +RUN pip install -U /os-capacity |
| 18 | + |
| 19 | +# |
| 20 | +# Now the image we run with |
| 21 | +# |
| 22 | +FROM ubuntu:24.04 AS run-image |
| 23 | + |
| 24 | +RUN apt-get update && \ |
| 25 | + apt-get upgrade -y && \ |
| 26 | + apt-get install --no-install-recommends python3 tini ca-certificates -y && \ |
| 27 | + rm -rf /var/lib/apt/lists/* |
| 28 | + |
| 29 | +# Copy accross the venv |
| 30 | +COPY --from=build-image /opt/venv /opt/venv |
| 31 | +ENV PATH="/opt/venv/bin:$PATH" |
| 32 | + |
| 33 | +# Create the user that will be used to run the app |
| 34 | +ENV APP_UID=1001 |
| 35 | +ENV APP_GID=1001 |
| 36 | +ENV APP_USER=app |
| 37 | +ENV APP_GROUP=app |
| 38 | +RUN groupadd --gid $APP_GID $APP_GROUP && \ |
| 39 | + useradd \ |
| 40 | + --no-create-home \ |
| 41 | + --no-user-group \ |
| 42 | + --gid $APP_GID \ |
| 43 | + --shell /sbin/nologin \ |
| 44 | + --uid $APP_UID \ |
| 45 | + $APP_USER |
| 46 | + |
| 47 | +# Don't buffer stdout and stderr as it breaks realtime logging |
| 48 | +ENV PYTHONUNBUFFERED=1 |
| 49 | + |
| 50 | +USER $APP_UID |
9 | 51 | ENTRYPOINT ["tini", "--"]
|
10 |
| -CMD ["python3", "-u", "/opt/os-capacity/prometheus.py"] |
| 52 | +CMD ["os_capacity"] |
0 commit comments