Reduce cassandra-init image 01/143601/4
authorFiete Ostkamp <fiete.ostkamp@telekom.de>
Thu, 12 Mar 2026 12:49:36 +0000 (13:49 +0100)
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Fri, 13 Mar 2026 10:34:15 +0000 (10:34 +0000)
- remove unnecessary packages (libffi,libxml,curl,perl,npt,apt-transport)
- reduce sdctool.tar archive size (440MB -> 185MB) by excluding artifacts
  that are not used in the init image (zusammen-tools)
- extract sdctool.tar in separate stage to avoid it being saved as it's own
  image layer
- reduces image size from 2.7GB to 750MB

Issue-ID: SDC-4803
Change-Id: I129052200c76906034b6c0ddb89b29ca1dddd89a
Signed-off-by: Fiete Ostkamp <fiete.ostkamp@telekom.de>
.gitignore
asdctool/sdc-cassandra-init/Dockerfile
asdctool/tarball.xml
pom.xml

index 8a7712b..9596ce1 100644 (file)
@@ -195,3 +195,4 @@ Vagrantfile
 *.xls
 node_modules
 node
+*.tar
index 093466d..52348a1 100644 (file)
@@ -1,53 +1,33 @@
-# Base image
+# The build stage is necessary here to avoid including the tar file
+# in a separate image layer
+FROM eclipse-temurin:11-jre-jammy AS builder
+COPY sdctool.tar /tmp/sdctool.tar
+RUN mkdir -p /opt && \
+    tar -xf /tmp/sdctool.tar -C /opt && \
+    rm /tmp/sdctool.tar
+
 FROM eclipse-temurin:11-jre-jammy
-# Create a new group and user
-RUN addgroup --system sdc && \
-    adduser --system --ingroup sdc --shell /bin/sh sdc
-USER sdc
-WORKDIR /home/sdc
-# Create Cassandra configuration directory and file
-RUN mkdir -p ~/.cassandra/ && \
-    echo '[cql]' > ~/.cassandra/cqlshrc && \
-    echo 'version=3.4.4' >> ~/.cassandra/cqlshrc && \
-    chmod 600 ~/.cassandra/cqlshrc
-# Switch to root to install necessary packages
+
 USER root
-RUN apt-get update --allow-releaseinfo-change && \
-    apt-get install -y --no-install-recommends \
-        python3-pip \
-        libffi-dev \
-        libxml2-dev \
-        curl \
-        wget \
-        perl \
-        ntp \
-        apt-transport-https && \
-    python3 -m pip install --upgrade pip && \
+RUN groupadd -r sdc && useradd -r -g sdc -m sdc
+
+RUN apt-get update && \
+    apt-get install -y --no-install-recommends python3-pip && \
     pip3 install --no-cache-dir cqlsh==6.1.0 && \
-    apt-get purge -y python3-dev python3-apt && \
-    apt-get clean && \
+    apt-get purge -y python3-pip && \
     rm -rf /var/lib/apt/lists/* /root/.cache/pip
-# Switch back to system user for runtime
+
 USER sdc
 WORKDIR /home/sdc
-# Copy sdctool tar and startup
-COPY --chown=sdc:sdc sdctool.tar /home/sdc/sdctool.tar
-COPY --chown=sdc:sdc scripts /home/sdc/scripts
-COPY --chown=sdc:sdc startup.sh /home/sdc
-# Extract and prepare sdctool
-RUN tar -xvf /home/sdc/sdctool.tar -C /home/sdc && \
-    rm /home/sdc/sdctool.tar && \
-    mkdir -p /home/sdc/tools && \
-    cp -pr /home/sdc/sdctool/tools/* /home/sdc/tools && \
-    chmod +x /home/sdc/sdctool/scripts/* && \
-    chmod +x /home/sdc/tools/build/scripts/* && \
-    chmod +x /home/sdc/tools/scripts/* && \
-    chown -R sdc:sdc /home/sdc/tools/build/scripts/* && \
-    chmod +x /home/sdc/startup.sh && \
-    chmod +x /home/sdc/scripts/* && \
-    cp -r /home/sdc/scripts/janusgraph.properties /home/sdc/sdctool/config && \
-    cp -r /home/sdc/scripts/configuration.yaml /home/sdc/sdctool/config
-# Ensure all scripts are executable and owned by sdc
-RUN find /home/sdc -type f -name "*.sh" -exec chmod 750 {} \; && \
-    chown -R sdc:sdc /home/sdc
+
+COPY --from=builder --chown=sdc:sdc /opt/sdctool ./sdctool
+COPY --chown=sdc:sdc scripts ./scripts
+COPY --chown=sdc:sdc startup.sh ./
+
+RUN mkdir -p tools && \
+    cp -pr sdctool/tools/* tools/ && \
+    cp scripts/janusgraph.properties sdctool/config/ && \
+    cp scripts/configuration.yaml sdctool/config/ && \
+    find /home/sdc -type f -name "*.sh" -exec chmod 750 {} \;
+
 ENTRYPOINT ["/bin/sh", "/home/sdc/startup.sh"]
index e5fc2ec..145f544 100644 (file)
         <fileSet>
             <directory>${project.parent.basedir}/openecomp-be/tools</directory>
             <outputDirectory>tools</outputDirectory>
+            <excludes>
+                <!-- swagger-ui is a browser UI, not needed at init time -->
+                <exclude>swagger-ui/**</exclude>
+                <!-- zusammen-tools source and Maven build artifacts are not needed at runtime -->
+                <exclude>zusammen-tools/src/**</exclude>
+                <exclude>zusammen-tools/target/**</exclude>
+                <exclude>zusammen-tools/pom.xml</exclude>
+                <!-- migration and scripts dirs under tools are not referenced by startup -->
+                <exclude>migration/**</exclude>
+                <exclude>scripts/**</exclude>
+                <exclude>test.push/**</exclude>
+            </excludes>
         </fileSet>
     </fileSets>
-</assembly>
\ No newline at end of file
+</assembly>
diff --git a/pom.xml b/pom.xml
index fa700c6..bcda20f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -283,13 +283,13 @@ Modifications copyright (c) 2018-2019 Nokia
       <dependency>
         <groupId>net.logstash.logback</groupId>
         <artifactId>logstash-logback-encoder</artifactId>
-        <version>${logstash.encoder.version}</version> 
+        <version>${logstash.encoder.version}</version>
       </dependency>
     </dependencies>
   </dependencyManagement>
 
   <dependencies>
-    
+
     <dependency>
       <!-- must be on the classpath -->
       <groupId>org.jacoco</groupId>
@@ -604,6 +604,13 @@ Modifications copyright (c) 2018-2019 Nokia
               <goal>parse-version</goal>
             </goals>
           </execution>
+          <execution>
+            <id>parse-version-default</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>parse-version</goal>
+            </goals>
+          </execution>
         </executions>
       </plugin>