From a118bb87cde258024493555d66277c219f7cffbf Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 29 Jan 2019 21:11:49 -0500 Subject: [PATCH 1/3] Clean root owned docker files before every step --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index e8bf12d..08c45f0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,6 +33,8 @@ def wrap = { fn-> variable: 'NEWRELIC_LICENSE_KEY_OVERRIDE')]) { sh (""" cp env.sh.sample env.sh + . bin/common.sh + clean_root_owned_docker_files rm -rf build mkdir build """) From 1d187c8c75efc6b3e8677199876bbd5ba0c2c192 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 29 Jan 2019 21:18:25 -0500 Subject: [PATCH 2/3] Move clean workspace scriptlet to full script --- Jenkinsfile | 8 +------- bin/clean-workspace.sh | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100755 bin/clean-workspace.sh diff --git a/Jenkinsfile b/Jenkinsfile index 08c45f0..a846962 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,13 +31,7 @@ def wrap = { fn-> variable: 'GOOGLE_APPLICATION_CREDENTIALS_OVERRIDE')]) { withCredentials([string(credentialsId: 'newrelic.license.key', variable: 'NEWRELIC_LICENSE_KEY_OVERRIDE')]) { - sh (""" - cp env.sh.sample env.sh - . bin/common.sh - clean_root_owned_docker_files - rm -rf build - mkdir build - """) + sh ("bin/clean-workspace.sh") fn() } } diff --git a/bin/clean-workspace.sh b/bin/clean-workspace.sh new file mode 100755 index 0000000..a227196 --- /dev/null +++ b/bin/clean-workspace.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# clean workspace +# +# Set bash unofficial strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail + +# Set DEBUG to true for enhanced debugging: run prefixed with "DEBUG=true" +${DEBUG:-false} && set -vx +# Credit to https://stackoverflow.com/a/17805088 +# and http://wiki.bash-hackers.org/scripting/debuggingtips +export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' + +# Credit to http://stackoverflow.com/a/246128/424301 +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BASE_DIR="$DIR/.." +BUILD_DIR="$BASE_DIR/build" +export BASE_DIR + +# shellcheck disable=SC1090 +. "$DIR/common.sh" + +cp "$BASE_DIR/env.sh.sample" "$BASE_DIR/env.sh" +clean_root_owned_docker_files +rm -rf "$BUILD_DIR" +mkdir "$BUILD_DIR" From fc63fa7175d45ea866c7aa42f4b037c16479c033 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 29 Jan 2019 21:22:05 -0500 Subject: [PATCH 3/3] Fix up CodeDeploy BASE_DIR --- bin/codedeploy/AfterInstall.sh | 2 +- bin/codedeploy/ApplicationStart.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/codedeploy/AfterInstall.sh b/bin/codedeploy/AfterInstall.sh index 93d1db5..2fcbca4 100755 --- a/bin/codedeploy/AfterInstall.sh +++ b/bin/codedeploy/AfterInstall.sh @@ -16,7 +16,7 @@ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' # Credit to http://stackoverflow.com/a/246128/424301 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -BASE_DIR="$DIR/.." +BASE_DIR="$DIR/../.." ANSIBLE_DIR="$BASE_DIR/ansible" # Invoke Ansible for final set up diff --git a/bin/codedeploy/ApplicationStart.sh b/bin/codedeploy/ApplicationStart.sh index 5d08139..c2698ca 100755 --- a/bin/codedeploy/ApplicationStart.sh +++ b/bin/codedeploy/ApplicationStart.sh @@ -16,7 +16,7 @@ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' # Credit to http://stackoverflow.com/a/246128/424301 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -BASE_DIR="$DIR/.." +BASE_DIR="$DIR/../.." ANSIBLE_DIR="$BASE_DIR/ansible" # Invoke Ansible for final set up