From f21f6ef83887bf9ba43a70f356c225307ad7ae15 Mon Sep 17 00:00:00 2001
From: Erickson Silva de Oliveira <Erickson.SilvadeOliveira@windriver.com>
Date: Tue, 30 Jul 2024 11:30:57 -0300
Subject: [PATCH] Change stx-ceph-manager base image

The stx-ceph-manager image, which is used for rook-ceph,
was with ceph v14.2.2, which is the bare-metal version.
However, rook-ceph uses ceph v18.2.2.

Therefore, to maintain version compatibility, the base image
was updated to docker.io/openstackhelm/ceph-config-helper:
ubuntu_jammy_18.2.2-1-20240312 and all necessary adjustments
were made to the Dockerfile so that all STX packages could be
installed successfully.

Test Plan:
- PASS: Build stx-ceph-manager image
- PASS: Change the stx-ceph-manager deployment in
	the rook-ceph app to use this image
- PASS: Access the stx-ceph-manager pod and check
	the ceph version
- PASS: Check the pod logs to verify if there
	are any errors

Story: 2011066
Task: 50702

Depends-On: https://review.opendev.org/c/starlingx/utilities/+/924883
Depends-On: https://review.opendev.org/c/starlingx/app-rook-ceph/+/924884

Change-Id: I30371e7ed586f5b956668517bc1f9e5ed6b5cdce
Signed-off-by: Erickson Silva de Oliveira <Erickson.SilvadeOliveira@windriver.com>
---
 ceph/ceph-manager/debian/docker/Dockerfile | 85 +++++++++++++++++-----
 1 file changed, 68 insertions(+), 17 deletions(-)

diff --git a/ceph/ceph-manager/debian/docker/Dockerfile b/ceph/ceph-manager/debian/docker/Dockerfile
index ce2311f4..61cd6994 100644
--- a/ceph/ceph-manager/debian/docker/Dockerfile
+++ b/ceph/ceph-manager/debian/docker/Dockerfile
@@ -1,21 +1,72 @@
 ARG BASE
-FROM ${BASE}
+FROM ${BASE} AS stx-debian
 
-RUN     apt-get update -y &&    \
-        apt-get install -y      \
-        python3-oslo.messaging  \
-        python3-eventlet        \
-        python3-fm-api          \
-        fm-rest-api             \
-        python3-cephclient      \
-        python3-fmclient        \
-        fm-common               \
-        librados2               \
-        librbd1                 \
-        ceph-common             \
-        ceph-manager            \
-        ceph-mon                \
-        ceph-osd                \
-        ceph-mgr
+FROM docker.io/openstackhelm/ceph-config-helper:ubuntu_jammy_18.2.2-1-20240312
+
+RUN mkdir -p /tmp/build
+WORKDIR /tmp/build
+
+# Copy the STX sources list from the $BASE image
+COPY --from=stx-debian /etc/apt/sources.list.d/stx.list /etc/apt/sources.list.d/
+
+RUN apt-get update -y
+
+# Install python3.9
+RUN apt-get install -y               \
+    python3.9                        \
+    libpython3.9                     \
+    software-properties-common
+
+RUN add-apt-repository ppa:deadsnakes/ppa -y
+RUN apt-get install python3.9-distutils -y
+RUN add-apt-repository --remove ppa:deadsnakes/ppa -y
+
+# Install pip3.9
+RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
+RUN python3.9 get-pip.py
+
+# Install pip dependencies
+RUN pip3.9 install greenlet yappi
+
+# Install apt dependencies
+RUN apt-get install -y               \
+    python3-ldap=3.2.0-4ubuntu7.1    \
+    libpq5 libldap-2.4-2             \
+    python3-pyasn1                   \
+    python3-pyasn1-modules
+
+# Create fm user
+RUN useradd -ms /bin/bash fm
+
+# Change Python dependency version
+RUN apt-get download fm-common
+RUN dpkg-deb -x fm-common*.deb fm-common
+RUN dpkg-deb --control fm-common*.deb fm-common/DEBIAN
+RUN sed -i 's/<< 3.10/<< 3.11/g' fm-common/DEBIAN/control
+RUN dpkg-deb -b fm-common
+RUN dpkg -i fm-common.deb
+
+# Install STX packages
+RUN apt-get install -y               \
+    fm-rest-api                      \
+    python3-fm-api                   \
+    python3-fmclient                 \
+    python3-cephclient               \
+    ceph-manager
+
+# Ensures that ceph-manager will run on python3.9
+RUN sed -i 's/python3\.*[0-9]*/python3.9/g' /usr/bin/ceph-manager
+
+# Suppress warning messages because the mgr restful module is configured with a self-signed certificate
+ENV PYTHONWARNINGS="ignore:Unverified HTTPS request"
+RUN sed -i '/import sys/a import os\nos.environ["CURL_CA_BUNDLE"] = ""' /usr/bin/ceph-manager
+
+# Cleanup
+RUN rm -rf /tmp/build
+RUN rm -rf /var/lib/apt/lists/*
+RUN rm -f /etc/apt/sources.list.d/stx.list
+RUN apt-get clean
+
+WORKDIR /
 
 CMD ["bash"]