Update Jenkins Init Scripts 78/14778/5
authorTim Johnson <tijohnson@linuxfoundation.org>
Tue, 5 Mar 2019 22:46:52 +0000 (14:46 -0800)
committerTim Johnson <tijohnson@linuxfoundation.org>
Thu, 7 Mar 2019 20:51:26 +0000 (12:51 -0800)
Support ability to specify swap size and to pre-allocate the '/w' volume
for the Hyperledger Project

Change-Id: I04af514bbb237f405eb1d31ec10e3f019c85a43e
Signed-off-by: Tim Johnson <tijohnson@linuxfoundation.org>
jenkins-init-scripts/create-jenkins-user.sh
jenkins-init-scripts/create-swap-file.sh
releasenotes/notes/custom-swap-size-864fc8ca8343d4af.yaml [new file with mode: 0644]
releasenotes/notes/pre-existing-work-volume-05af4e8546facbea.yaml [new file with mode: 0644]

index 0005244..0983129 100755 (executable)
@@ -29,10 +29,14 @@ if grep -q mock /etc/group; then
     usermod -a -G mock jenkins
 fi
 
-mkdir /home/jenkins/.ssh /w
+mkdir /home/jenkins/.ssh
 cp -r "/home/${OS}/.ssh/authorized_keys" /home/jenkins/.ssh/authorized_keys
 
 # Generate ssh key for use by Robot jobs
 echo -e 'y\n' | ssh-keygen -N "" -f /home/jenkins/.ssh/id_rsa -t rsa
-chown -R jenkins:jenkins /home/jenkins/.ssh /w
+chown -R jenkins:jenkins /home/jenkins/.ssh
 chmod 700 /home/jenkins/.ssh
+
+# The '/w' volume may already be part of image
+[[ ! -d '/w' ]] && mkdir /w
+chown -R jenkins:jenkins /w
index cf8d97f..6f07738 100755 (executable)
@@ -9,7 +9,22 @@
 # http://www.eclipse.org/legal/epl-v10.html
 ##############################################################################
 
-dd if=/dev/zero of=/swap count=1024 bs=1MiB
+# Get the blockCount from the 'SWAP_SIZE' environmental variable
+blockCount=${SWAP_SIZE-''}
+
+# Validate SWAP_SIZE
+# Empty:   Set blockCount 1
+# Zero:    No Swap
+# Integer: Set blockCount
+# Else:    No Swap
+case $blockCount in
+    '')      blockCount=1 ;;
+    [0-9]*)  blockCount=$blockCount ;;
+    *)       exit ;;
+esac
+[[ $blockCount == 0 ]] && exit
+
+dd if=/dev/zero of=/swap count="${blockCount}k" bs=1MiB
 chmod 600 /swap
 mkswap /swap
 swapon /swap
diff --git a/releasenotes/notes/custom-swap-size-864fc8ca8343d4af.yaml b/releasenotes/notes/custom-swap-size-864fc8ca8343d4af.yaml
new file mode 100644 (file)
index 0000000..9ff6a47
--- /dev/null
@@ -0,0 +1,11 @@
+---
+prelude:
+  - |
+    Previously the swap size was fixed at 1GB.
+features:
+  - |
+    If the environmental variable 'SWAP_SIZE' is set when the
+    'init.sh' script is called, then a 'SWAP_SIZE' GB swap space will
+    be configured. If 'SWAP_SIZE' is '0' or is not a valid integer,
+    then no swap space is cofigured. If it is unset then 1GB of swap
+    will be configured.
diff --git a/releasenotes/notes/pre-existing-work-volume-05af4e8546facbea.yaml b/releasenotes/notes/pre-existing-work-volume-05af4e8546facbea.yaml
new file mode 100644 (file)
index 0000000..b09c101
--- /dev/null
@@ -0,0 +1,9 @@
+---
+prelude:
+  - |
+    The work directory (/w) was created in the '/' volume. The ownership was
+    set to 'jenkins:jenkins'.
+features:
+  - |
+    If the work directory or volume (/w) aleady exists, the ownership will be
+    recursivly set to 'jenkins:jenkins'.