Skip to content

Commit

Permalink
Improved package script workflow
Browse files Browse the repository at this point in the history
* moved variable declarations to the top of the script
* added a `package_version` variable to store the version of the package
* fixed logic to create the package in the correct directory
* cleaned up the exit_trap function to remove the temporary files if
  they exist
  • Loading branch information
dennisjbell committed Oct 7, 2024
1 parent fce7ccb commit 4a2455e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions bin/package
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#!/usr/bin/env bash
# shellcheck disable=SC2317

set -xeuo pipefail

declare git_url git_tag work_dir
declare -x TAG NODE_VERSION TMP_DIR

git_url="https://github.com/cloudfoundry-community/stratos.git"
git_tag="${TAG:-develop}"
work_dir="${PWD}"
NODE_VERSION="${NODE_VERISON:-20.13.1}"
NODE_SHA2="${NODE_SHA2:-71ec5c92b35770170dad21ff65130f3e4201e8a0bcd32986e5dcf32b57f379e6}"
TMP_DIR=/tmp

node::install() {
local download_file
download_file="${TMP_DIR}/node${NODE_VERSION}.tar.gz"
Expand All @@ -21,15 +32,14 @@ node::install() {
# source: https://nodejs.org/dist/v20.13.1/node-v20.13.1.tar.gz
# source_sha256: a85ee53aa0a5c2f5ca94fa414cdbceb91eb7d18a77fc498358512c14cc6c6991

NODE_SHA2="71ec5c92b35770170dad21ff65130f3e4201e8a0bcd32986e5dcf32b57f379e6"
URL=https://buildpacks.cloudfoundry.org/dependencies/node/node_${NODE_VERSION}_linux_x64_cflinuxfs4_71ec5c92.tgz

echo "-----> Download Nodejs ${NODE_VERSION}"
curl -s -L --retry 15 --retry-delay 2 $URL -o ${download_file}
curl -s -L --retry 15 --retry-delay 2 "$URL" -o "${download_file}"

DOWNLOAD_SHA2=$(sha256sum ${download_file} | cut -d ' ' -f 1)
DOWNLOAD_SHA2=$(sha256sum "${download_file}" | cut -d ' ' -f 1)

if [[ ${DOWNLOAD_SHA2} != ${NODE_SHA2} ]]; then
if [[ ${DOWNLOAD_SHA2} != "${NODE_SHA2}" ]]; then
echo " **ERROR** MD5 mismatch: got $DOWNLOAD_SHA2 expected $NODE_SHA2"
exit 1
fi
Expand All @@ -46,14 +56,6 @@ node::install() {
export NODE_HOME="${node_install_dir}"
}

declare git_url git_tag work_dir
declare -x TAG NODE_VERSION TMP_DIR

git_url="https://github.com/cloudfoundry-community/stratos.git"
git_tag="${TAG:-develop}"
work_dir="${PWD}"
NODE_VERSION="${NODE_VERISON:-20.13.1}"
TMP_DIR=/tmp

if [[ -z ${USE_LOCAL:-""} ]] ; then

Expand All @@ -73,10 +75,10 @@ if [[ -z ${VERSION:-""} ]] ; then
export stratos_version="${VERSION}" # Will be tagged on publish in Concourse
fi

function exit_trap() {
exit_trap() {
# See: install_nodejs.sh
NODE_VERSION="20.13.1"
rm -rf "/tmp/node${NODE_VERSION}.tar.gz" "/tmp/node${NODE_VERSION}"
[[ -d "${TMP_DIR}/node${NODE_VERSION}" ]] && rm -rf "${TMP_DIR}/node${NODE_VERSION}"
[[ -f "${TMP_DIR}/node${NODE_VERSION}.tar.gz" ]] && rm -rf "${TMP_DIR}/node${NODE_VERSION}.tar.gz"
}
trap exit_trap EXIT

Expand Down Expand Up @@ -117,10 +119,11 @@ echo "web: ./deploy/cloud-foundry/start.sh" > "${build_dir}/Procfile"

ls -lah "${build_dir}"
cd "${build_dir}"
if [[ -z ${BUILD_ROOT:-"" } ]] ; then
zip -r [email protected] "${BUILD_ROOT}/stratos-ui-packaged.zip" ./*
package_version="${stratos_version:-"dev-$(date +%Y%m%d%H%M%S)"}"
if [[ -n ${RELEASE_DIR:-""} ]] ; then
zip -r [email protected] "${RELEASE_DIR}/stratos-ui-${package_version}.zip" ./*
else
zip -r [email protected] "${work_dir}/stratos-ui-packaged.zip" ./*
zip -r [email protected] "${work_dir}/stratos-ui-${package_version}.zip" ./*
fi
cd "${work_dir}"

Expand Down

0 comments on commit 4a2455e

Please sign in to comment.