mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-12-05 02:31:33 +00:00
Integrate old bootstrap_tfw_dev.sh into tfw.sh
This commit is contained in:
parent
0f9b5920c1
commit
df285fea58
@ -1,193 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
set -o pipefail
|
||||
set -o errtrace
|
||||
shopt -s expand_aliases
|
||||
[ "$(uname)" == "Darwin" ] && alias sed="gsed" || :
|
||||
|
||||
pushd() { command pushd "$@" > /dev/null; }
|
||||
popd() { command popd "$@" > /dev/null; }
|
||||
|
||||
TFWDEV="${TFWDEV:-0}"
|
||||
HTTPS_REMOTES="${HTTPS_REMOTES:-}"
|
||||
|
||||
TFW_POSTFIX=tutorial-framework
|
||||
BASEDIR="$(pwd)"
|
||||
BASEIMAGE=baseimage-${TFW_POSTFIX}
|
||||
TEST=test-${TFW_POSTFIX}
|
||||
FRONTEND=frontend-${TFW_POSTFIX}
|
||||
BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}"
|
||||
|
||||
LOGFILE=/tmp/bootstrap_tfw.log
|
||||
|
||||
remotebase="git@github.com:"
|
||||
|
||||
run()
|
||||
{
|
||||
trap 'exit 1' INT
|
||||
trap handle_exit EXIT
|
||||
: > $LOGFILE
|
||||
|
||||
check_dependencies
|
||||
clone_required_repos_ask_ssh_or_https
|
||||
TAG="${BASEIMAGE_ONLY:-$(fetch_latest_tag)}"
|
||||
TAG=$TAG build_baseimage
|
||||
|
||||
if [ -z "${BASEIMAGE_ONLY:-}" ]; then
|
||||
TAG=$TAG pin_baseimage
|
||||
install_frontend_deps
|
||||
if [ "$TFWDEV" == "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: ${TEST}/hack/tfw.sh start"
|
||||
else
|
||||
echo "Baseimage version ${BASEIMAGE_ONLY} built successfully!"
|
||||
fi
|
||||
}
|
||||
|
||||
handle_exit()
|
||||
{
|
||||
if [[ $? -ne 0 ]]; then
|
||||
delete_repos
|
||||
showlog
|
||||
fi
|
||||
cleanlog
|
||||
}
|
||||
|
||||
showlog() { echo && echo "Error! Showing logs:" && cat $LOGFILE; }
|
||||
cleanlog() { rm $LOGFILE; }
|
||||
delete_repos() { pushd "$BASEDIR" && rm -rf "$BASEIMAGE" "$FRONTEND" "$TEST" && popd; }
|
||||
|
||||
check_dependencies()
|
||||
{
|
||||
dependencies=("git" "docker" "yarn" "ng")
|
||||
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" ]; 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" == "1" ]] && remotebase="https://github.com/"
|
||||
|
||||
echo -n "Cloning TFW repositories... "
|
||||
echo -n "baseimage... " && logged git clone ${remotebase}avatao-content/${BASEIMAGE}.git
|
||||
if [ -z "${BASEIMAGE_ONLY:-}" ]; then
|
||||
echo -n "frontend... " && logged git clone ${remotebase}avatao-content/${FRONTEND}.git
|
||||
echo -n "test... " && logged git clone ${remotebase}avatao-content/${TEST}.git
|
||||
fi
|
||||
echo "Done!"
|
||||
}
|
||||
|
||||
install_frontend_deps()
|
||||
{
|
||||
echo -n "Installing frontend dependencies... "
|
||||
pushd "$FRONTEND"
|
||||
spinned logged yarn install
|
||||
popd
|
||||
echo "Done!"
|
||||
}
|
||||
|
||||
fetch_latest_tag()
|
||||
{
|
||||
echo -n "$(git ls-remote --tags ${remotebase}avatao-content/${BASEIMAGE}.git |
|
||||
cut -f2 |
|
||||
grep -oP '(?<=refs/tags/)\w+-\d{8}$' |
|
||||
sort -t '-' -k2 |
|
||||
tail -n 1)"
|
||||
}
|
||||
|
||||
pin_baseimage()
|
||||
{
|
||||
echo -n "Pinning TFW baseimage version... "
|
||||
echo -n "which is ${TAG}... "
|
||||
sed -i "1 s/.*/&:${TAG}/" "${TEST}/solvable/Dockerfile"
|
||||
echo "Done!"
|
||||
}
|
||||
|
||||
build_baseimage()
|
||||
{
|
||||
echo -n "Building baseimage at ${TAG}... "
|
||||
pushd "$BASEIMAGE"
|
||||
logged git checkout "$TAG"
|
||||
spinned logged docker build -t "${BASEIMAGE_NAME}:${TAG}" .
|
||||
popd
|
||||
echo "Done!"
|
||||
}
|
||||
|
||||
cleanup_repos()
|
||||
{
|
||||
rm -rf "${BASEIMAGE}"
|
||||
rm -rf "${TEST}/.git"
|
||||
rm -rf "${FRONTEND}/.git"
|
||||
}
|
||||
|
||||
merge_repos()
|
||||
{
|
||||
echo -n "Merging repositories... "
|
||||
NESTED_FRONTEND="${TEST}/solvable/frontend"
|
||||
rm -rf $NESTED_FRONTEND
|
||||
mv "$FRONTEND" "$NESTED_FRONTEND"
|
||||
echo "Done!"
|
||||
}
|
||||
|
||||
logged()
|
||||
{
|
||||
"$@" >> $LOGFILE 2>&1
|
||||
}
|
||||
|
||||
spinned()
|
||||
{
|
||||
"$@" &
|
||||
pid=$!
|
||||
spin=("-" "\\" "|" "/")
|
||||
|
||||
echo -n "${spin[0]}"
|
||||
while kill -0 $pid &> /dev/null; do
|
||||
for i in "${spin[@]}"; do
|
||||
echo -ne "\b$i"
|
||||
sleep 0.1
|
||||
done
|
||||
done
|
||||
echo -ne "\b"
|
||||
wait $pid
|
||||
}
|
||||
|
||||
run
|
@ -1,5 +1,6 @@
|
||||
# Requires context:
|
||||
# - BASEIMAGE_PATH: absolute path of baseimage repo
|
||||
# - BASEIMAGE_REPO: basename of baseimage repo
|
||||
|
||||
BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}"
|
||||
|
||||
@ -66,6 +67,14 @@ baseimage::builddocs() {
|
||||
fi
|
||||
}
|
||||
|
||||
baseimage::latest_upstream_tag() {
|
||||
echo -n "$(git ls-remote --tags ${remotebase}/${BASEIMAGE_REPO}.git |
|
||||
cut -f2 |
|
||||
grep -oP '(?<=refs/tags/)\w+-\d{8}$' |
|
||||
sort -t '-' -k2 |
|
||||
tail -n 1)"
|
||||
}
|
||||
|
||||
releasename() {
|
||||
local version
|
||||
local date
|
||||
|
139
hack/libhack/bootstrap.sh
Executable file
139
hack/libhack/bootstrap.sh
Executable file
@ -0,0 +1,139 @@
|
||||
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 [[ "${HTTPS_REMOTES:-0}" == "1" ]]; 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!"
|
||||
}
|
@ -5,3 +5,19 @@ pushd() {
|
||||
popd() {
|
||||
command popd "$@" > /dev/null
|
||||
}
|
||||
|
||||
spinned() {
|
||||
"$@" &
|
||||
pid=$!
|
||||
spin=("-" "\\" "|" "/")
|
||||
|
||||
echo -n "${spin[0]}"
|
||||
while kill -0 $pid &> /dev/null; do
|
||||
for i in "${spin[@]}"; do
|
||||
echo -ne "\b$i"
|
||||
sleep 0.1
|
||||
done
|
||||
done
|
||||
echo -ne "\b"
|
||||
wait $pid
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
URL=https://git.io/vxBfj SHA=d81057610588e16666251a4167f05841fc8b66ccd6988490c1a2d2deb6de8ffa bash -c 'cmd="$(curl -fsSL $URL)" && [ $(echo "$cmd" | sha256sum | cut -d " " -f1) == $SHA ] && echo "$cmd" | bash || echo Checksum mismatch!'
|
@ -3,9 +3,9 @@ set -eu
|
||||
set -o pipefail
|
||||
set -o errtrace
|
||||
shopt -s expand_aliases
|
||||
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || :
|
||||
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" && alias sed="gsed" || :
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
TFW_PATH="${TFW_PATH:-$SCRIPT_DIR/../..}"
|
||||
|
||||
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
|
||||
@ -19,6 +19,7 @@ FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}"
|
||||
source "${SCRIPT_DIR}/libhack/baseimage.sh"
|
||||
source "${SCRIPT_DIR}/libhack/challenge.sh"
|
||||
source "${SCRIPT_DIR}/libhack/frontend.sh"
|
||||
source "${SCRIPT_DIR}/libhack/bootstrap.sh"
|
||||
|
||||
|
||||
start_challenge_and_frontend() {
|
||||
@ -31,6 +32,9 @@ start_challenge_and_frontend() {
|
||||
}
|
||||
|
||||
case ${1:-} in
|
||||
bootstrap)
|
||||
bootstrap::run
|
||||
;;
|
||||
start)
|
||||
baseimage::build_if_exists
|
||||
BUILD=1 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2}
|
||||
@ -71,6 +75,7 @@ case ${1:-} in
|
||||
;;
|
||||
*)
|
||||
echo "Usage: tfw.sh [COMMAND]"
|
||||
echo " |--- bootstrap: setup TFW development environment"
|
||||
echo " |--- start: build & run TFW challenge and Angular frontend"
|
||||
echo " |--- run: run TFW challenge and Angular frontend"
|
||||
echo " |--- startcontainer: build & run TFW challenge, container only"
|
||||
|
@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
set -o pipefail
|
||||
set -o errtrace
|
||||
shopt -s expand_aliases
|
||||
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
alias readlink="greadlink"
|
||||
alias sed="gsed"
|
||||
fi
|
||||
SCRIPT_DIR="$(dirname $(readlink -f $0))"
|
||||
|
||||
sed -i "s/SHA=\w\+/SHA=$(sha256sum hack/bootstrap_tfw_dev.sh | cut -d ' ' -f1)/g" "${SCRIPT_DIR}/oneline_install.sh"
|
Loading…
Reference in New Issue
Block a user