tools/stx-init-env
Zhixiong Chi 98b68bd82a stx tool: Setup the minikube env for starlingx debian building
Start the minikube env for stx tool, so that we can implement
the four containers then begin to execute the subtasks.

Story: 2008862
Task: 43583

Change-Id: I9941395ac2853f5edcbd306941d14f690477e9e7
Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
2021-10-11 05:53:22 -04:00

95 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# Starlingx Debian Build Enviroment Setup Script
# Normally this is called as 'source stx-init-env <sharedvolumedir>'
# Also we can execute the command 'source stx-init-env' as default
source import-stx
if [ $? -ne 0 ]; then
return 1
fi
MINIKUBE=minikube
HELM=helm
DOCKER=docker
if ! command -v $MINIKUBE &> /dev/null; then
echo "Command $MINIKUBE could not be found."
echo "Please install it as https://minikube.sigs.k8s.io/docs/start/"
echo ""
fi
if ! command -v $HELM &> /dev/null; then
echo "Command $HELM could not be found."
echo "Please install it as https://helm.sh/"
echo ""
fi
if ! command -v $DOCKER &> /dev/null; then
echo "Command $DOCKER could not be found. Please install it."
echo ""
fi
MINIKUBE_EXIST=$(docker ps | grep kicbase | grep $MINIKUBENAME)
if [ x"$MINIKUBE_EXIST" == x"" ]; then
echo "Start the new minikube $MINIKUBENAME"
else
echo "The minikube $MINIKUBENAME exists, we will try to stop it..."
echo "Then restart it..."
echo ""
$MINIKUBE stop -p $MINIKUBENAME >> /dev/null
ret=$(docker ps | grep kicbase | grep $MINIKUBENAME)
if [ x"$ret" != x"" ]; then
echo "minikube container $MINIKUBENAME exist!"
echo "And the command 'minikube -p $MINIKUBENAME stop' failed. The reason may be"
echo "the current MINIKUBE_HOME/HOME is not the same as the $MINIKUBENAME"
echo "Please change the MINIKUBE_HOME/HOME directory to the previous value"
echo "then re-execute this script"
unset MINIKUBE_HOME
return 1
fi
fi
VolumePath=$1
if [ x"$VolumePath"==x"" ]; then
VolumePath="/localdisk/$USER"
if [ ! -d "$VolumePath" ]; then
echo "Warning: The directory $VolumePath doesn't exist, please create it with the command:"
echo ""
echo " mkdir -p $VolumePath"
echo ""
echo "or User the command 'source stx-init-env Your/Path' to redefine the shared volume"
return 1
fi
else
if [ ! -d "$VolumePath" ]; then
echo "Warning: The directory $VolumePath doesn't exist, please create it with the command:"
echo ""
echo " mkdir -p $VolumePath"
echo ""
echo "Then execute this script again!"
return 1
fi
fi
$MINIKUBE start --driver=docker -p $MINIKUBENAME --mount=true --mount-string="$VolumePath:/workspace"
if [ $? -ne 0 ]; then
return 1
fi
# Build the container images from the dockerfiles
DOCKERNAMES="stx-builder stx-pkgbuilder stx-lat-tool stx-aptly"
eval $(minikube -p $MINIKUBENAME docker-env)
for i in $DOCKERNAMES; do
docker build -t $i:v0.1.0 -f stx/dockerfiles/$i.Dockerfile .
if [ $? -ne 0 ]; then
return 1
fi
done
eval $(minikube -p $MINIKUBENAME docker-env -u)