|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +node::install() { |
| 6 | + local download_file |
| 7 | + download_file="${TMP_DIR}/node${NODE_VERSION}.tar.gz" |
| 8 | + |
| 9 | + export node_install_dir="/tmp/node${NODE_VERSION}" |
| 10 | + export node_dir="${node_install_dir}/node-v${NODE_VERSION}-linux-x64" |
| 11 | + |
| 12 | + mkdir -p "${node_install_dir}" |
| 13 | + |
| 14 | + if [[ ! -f "${node_install_dir}/go/bin/go" ]]; then |
| 15 | + NODE_MD5="5bda713bd4aa39394536fc48c744854b" |
| 16 | + URL=https://buildpacks.cloudfoundry.org/dependencies/node/node-${NODE_VERSION}-linux-x64-40e8e080.tgz |
| 17 | + |
| 18 | + echo "-----> Download Nodejs ${NODE_VERSION}" |
| 19 | + curl -s -L --retry 15 --retry-delay 2 $URL -o ${download_file} |
| 20 | + |
| 21 | + DOWNLOAD_MD5=$(md5sum ${download_file} | cut -d ' ' -f 1) |
| 22 | + |
| 23 | + if [[ ${DOWNLOAD_MD5} != ${NODE_MD5} ]]; then |
| 24 | + echo " **ERROR** MD5 mismatch: got $DOWNLOAD_MD5 expected $NODE_MD5" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + |
| 28 | + tar xzf "${download_file}" -C "${node_install_dir}" |
| 29 | + rm "${download_file}" |
| 30 | + fi |
| 31 | + |
| 32 | + if [[ ! -f "${node_dir}/bin/node" ]]; then |
| 33 | + echo " **ERROR** Could not download nodejs" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + |
| 37 | + export NODE_HOME="${node_dir}" |
| 38 | +} |
| 39 | + |
| 40 | +declare git_url git_tag work_dir |
| 41 | +declare -x TAG NODE_VERSION TMP_DIR |
| 42 | + |
| 43 | +git_url="https://github.com/cloudfoundry-community/stratos.git" |
| 44 | +git_tag="${TAG:-master}}" |
| 45 | +work_dir="${PWD}" |
| 46 | +NODE_VERSION="${NODE_VERISON:-8.11.2}" |
| 47 | +TMP_DIR=/tmp |
| 48 | + |
| 49 | +git clone "${git_url}" stratos-ui || true |
| 50 | + |
| 51 | +if [[ -n ${git_tag} ]]; then |
| 52 | + pushd stratos-ui |
| 53 | + git checkout "${git_tag}" |
| 54 | + export stratos_version="${git_tag}" |
| 55 | + popd |
| 56 | +fi |
| 57 | + |
| 58 | +function exit_trap() { |
| 59 | + # See: install_nodejs.sh |
| 60 | + NODE_VERSION="8.11.2" |
| 61 | + rm -rf "/tmp/node${NODE_VERSION}.tar.gz" "/tmp/node${NODE_VERSION}" |
| 62 | +} |
| 63 | +trap exit_trap EXIT |
| 64 | + |
| 65 | +if ! which npm > /dev/null; then |
| 66 | + node::install |
| 67 | + export PATH="${NODE_HOME}/bin:$PATH" |
| 68 | +else |
| 69 | + npm_location="$(which npm)" |
| 70 | + export NODE_HOME="${npm_location%%/bin/npm}" |
| 71 | +fi |
| 72 | + |
| 73 | +mkdir -p cache |
| 74 | +build_dir="${work_dir}/stratos-ui" |
| 75 | + |
| 76 | +# Fix the "authenticity of host can't be established" error during build |
| 77 | +ssh-keyscan "bitbucket.org" >> ~/.ssh/known_hosts |
| 78 | + |
| 79 | +# prebuild ui |
| 80 | +cd stratos-ui |
| 81 | +npm install |
| 82 | +npm run prebuild-ui |
| 83 | +rm -Rf ./dist |
| 84 | + |
| 85 | +# Actually build Stratos |
| 86 | +bash -x deploy/cloud-foundry/build.sh "${build_dir}" "${work_dir}/cache" |
| 87 | +cd "${work_dir}" |
| 88 | + |
| 89 | +# Remove build artifacts (node_modules & bower_components) |
| 90 | +if [[ -d "${build_dir}/node_modules" ]]; then |
| 91 | + rm -rf "${build_dir}/node_modules" |
| 92 | +fi |
| 93 | + |
| 94 | +if [[ -d "${build_dir}/bower_components" ]]; then |
| 95 | + rm -rf "${build_dir}/bower_components" |
| 96 | +fi |
| 97 | + |
| 98 | +echo "web: ./deploy/cloud-foundry/start.sh" > "${build_dir}/Procfile" |
| 99 | + |
| 100 | +ls -lah "${build_dir}" |
| 101 | +cd "${build_dir}" |
| 102 | +zip -r "${work_dir}}/stratos-ui-packaged.zip" ./* |
| 103 | +cd "${work_dir}" |
| 104 | + |
| 105 | +exit 0 |
0 commit comments