Browse code

make-docker-image.sh: nit pick fixes

Change-Id: I113cc137bee25e96e50e268ffaa883e242d2262b
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/c/photon/+/23774
Tested-by: gerrit-photon <photon-checkins@vmware.com>

Shreenidhi Shedi authored on 2024/04/20 16:30:05
Showing 1 changed files
... ...
@@ -2,44 +2,43 @@
2 2
 
3 3
 set -ex
4 4
 
5
-echoerr()
6
-{
5
+echoerr() {
7 6
   echo -e "$*" 1>&2
8 7
 }
9 8
 
10
-echo PHOTON_RELEASE_VERSION=$PHOTON_RELEASE_VERSION
9
+echo "PHOTON_RELEASE_VERSION=${PHOTON_RELEASE_VERSION}"
11 10
 arch="$(uname -m)"
12
-TEMP_CHROOT=$(pwd)/temp_chroot
13
-ROOTFS_TAR_FILENAME=photon-rootfs-$PHOTON_RELEASE_VERSION-$PHOTON_BUILD_NUMBER.${arch}.tar.gz
14
-STAGE_DIR=$(pwd)/stage
11
+TEMP_CHROOT="${PWD}/temp_chroot"
12
+ROOTFS_TAR_FILENAME="photon-rootfs-${PHOTON_RELEASE_VERSION}-${PHOTON_BUILD_NUMBER}.${arch}.tar.gz"
13
+STAGE_DIR="${PWD}/stage"
15 14
 
16 15
 rm -rf /etc/yum.repos.d/*
17 16
 
18 17
 cat > /etc/yum.repos.d/photon-local.repo <<- EOF
19 18
 [photon-local]
20 19
 name=VMware Photon Linux ${PHOTON_RELEASE_VERSION}($arch)
21
-baseurl=file://$(pwd)/stage/RPMS
20
+baseurl=file://${PWD}/stage/RPMS
22 21
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY
23 22
 gpgcheck=0
24 23
 enabled=1
25 24
 skip_if_unavailable=True
26 25
 EOF
27 26
 
28
-rm -rf $TEMP_CHROOT
29
-mkdir $TEMP_CHROOT
27
+rm -rf ${TEMP_CHROOT}
28
+mkdir ${TEMP_CHROOT}
30 29
 
31 30
 tdnf install -y --setopt=tsflags=nodocs rpm tar gzip grep coreutils
32 31
 
33
-rpm --root $TEMP_CHROOT/ --initdb
32
+rpm --root ${TEMP_CHROOT}/ --initdb
34 33
 
35 34
 tdnf --releasever ${PHOTON_RELEASE_VERSION} \
36
-     --installroot $TEMP_CHROOT/ \
35
+     --installroot ${TEMP_CHROOT}/ \
37 36
      --rpmverbosity error \
38 37
      --setopt=tsflags=nodocs \
39 38
      install -y \
40 39
      filesystem bash toybox tdnf photon-release photon-repos curl
41 40
 
42
-actual_pkg_list=($(tdnf --installroot $TEMP_CHROOT/ \
41
+actual_pkg_list=($(tdnf --installroot ${TEMP_CHROOT}/ \
43 42
                         --disablerepo=* -q \
44 43
                         list installed 2>/dev/null | cut -d'.' -f1))
45 44
 
... ...
@@ -57,38 +56,38 @@ expected_pkg_count=${#expected_pkg_list[@]}
57 57
 pkg_diff="$(echo ${expected_pkg_list[@]} ${actual_pkg_list[@]} | \
58 58
             tr ' ' '\n' | sort | uniq -u)"
59 59
 
60
-if [ $expected_pkg_count -ne $actual_pkg_count ] || [ -n "${pkg_diff}" ]; then
60
+if [ ${expected_pkg_count} -ne ${actual_pkg_count} ] || [ -n "${pkg_diff}" ]; then
61 61
   echoerr "Following package difference found in docker image:\n${pkg_diff}"
62
-  echoerr "Expected package count: $expected_pkg_count"
63
-  echoerr "Actual package count: $actual_pkg_count"
64
-  rm -rf $TEMP_CHROOT
62
+  echoerr "Expected package count: ${expected_pkg_count}"
63
+  echoerr "Actual package count: ${actual_pkg_count}"
64
+  rm -rf ${TEMP_CHROOT}
65 65
   exit 1
66 66
 fi
67 67
 
68
-rpm --root $TEMP_CHROOT/ --import $TEMP_CHROOT/etc/pki/rpm-gpg/*
68
+rpm --root ${TEMP_CHROOT}/ --import ${TEMP_CHROOT}/etc/pki/rpm-gpg/*
69 69
 
70 70
 # cleanup anything not needed inside rootfs
71
-pushd $TEMP_CHROOT
71
+pushd ${TEMP_CHROOT}
72 72
 rm -rf usr/src/ home/* var/log/* var/cache/tdnf/
73 73
 # set TERM to linux due to stripped terminfo
74 74
 echo "export TERM=linux" >> etc/bash.bashrc
75 75
 
76
-tar -I 'gzip -9' -cpf ../$ROOTFS_TAR_FILENAME .
76
+tar -I 'gzip -9' -cpf ../${ROOTFS_TAR_FILENAME} .
77 77
 popd
78 78
 
79 79
 # expected size plus 2% wiggle room
80 80
 max_size=17313736
81 81
 
82
-actual_size=$(wc -c $ROOTFS_TAR_FILENAME | cut -d' ' -f1)
83
-if (( $actual_size > $max_size )); then
82
+actual_size=$(wc -c ${ROOTFS_TAR_FILENAME} | cut -d' ' -f1)
83
+if (( ${actual_size} > ${max_size} )); then
84 84
   echoerr "ERROR: docker image tarball size is bigger than expected"
85
-  echoerr "Expected size(in bytes): $max_size"
86
-  echoerr "Actual size(in bytes): $actual_size"
87
-  rm -rf $TEMP_CHROOT $ROOTFS_TAR_FILENAME
85
+  echoerr "Expected size(in bytes): ${max_size}"
86
+  echoerr "Actual size(in bytes): ${actual_size}"
87
+  rm -rf ${TEMP_CHROOT} ${ROOTFS_TAR_FILENAME}
88 88
   exit 1
89 89
 fi
90 90
 
91
-mv $ROOTFS_TAR_FILENAME $STAGE_DIR/
91
+mv ${ROOTFS_TAR_FILENAME} ${STAGE_DIR}/
92 92
 
93 93
 # cleanup
94
-rm -rf $TEMP_CHROOT
94
+rm -rf ${TEMP_CHROOT}