Skip to content

Commit 5da16fc

Browse files
authored
Merge pull request #272 from Helene/multistage_dockerfile
Rework Dockerfile allowing build grafana-bridge image from Redhat UBI9/Python3.9
2 parents e3c36d1 + 1a0cdca commit 5da16fc

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

Dockerfile

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
ARG BUILD_ENV=prod
12
ARG BASE=registry.access.redhat.com/ubi9/ubi:9.5-1732804088
2-
FROM $BASE
3+
4+
FROM $BASE as build_prod
5+
ONBUILD COPY ./requirements/requirements_ubi9.txt /root/requirements_ubi9.txt
6+
7+
FROM $BASE as build_test
8+
ONBUILD COPY ./requirements/requirements_ubi.in /root/requirements_ubi.in
9+
10+
FROM $BASE as build_custom
11+
ONBUILD COPY ./requirements/requirements.in /root/requirements.in
12+
13+
FROM build_${BUILD_ENV}
14+
15+
ARG BUILD_ENV
16+
ARG BASE
317

418
LABEL com.ibm.name="IBM Storage Scale bridge for Grafana"
519
LABEL com.ibm.vendor="IBM"
@@ -26,11 +40,9 @@ ENV GID=$GROUPID
2640

2741
ARG HTTPPROTOCOL=http
2842
ENV PROTOCOL=$HTTPPROTOCOL
29-
RUN echo "the HTTP/S protocol is set to $PROTOCOL"
3043

3144
ARG HTTPBASICAUTH=True
3245
ENV BASICAUTH=$HTTPBASICAUTH
33-
RUN echo "the HTTP/S basic authentication is set to $BASICAUTH"
3446

3547
ARG AUTHUSER=None
3648
ENV BASICAUTHUSER=$AUTHUSER
@@ -40,15 +52,12 @@ ENV BASICAUTHPASSW=$AUTHPASSW
4052

4153
ARG HTTPPORT=None
4254
ENV PORT=$HTTPPORT
43-
RUN echo "the OpentTSDB API HTTP/S port is set to $PORT"
4455

4556
ARG PROMPORT=None
46-
ENV PROMETHEUS=$PROMPORT
47-
RUN echo "the Prometheus API HTTPS port is set to $PROMETHEUS"
57+
ENV PROMETHEUS=$PROMPORT
4858

4959
ARG PERFMONPORT=9980
5060
ENV SERVERPORT=$PERFMONPORT
51-
RUN echo "the PERFMONPORT port is set to $SERVERPORT"
5261

5362
ARG CERTPATH='/etc/bridge_ssl/certs'
5463
ENV TLSKEYPATH=$CERTPATH
@@ -67,27 +76,33 @@ ENV APIKEYVALUE=$KEYVALUE
6776

6877
ARG PMCOLLECTORIP=0.0.0.0
6978
ENV SERVER=$PMCOLLECTORIP
70-
RUN echo "the pmcollector server ip is set to $SERVER"
7179

7280
ARG DEFAULTLOGPATH='/var/log/ibm_bridge_for_grafana'
7381
ENV LOGPATH=$DEFAULTLOGPATH
74-
RUN echo "the log will use $LOGPATH"
7582

7683
ARG DEFAULTLOGLEVEL=15
7784
ENV LOGLEVEL=$DEFAULTLOGLEVEL
7885

79-
COPY ./requirements/requirements_ubi9.txt /root/requirements_ubi9.txt
80-
# COPY ./requirements/requirements_ubi.in /root/requirements_ubi.in
81-
82-
RUN yum install -y python39 python3-pip
83-
84-
# RUN /usr/bin/python3 -m pip install pip-tools && \
85-
# /usr/bin/python3 -m piptools compile /root/requirements_ubi.in --output-file /root/requirements_ubi9.txt && \
86-
# echo "Compiled python packages: $(cat /root/requirements_ubi9.txt)"
87-
88-
RUN /usr/bin/python3 -m pip install -r /root/requirements_ubi9.txt && \
89-
echo "Installed python version: $(/usr/bin/python3 -V)" && \
90-
echo "Installed python packages: $(/usr/bin/python3 -m pip list)"
86+
RUN echo "the HTTP/S protocol is set to $PROTOCOL" && \
87+
echo "the HTTP/S basic authentication is set to $BASICAUTH" && \
88+
echo "the OpentTSDB API HTTP/S port is set to $PORT" && \
89+
echo "the Prometheus API HTTPS port is set to $PROMETHEUS" && \
90+
echo "the PERFMONPORT port is set to $SERVERPORT" && \
91+
echo "the pmcollector server ip is set to $SERVER" && \
92+
echo "the log will use $LOGPATH"
93+
94+
RUN if [ $(expr "$BASE" : '.*python.*') -eq 0 ]; then \
95+
yum install -y python39 python3-pip; \
96+
if [ "$BUILD_ENV" = "build_test" ]; then \
97+
python3 -m pip install pip-tools && \
98+
python3 -m piptools compile /root/requirements_ubi.in --output-file /root/requirements_ubi9.txt && \
99+
echo "Compiled python packages: $(cat /root/requirements_ubi9.txt)"; fi && \
100+
python3 -m pip install -r /root/requirements_ubi9.txt && \
101+
echo "Installed python version: $(python3 -V)" && \
102+
echo "Installed python packages: $(python3 -m pip list)"; else \
103+
echo "Already using python container as base image. No need to install it." && \
104+
python3 -m pip install -r /root/requirements.in && \
105+
echo "Installed python packages: $(python3 -m pip list)"; fi
91106

92107
USER root
93108

@@ -101,8 +116,8 @@ COPY ./source/gpfsConfig/mmsdrfs* /var/mmfs/gen/
101116
COPY ./source/gpfsConfig/ZIMon* /opt/IBM/zimon/
102117

103118
RUN if [ "${APIKEYVALUE:0:1}" = "/" ]; then ln -s $APIKEYVALUE /etc/perfmon-api-keys; echo "APIKEYVALUE is a PATH"; else echo "APIKEYVALUE not a PATH"; fi && \
104-
if [ -z "$TLSKEYPATH" ] || [ -z "$TLSCERTFILE" ] || [ -z "$TLSKEYFILE" ] && [ "$PROTOCOL" = "https" ]; then echo "TLSKEYPATH FOR SSL CONNECTION NOT SET - ERROR"; exit 1; else echo "PASS"; fi
105-
RUN echo "the ssl certificates path is set to $TLSKEYPATH"
119+
if [ -z "$TLSKEYPATH" ] || [ -z "$TLSCERTFILE" ] || [ -z "$TLSKEYFILE" ] && [ "$PROTOCOL" = "https" ]; then echo "TLSKEYPATH FOR SSL CONNECTION NOT SET - ERROR"; exit 1; else echo "PASS"; fi && \
120+
echo "the ssl certificates path is set to $TLSKEYPATH"
106121

107122
# Switch to the working directory
108123
WORKDIR /opt/IBM/bridge

requirements/requirements.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is used for generating python requirements list "requirements.txt".
2+
# It includes the packages needed to be installed to run the IBM Storage Scale Performance Monitoring bridge for Grafana
3+
# on top of the Redhat ubi9/python-39 image.
4+
#
5+
# To update, run:
6+
#
7+
# $ pip-compile requirements_ubi.in --output-file requirements.txt
8+
#
9+
# setuptools
10+
cherrypy
11+
PyYAML
12+
# psutil
13+
# urllib3
14+
requests

requirements/requirements_ubi.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is used for generating python requirements list "requirements_ubi9.txt".
22
# It includes the packages needed to be installed to run the IBM Storage Scale Performance Monitoring bridge for Grafana
3-
# in an OpenShift production environment, on top of the redhat UBI8 image.
3+
# in an OpenShift production environment, on top of the Redhat UBI9 image.
44
#
55
# To update, run:
66
#

0 commit comments

Comments
 (0)