2727# - s) SBOM tool path.
2828# - t) Script to create SBOM for the container image.
2929# - u) Create Distroless container (e.g. true, false. If true, the script will also create a distroless container)
30+ # - v) Version extract command (e.g. 'busybox | head -1 | cut -c 10-15')
3031
3132# Assuming you are in your current working directory. Below should be the directory structure:
3233# │ rpms.tar.gz
5556# -j OUTPUT -k ./rpms.tar.gz -l ~/CBL-Mariner/.pipelines/containerSourceData \
5657# -m "false" -n "false" -p development -q "false" -u "true"
5758
58- while getopts " :a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:" OPTIONS; do
59+ while getopts " :a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v: " OPTIONS; do
5960 case ${OPTIONS} in
6061 a ) BASE_IMAGE_NAME_FULL=$OPTARG ;;
6162 b ) ACR=$OPTARG ;;
@@ -78,6 +79,7 @@ while getopts ":a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:" OPTIONS; do
7879 s ) SBOM_TOOL_PATH=$OPTARG ;;
7980 t ) SBOM_SCRIPT=$OPTARG ;;
8081 u ) DISTROLESS=$OPTARG ;;
82+ v ) VERSION_EXTRACT_CMD=$OPTARG ;;
8183
8284 \? )
8385 echo " Error - Invalid Option: -$OPTARG " 1>&2
@@ -113,6 +115,7 @@ function print_inputs {
113115 echo " CONTAINER_SRC_DIR -> $CONTAINER_SRC_DIR "
114116 echo " IS_HCI_IMAGE -> $IS_HCI_IMAGE "
115117 echo " USE_RPM_QA_CMD -> $USE_RPM_QA_CMD "
118+ echo " Version Extract Command -> $VERSION_EXTRACT_CMD "
116119 echo " REPO_PREFIX -> $REPO_PREFIX "
117120 echo " PUBLISHING_LEVEL -> $PUBLISHING_LEVEL "
118121 echo " PUBLISH_TO_ACR -> $PUBLISH_TO_ACR "
@@ -277,21 +280,26 @@ function set_image_tag {
277280 local containerId
278281 local installedPackage
279282
280- containerId=$( docker run --entrypoint /bin/bash -dt " $GOLDEN_IMAGE_NAME " )
283+ containerId=$( docker run --entrypoint /bin/sh -dt " $GOLDEN_IMAGE_NAME " )
281284
282285 echo " Container ID -> $containerId "
283286
284- if [[ $USE_RPM_QA_CMD =~ [Tt]rue ]] ; then
285- echo " Using rpm -qa command to get installed package ."
286- installedPackage =$( docker exec " $containerId " rpm -qa | grep ^ " $COMPONENT " )
287+ if [[ -n " $VERSION_EXTRACT_CMD " ]] ; then
288+ echo " Using custom version extract command ."
289+ COMPONENT_VERSION =$( docker exec " $containerId " sh -c " $VERSION_EXTRACT_CMD " )
287290 else
288- echo " Using tdnf repoquery command to get installed package."
289- # exec as root as the default user for some containers is non-root
290- installedPackage=$( docker exec -u 0 " $containerId " tdnf repoquery --installed " $COMPONENT " | grep ^" $COMPONENT " )
291+ if [[ $USE_RPM_QA_CMD =~ [Tt]rue ]] ; then
292+ echo " Using rpm -qa command to get installed package."
293+ installedPackage=$( docker exec " $containerId " rpm -qa | grep ^" $COMPONENT " )
294+ else
295+ echo " Using tdnf repoquery command to get installed package."
296+ # exec as root as the default user for some containers is non-root
297+ installedPackage=$( docker exec -u 0 " $containerId " tdnf repoquery --installed " $COMPONENT " | grep ^" $COMPONENT " )
298+ fi
299+ echo " Full Installed Package: -> $installedPackage "
300+ COMPONENT_VERSION=$( echo " $installedPackage " | awk ' {n=split($0,a,"-")};{split(a[n],b,".")}; {print a[n-1]"-"b[1]}' ) # 16.16.0-1
291301 fi
292302
293- echo " Full Installed Package: -> $installedPackage "
294- COMPONENT_VERSION=$( echo " $installedPackage " | awk ' {n=split($0,a,"-")};{split(a[n],b,".")}; {print a[n-1]"-"b[1]}' ) # 16.16.0-1
295303 echo " Component Version -> $COMPONENT_VERSION "
296304 docker rm -f " $containerId "
297305
0 commit comments