Skip to content

Commit a080ada

Browse files
committed
Refactor the docker file for build/run stage
1 parent 47b3933 commit a080ada

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

Dockerfile

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,49 @@
1-
FROM ubuntu:24.04
1+
FROM ubuntu:24.04 AS build-image
22

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/*
47

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"
711

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+
USER $APP_UID
948
ENTRYPOINT ["tini", "--"]
10-
CMD ["python3", "-u", "/opt/os-capacity/prometheus.py"]
49+
CMD ["os_capacity"]

0 commit comments

Comments
 (0)