HERE="$(pwd)" CHALLENGE=${CHALLENGE:-test-tutorial-framework} LOGFILE=/tmp/bootstrap_tfw.log REMOTEBASE="git@github.com:avatao-content" libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" source "${libhack_dir}/common.sh" source "${libhack_dir}/baseimage.sh" bootstrap::run() { trap 'exit 1' INT trap handle_exit EXIT : > "${LOGFILE}" check_dependencies clone_required_repos_ask_ssh_or_https local tag tag="${BASEIMAGE_ONLY:-$(remotebase="${REMOTEBASE}" baseimage::latest_upstream_tag)}" tag=${tag} build_baseimage if [ -z "${BASEIMAGE_ONLY:-}" ]; then tag=${tag} pin_baseimage install_frontend_deps if [ "${TFWDEV:-0}" == "0" ]; then cleanup_repos merge_repos fi else delete_repos fi echo if [ -z "${BASEIMAGE_ONLY:-}" ]; then echo "You can build & start TFW by executing the command: ${CHALLENGE}/hack/tfw.sh start" else echo "Baseimage version ${BASEIMAGE_ONLY} built successfully!" fi } handle_exit() { if [[ $? -ne 0 ]]; then delete_repos showlog fi cleanlog } logged() { "$@" >> "${LOGFILE}" 2>&1; } showlog() { echo && echo "Error! Showing logs:" && cat "${LOGFILE}"; } cleanlog() { rm "${LOGFILE}"; } delete_repos() { pushd "${HERE}" && rm -rf "${BASEIMAGE_REPO}" "${FRONTEND_REPO}" "${CHALLENGE}" && popd; } check_dependencies() { local dependencies=("git" "docker" "yarn" "ng") local missing="0" for dep in ${dependencies[@]}; do if ! type "${dep}" > /dev/null 2>&1; then logged echo "Dependency '${dep}' not found!" missing="1" fi done if [ "${missing}" == "1" ]; then logged echo "Please install the missing packages and retry!" exit 1 fi if [ "${TFWDEV:-0}" == "0" ]; then if ! docker info > /dev/null 2>&1; then logged echo "The Docker daemon appears to be stopped. Please start it and try again!" exit 1 fi fi } clone_required_repos_ask_ssh_or_https() { if [[ -z "${HTTPS_REMOTES:-}" ]]; then read -p "Repos are pulled over SSH by default. Should I use HTTPS instead? [y/N]" -r -t 5 || : echo if [[ ${REPLY} =~ ^(y|Y|yes|Yes|YES)$ ]]; then HTTPS_REMOTES=1 clone_required_repos else HTTPS_REMOTES=0 clone_required_repos fi else clone_required_repos fi } clone_required_repos() { [[ "${HTTPS_REMOTES:-0}" == "1" ]] && REMOTEBASE="https://github.com/avatao-content" echo -n "Cloning TFW repositories... " echo -n "baseimage... " && logged git clone ${REMOTEBASE}/${BASEIMAGE_REPO}.git if [ -z "${BASEIMAGE_ONLY:-}" ]; then echo -n "frontend... " && logged git clone ${REMOTEBASE}/${FRONTEND_REPO}.git echo -n "test... " && logged git clone ${REMOTEBASE}/${CHALLENGE}.git fi echo "Done!" } install_frontend_deps() { echo -n "Installing frontend dependencies... " pushd "${FRONTEND_REPO}" spinned logged yarn install popd echo "Done!" } pin_baseimage() { echo -n "Pinning TFW baseimage version... " echo -n "which is ${tag}... " sed -i "1 s/.*/&:${tag}/" "${CHALLENGE}/solvable/Dockerfile" echo "Done!" } build_baseimage() { echo -n "Building baseimage at ${tag}... " pushd "${BASEIMAGE_REPO}" logged git checkout "${tag}" spinned logged docker build -t "${BASEIMAGE_NAME}:${tag}" . popd echo "Done!" } cleanup_repos() { rm -rf "${BASEIMAGE_REPO}" rm -rf "${CHALLENGE}/.git" rm -rf "${FRONTEND_REPO}/.git" } merge_repos() { echo -n "Merging repositories... " NESTED_FRONTEND="${CHALLENGE}/solvable/frontend" rm -rf "${NESTED_FRONTEND}" mv "${FRONTEND_REPO}" "${NESTED_FRONTEND}" echo "Done!" }