-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the docker file for build/run stage
- Loading branch information
1 parent
47b3933
commit a080ada
Showing
1 changed file
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
FROM ubuntu:24.04 | ||
FROM ubuntu:24.04 AS build-image | ||
|
||
RUN apt-get update && apt-get upgrade -y && apt-get install python3-pip tini -y && apt-get clean | ||
RUN apt-get update && \ | ||
apt-get upgrade -y && \ | ||
apt-get install python3-venv python3-dev gcc git -y && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
COPY ./requirements.txt /opt/os-capacity/requirements.txt | ||
RUN pip install -U -r /opt/os-capacity/requirements.txt | ||
# build into a venv we can copy across | ||
RUN python3 -m venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" | ||
|
||
COPY ./os_capacity/prometheus.py /opt/os-capacity/prometheus.py | ||
COPY ./requirements.txt /os-capacity/requirements.txt | ||
RUN pip install -U pip setuptools | ||
RUN pip install --requirement /os-capacity/requirements.txt | ||
|
||
COPY . /os-capacity | ||
RUN pip install -U /os-capacity | ||
|
||
# | ||
# Now the image we run with | ||
# | ||
FROM ubuntu:24.04 AS run-image | ||
|
||
RUN apt-get update && \ | ||
apt-get upgrade -y && \ | ||
apt-get install --no-install-recommends python3 tini ca-certificates -y && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy accross the venv | ||
COPY --from=build-image /opt/venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" | ||
|
||
# Create the user that will be used to run the app | ||
ENV APP_UID=1001 | ||
ENV APP_GID=1001 | ||
ENV APP_USER=app | ||
ENV APP_GROUP=app | ||
RUN groupadd --gid $APP_GID $APP_GROUP && \ | ||
useradd \ | ||
--no-create-home \ | ||
--no-user-group \ | ||
--gid $APP_GID \ | ||
--shell /sbin/nologin \ | ||
--uid $APP_UID \ | ||
$APP_USER | ||
|
||
USER $APP_UID | ||
ENTRYPOINT ["tini", "--"] | ||
CMD ["python3", "-u", "/opt/os-capacity/prometheus.py"] | ||
CMD ["os_capacity"] |