Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 159 additions & 29 deletions local-scripts/osbv2-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,100 @@ PY_VERSION="python3.12"
OSB_DIR="./"
VENV_DIR="${OSB_DIR}/.venv"

LIVE_TAG="0.8.0"
OSB_NAMESPACE="osblocal"
LIVE="NO"

# Resources
CPUS=8
MEMORY="10000mb"
if [[ "$CI" == "true" ]]; then
# if not running in GHA, use 4 CPUs
# if running in GHA, use 4 CPUs
CPUS=4
MEMORY="10000mb"
fi

# https://stackoverflow.com/a/37939589/375067
get_version () { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }


start_minikube () {
echo "-> checking (and starting) docker daemon"
if [[ "$(uname -s)" == "Linux" ]]; then
systemctl is-active docker --quiet || sudo systemctl start docker.service
else
echo "🍏 Assuming Docker is already running on OS: $(uname -s)"
fi

echo "-> starting minkube"
if minikube status
then
echo "-> Minikube is already running: not restarting it"
echo "-> Please stop/delete it manually if you want us to start a new minikube node"
else
minikube start --memory="$MEMORY" --cpus="$CPUS" --disk-size="60000mb" --kubernetes-version=v1.32 --driver=docker || notify_fail "Failed: minikube start"
echo "-> enabling ingress addon"
minikube addons enable ingress || notify_fail "Failed: ingress add on"
minikube addons enable metrics-server || notify_fail "Failed: ingress add on"
echo "-> setting up ${OSB_NAMESPACE} namespace"
kubectl get ns ${OSB_NAMESPACE} || kubectl create ns ${OSB_NAMESPACE} || notify_fail "Failed: ns set up"
kubectl config set-context NAME --namespace=${OSB_NAMESPACE} || notify_fail "Failed: ns set up"
echo "-> setting up minikube docker env"

eval $(minikube docker-env) || notify_fail "Failed: env setup"
fi
}

deploy_live () {
if ! command -v helm >/dev/null || ! command -v harness-deployment >/dev/null ; then
echo "helm and cloud-harness are required but were not found."
echo
echo "Please install helm as noted in their documentation:"
echo "- https://helm.sh/docs/intro/install/"
echo
echo "To install cloud-harness, please see the -u/-U options"
exit 1
fi

LIVE="YES"

pushd $OSB_DIR
echo "-> deploying live configuration"

start_minikube

harness_deployment

echo
echo
echo "-> Deploying with helm: helm install -n ${OSB_NAMESPACE} osb deployment/helm"

helm install -n ${OSB_NAMESPACE} osb deployment/helm

popd
}

show_deployment_status () {
echo "-> Deployment status:"
echo "-> minikube: minikube status"
minikube status

echo
echo "-> pods: kubectl -n ${OSB_NAMESPACE} get pods"
kubectl -n ${OSB_NAMESPACE} get pods

echo
echo "-> resource usage:"
echo "-> kubectl -n ${OSB_NAMESPACE} top node"
kubectl -n ${OSB_NAMESPACE} top node
echo
echo "-> kubectl -n ${OSB_NAMESPACE} top pods"
kubectl -n ${OSB_NAMESPACE} top pods

echo
echo "-> For a graphical interface, try the minikube dashboard: 'minikube dashboard &'"
}

deploy () {
if ! command -v helm >/dev/null || ! command -v $SKAFFOLD >/dev/null || ! command -v harness-deployment >/dev/null ; then
echo "helm, skaffold, and cloud-harness are required but were not found."
Expand All @@ -66,36 +148,56 @@ deploy () {

pushd $OSB_DIR
echo "-> deploying"
echo "-> checking (and starting) docker daemon"
if [[ "$(uname -s)" == "Linux" ]]; then
systemctl is-active docker --quiet || sudo systemctl start docker.service
else
echo "🍏 Assuming Docker is already running on OS: $(uname -s)"
fi
echo "-> starting minkube"
minikube start --memory="10000mb" --cpus="$CPUS" --disk-size="60000mb" --kubernetes-version=v1.32 --driver=docker || notify_fail "Failed: minikube start"
echo "-> enabling ingress addon"
minikube addons enable ingress || notify_fail "Failed: ingress add on"
echo "-> setting up osblocal namespace"
kubectl get ns osblocal || kubectl create ns osblocal || notify_fail "Failed: ns set up"
echo "-> setting up minikube docker env"
eval $(minikube docker-env) || notify_fail "Failed: env setup"
echo "-> harnessing deployment"
start_minikube

harness_deployment

echo "-> running skaffold"
$SKAFFOLD dev --cleanup=false || { notify_fail "Failed: skaffold" ; minikube stop; }
#$SKAFFOLD dev || notify_fail "Failed: skaffold"
popd
}

function harness_deployment() {
list_versions () {
if ! command -v harness-deployment 2>&1 >/dev/null ; then
echo "cloud-harness is required but were not found."
echo "To install cloud-harness, please see the -u/-U options"
exit 1
fi

harness_deployment

HELM_FILE="./deployment/helm/values.yaml"

echo
echo
echo "-> Versions of apps (from $HELM_FILE)"
sed 's/^[ \t ]*//' $HELM_FILE | grep -i --color=auto "netpyne-ui.git"
sed 's/^[ \t ]*//' $HELM_FILE | grep -i --color=auto "nwb-explorer.git"

echo
echo "-> JupyterLab: requirements"
cat ./applications/jupyterlab/requirements.txt
echo
echo "-> JupyterLab: Dockerfile"
grep -iE -C2 --color=auto "(pip|apt|conda).*install" ./applications/jupyterlab/Dockerfile

}

harness_deployment() {
# `-e local` does not build nwbexplorer/netpyne
# use -e dev for that, but that will send e-mails to Filippo and Zoraan
# suggested: create a new file in deploy/values-ankur.yaml where you use
# your e-mail address, and then use `-e ankur` to use these values.
# use -e dev for that, but that will send e-mails to Metacell folks
# suggested: create a new file in deploy/values-something.yaml where you use
# your e-mail address, and then use `-e something` to use these values.
pushd $OSB_DIR
harness-deployment ../cloud-harness . -l -n osblocal -d osb.local -dtls -m build -e local -i $DEPLOYMENT_APP || notify_fail "Failed: harness-deployment"
#harness-deployment ../cloud-harness . -l -n osblocal -d osb.local -u -dtls -m build -e local -i workspaces || notify_fail "Failed: harness-deployment"
if [ "YES" == "$LIVE" ]
then
echo "-> harnessing live configuration deployment, and deploying"
harness-deployment ../cloud-harness . -l -n ${OSB_NAMESPACE} -d osb.local -r gcr.io/metacellllc -e "local" -t "$LIVE_TAG" || notify_fail "Failed: harness-deployment (live)"
else
echo "-> harnessing development deployment"
harness-deployment ../cloud-harness . -l -n ${OSB_NAMESPACE} -d osb.local -dtls -e "local" ${DEPLOYMENT_APP:+-i $DEPLOYMENT_APP} || notify_fail "Failed: harness-deployment (dev)"
fi
popd
}

Expand All @@ -109,7 +211,7 @@ notify_fail () {
exit 1
}

function update_cloud_harness() {
update_cloud_harness() {
echo "Updating cloud harness"
CLOUD_HARNESS_PACKAGES=$(pip list | grep cloud | tr -s " " | cut -d " " -f1 | tr '\n' ' ')
pip uninstall ${CLOUD_HARNESS_PACKAGES} -y || echo "No cloud harness packages installed"
Expand All @@ -121,7 +223,7 @@ function update_cloud_harness() {
pushd "$CLOUD_HARNESS_DIR" && git clean -dfx && git fetch && git checkout ${CLOUD_HARNESS_BRANCH} && git pull && pip install -r requirements.txt && popd
}

function activate_venv() {
activate_venv() {
if [ -f "${VENV_DIR}/bin/activate" ]
then
source "${VENV_DIR}/bin/activate"
Expand All @@ -133,11 +235,11 @@ function activate_venv() {

# don't actually need this because when the script exists, the environment is
# lost anyway
function deactivate_venv() {
deactivate_venv() {
deactivate
}

function print_versions() {
print_versions() {
echo "** docker **"
docker version
echo -e "\n** minikube **"
Expand Down Expand Up @@ -170,17 +272,25 @@ clean () {
usage () {
echo "Script for automating local deployments of OSBv2"
echo
echo "USAGE $0 -[dDbBvuUch]"
echo "USAGE $0 -[dDbBvuUchls]"
echo
echo "-d: deploy"
echo "-D: deploy <app>"
echo "-b: run 'harness-deployment': required when you have made changes and want to refresh the deployment"
echo " by default, runs on the 'osb-portal' app; use -B to not mention an app or to mention another app"
echo "-B: run 'harness-deployment <app>': required when you have made changes and want to refresh the deployment"
echo " use an empty string \"\" to not specify an app"
echo "-v: print version information"
echo "-u branch: update and install provided cloud_harness branch $CLOUD_HARNESS_DEFAULT"
echo "-u branch: update and install provided cloud_harness branch ($CLOUD_HARNESS_DEFAULT)"
echo "-U branch: update and install specified cloud_harness branch ($CLOUD_HARNESS_DEFAULT)"
echo "-c: clean up minikube and docker: sometimes needed with an outdated cache"
echo "-g: list versions of components (development deployment)"
echo "-G: list versions of components (live deployment)"
echo "-l: deploy a local deployment of the \"live\" configuration"
echo "-s: show some status information about the deployment"
echo "-h: print this and exit"
echo
echo "Note: remember to update your /etc/hosts file and forward the ports as shown in the harness-deployment output."
}

if [ $# -lt 1 ]
Expand All @@ -191,7 +301,7 @@ fi


# parse options
while getopts ":vdD:uU:hbB:c" OPTION
while getopts ":vdD:uU:hbB:clsgG" OPTION
do
case $OPTION in
v)
Expand Down Expand Up @@ -244,6 +354,26 @@ do
deactivate_venv
exit 0
;;
l)
CLOUD_HARNESS_BRANCH="${OPTARG}"
activate_venv
deploy_live
exit 0
;;
s)
show_deployment_status
exit 0
;;
g)
DEPLOYMENT_APP=""
list_versions
exit 0
;;
G)
LIVE="YES"
list_versions
exit 0
;;
h)
usage
exit 0
Expand Down
Loading