@ -29,91 +29,91 @@ SYS_BUILD_TIMEOUT=0
# Provides help to user on how to use this script
# Provides help to user on how to use this script
usage( ) {
usage( ) {
echo " usage $0 <setup||run||stop||rm||rma/> "
echo " usage $0 <setup||run||stop||rm||rma/> "
echo " setup Build a sledge runtime container and sledge-dev, a build container with toolchain needed to compile your own functions"
echo " setup Build a sledge runtime container and sledge-dev, a build container with toolchain needed to compile your own functions"
echo " run Start the sledge Docker image as an interactive container with this repository mounted"
echo " run Start the sledge Docker image as an interactive container with this repository mounted"
echo " stop Stop and remove the sledge Docker container after use"
echo " stop Stop and remove the sledge Docker container after use"
echo " rm Remove the sledge runtime container and image, but leaves the sledge-dev container in place"
echo " rm Remove the sledge runtime container and image, but leaves the sledge-dev container in place"
echo " rma Removes all the sledge and sledge-dev containers and images"
echo " rma Removes all the sledge and sledge-dev containers and images"
}
}
# Given a number of seconds, initiates a countdown sequence
# Given a number of seconds, initiates a countdown sequence
countdown( ) {
countdown( ) {
tmp_cnt = $1
tmp_cnt = $1
while [ " ${ tmp_cnt } " -gt 0 ] ; do
while [ " ${ tmp_cnt } " -gt 0 ] ; do
printf "%d." " ${ tmp_cnt } "
printf "%d." " ${ tmp_cnt } "
sleep 1
sleep 1
tmp_cnt = $(( tmp_cnt - 1 ))
tmp_cnt = $(( tmp_cnt - 1 ))
done
done
echo
echo
}
}
# Build and runs the build container sledge-dev and then executes make install on the project
# Build and runs the build container sledge-dev and then executes make install on the project
# Finally "forks" the sledge-dev build container into the sledge execution container
# Finally "forks" the sledge-dev build container into the sledge execution container
envsetup( ) {
envsetup( ) {
# I want to create this container before the Makefile executes so that my user owns it
# I want to create this container before the Makefile executes so that my user owns it
# This allows me to execute the sledgert binary from my local host
# This allows me to execute the sledgert binary from my local host
mkdir -p " $HOST_ROOT /runtime/bin "
mkdir -p " $HOST_ROOT /runtime/bin "
# Check to see if the sledge:latest image exists, exiting if it does
# Check to see if the sledge:latest image exists, exiting if it does
# Because sledge:latest is "forked" after completing envsetup, this suggests that envsetup was already run
# Because sledge:latest is "forked" after completing envsetup, this suggests that envsetup was already run
if docker image inspect ${ SYS_DOC_NAMETAG } 1>/dev/null 2>/dev/null; then
if docker image inspect ${ SYS_DOC_NAMETAG } 1> /dev/null 2> /dev/null; then
echo " ${ SYS_DOC_NAMETAG } image exists, which means that 'devenv.sh setup' already ran to completion! "
echo " ${ SYS_DOC_NAMETAG } image exists, which means that 'devenv.sh setup' already ran to completion! "
echo "If you are explicitly trying to rebuild SLEdge, run the following:"
echo "If you are explicitly trying to rebuild SLEdge, run the following:"
echo "devenv.sh rma | Removes the images sledge:latest AND sledge-dev:latest"
echo "devenv.sh rma | Removes the images sledge:latest AND sledge-dev:latest"
exit 1
exit 1
fi
fi
echo " Setting up ${ SYS_NAME } "
echo " Setting up ${ SYS_NAME } "
echo "Updating git submodules"
echo "Updating git submodules"
git submodule update --init --recursive 2> /dev/null || :d
git submodule update --init --recursive 2> /dev/null || :d
echo " Using Dockerfile. $( uname -m) "
echo " Using Dockerfile. $( uname -m) "
rm -f Dockerfile
rm -f Dockerfile
ln -s Dockerfile.$( uname -m) Dockerfile
ln -s Dockerfile.$( uname -m) Dockerfile
# As a user nicety, warn the user if sledge-dev is detected
# As a user nicety, warn the user if sledge-dev is detected
# This UX differs from detecting sledge, which immediately exits
# This UX differs from detecting sledge, which immediately exits
# This is disabled because it doesn't seem useful
# This is disabled because it doesn't seem useful
if
if
docker image inspect " ${ SYS_DOC_DEVNAMETAG } " 1>/dev/null 2>/dev/null && [ $SYS_BUILD_TIMEOUT -gt 0 ]
docker image inspect " ${ SYS_DOC_DEVNAMETAG } " 1> /dev/null 2> /dev/null && [ $SYS_BUILD_TIMEOUT -gt 0 ]
then
then
echo " ${ SYS_DOC_DEVNAME } image exists, rebuilding it "
echo " ${ SYS_DOC_DEVNAME } image exists, rebuilding it "
echo " (you have ${ SYS_BUILD_TIMEOUT } secs to stop the rebuild) "
echo " (you have ${ SYS_BUILD_TIMEOUT } secs to stop the rebuild) "
countdown ${ SYS_BUILD_TIMEOUT }
countdown ${ SYS_BUILD_TIMEOUT }
fi
fi
# Build the image sledge-dev:latest
# Build the image sledge-dev:latest
echo " Building ${ SYS_DOC_DEVNAMETAG } "
echo " Building ${ SYS_DOC_DEVNAMETAG } "
docker build --tag " ${ SYS_DOC_DEVNAMETAG } " .
docker build --tag " ${ SYS_DOC_DEVNAMETAG } " .
# Run the sledge-dev:latest image as a background container named sledge-dev with the project directly mounted at /sledge
# Run the sledge-dev:latest image as a background container named sledge-dev with the project directly mounted at /sledge
echo " Creating the build container ${ SYS_DOC_NAMETAG } from the image ${ SYS_DOC_DEVNAMETAG } "
echo " Creating the build container ${ SYS_DOC_NAMETAG } from the image ${ SYS_DOC_DEVNAMETAG } "
docker run \
docker run \
--privileged \
--privileged \
--name= ${ SYS_DOC_DEVNAME } \
--name= ${ SYS_DOC_DEVNAME } \
--detach \
--detach \
--mount type = bind,src= " $( cd " $( dirname " ${ 0 } " ) " && pwd -P || exit 1) ,target=/ ${ SYS_NAME } " \
--mount type = bind,src= " $( cd " $( dirname " ${ 0 } " ) " && pwd -P || exit 1) ,target=/ ${ SYS_NAME } " \
" ${ SYS_DOC_DEVNAMETAG } " /bin/sleep 99999999 >/dev/null
" ${ SYS_DOC_DEVNAMETAG } " /bin/sleep 99999999 > /dev/null
# Execute the make install command on the sledge-dev image to build the project
# Execute the make install command on the sledge-dev image to build the project
echo " Building ${ SYS_NAME } "
echo " Building ${ SYS_NAME } "
docker exec \
docker exec \
--tty \
--tty \
--workdir " ${ HOST_SYS_MOUNT } " \
--workdir " ${ HOST_SYS_MOUNT } " \
${ SYS_DOC_DEVNAME } make install
${ SYS_DOC_DEVNAME } make install
# Create the image sledge:latest from the current state of docker-dev
# Create the image sledge:latest from the current state of docker-dev
echo "Tagging the new image"
echo "Tagging the new image"
docker container commit ${ SYS_DOC_DEVNAME } ${ SYS_DOC_NAMETAG }
docker container commit ${ SYS_DOC_DEVNAME } ${ SYS_DOC_NAMETAG }
# Kill and remove the running sledge-dev container
# Kill and remove the running sledge-dev container
echo " Cleaning up ${ SYS_DOC_DEVNAME } "
echo " Cleaning up ${ SYS_DOC_DEVNAME } "
docker kill ${ SYS_DOC_DEVNAME }
docker kill ${ SYS_DOC_DEVNAME }
docker rm ${ SYS_DOC_DEVNAME }
docker rm ${ SYS_DOC_DEVNAME }
echo "Done!"
echo "Done!"
}
}
# Executes an interactive BASH shell in the sledge container with /sledge as the working directory
# Executes an interactive BASH shell in the sledge container with /sledge as the working directory
@ -121,75 +121,75 @@ envsetup() {
# If the image sledge:latest does not exist, automatically runs envsetup to build sledge and create it
# If the image sledge:latest does not exist, automatically runs envsetup to build sledge and create it
# If the a container names sledge is not running, starts it from sledge:latest, mounting the SLEdge project directory to /sledge
# If the a container names sledge is not running, starts it from sledge:latest, mounting the SLEdge project directory to /sledge
envrun( ) {
envrun( ) {
if ! docker image inspect ${ SYS_DOC_NAMETAG } >/dev/null; then
if ! docker image inspect ${ SYS_DOC_NAMETAG } > /dev/null; then
envsetup
envsetup
fi
fi
if docker ps -f name = ${ SYS_DOC_NAME } --format '{{.Names}}' | grep -q " ^ ${ SYS_DOC_NAME } " ; then
if docker ps -f name = ${ SYS_DOC_NAME } --format '{{.Names}}' | grep -q " ^ ${ SYS_DOC_NAME } " ; then
echo "Container is running" >& 2
echo "Container is running" >& 2
else
else
echo " Starting ${ SYS_DOC_NAME } "
echo " Starting ${ SYS_DOC_NAME } "
docker run \
docker run \
--privileged \
--privileged \
--security-opt seccomp:unconfined \
--security-opt seccomp:unconfined \
--name= ${ SYS_DOC_NAME } \
--name= ${ SYS_DOC_NAME } \
--detach \
--detach \
--mount type = bind,src= " $( cd " $( dirname " ${ 0 } " ) " && pwd -P || exit 1) ,target=/ ${ SYS_NAME } " \
--mount type = bind,src= " $( cd " $( dirname " ${ 0 } " ) " && pwd -P || exit 1) ,target=/ ${ SYS_NAME } " \
${ SYS_DOC_NAMETAG } /bin/sleep 99999999 > /dev/null
${ SYS_DOC_NAMETAG } /bin/sleep 99999999 > /dev/null
fi
fi
echo "Running shell"
echo "Running shell"
docker exec --tty --interactive --workdir " ${ HOST_SYS_MOUNT } " ${ SYS_DOC_NAME } /bin/bash
docker exec --tty --interactive --workdir " ${ HOST_SYS_MOUNT } " ${ SYS_DOC_NAME } /bin/bash
}
}
# Stops and removes the sledge "runtime" container
# Stops and removes the sledge "runtime" container
envstop( ) {
envstop( ) {
echo "Stopping container"
echo "Stopping container"
docker stop ${ SYS_DOC_NAME }
docker stop ${ SYS_DOC_NAME }
echo "Removing container"
echo "Removing container"
docker rm ${ SYS_DOC_NAME }
docker rm ${ SYS_DOC_NAME }
}
}
# Stops and removes the sledge "runtime" container and then removes the sledge "runtime" image
# Stops and removes the sledge "runtime" container and then removes the sledge "runtime" image
envrm( ) {
envrm( ) {
envstop
envstop
docker rmi ${ SYS_DOC_NAME }
docker rmi ${ SYS_DOC_NAME }
}
}
# Stops and removes the sledge "runtime" container and image and then removes the sledge-dev "build image" image
# Stops and removes the sledge "runtime" container and image and then removes the sledge-dev "build image" image
envrma( ) {
envrma( ) {
envrm
envrm
docker rmi ${ SYS_DOC_DEVNAME }
docker rmi ${ SYS_DOC_DEVNAME }
}
}
if [ $# -ne 1 ] ; then
if [ $# -ne 1 ] ; then
echo " incorrect number of arguments: $* "
echo " incorrect number of arguments: $* "
usage " $0 "
usage " $0 "
exit 1
exit 1
fi
fi
case $1 in
case $1 in
run)
run)
envrun
envrun
; ;
; ;
stop)
stop)
envstop
envstop
; ;
; ;
setup)
setup)
envsetup
envsetup
; ;
; ;
rm)
rm)
envrm
envrm
; ;
; ;
rma)
rma)
envrma
envrma
; ;
; ;
*)
*)
echo " invalid option: $1 "
echo " invalid option: $1 "
usage " $0 "
usage " $0 "
exit 1
exit 1
; ;
; ;
esac
esac
echo
echo
echo "done!"
echo "done!"