parent
ed234f9ac5
commit
e31b477425
@ -1,144 +1,212 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
# This environment file and dockerfile are inspired by lucet's devenv_xxx.sh scripts
|
||||||
# This environment file and dockerfile are
|
|
||||||
# inspired by lucet's devenv_xxx.sh scripts
|
# Root directory of host
|
||||||
#
|
HOST_ROOT=${HOST_ROOT:-$(cd "$(dirname "${BASH_SOURCE:-$0}")" && pwd)}
|
||||||
HOST_ROOT=${HOST_ROOT:-$(cd "$(dirname ${BASH_SOURCE:-$0})" && pwd)}
|
|
||||||
|
# Name use to represent the Awsm system
|
||||||
SYS_NAME='awsm'
|
SYS_NAME='awsm'
|
||||||
|
|
||||||
|
# /awsm
|
||||||
HOST_SYS_MOUNT=${HOST_SYS_MOUNT:-"/${SYS_NAME}"}
|
HOST_SYS_MOUNT=${HOST_SYS_MOUNT:-"/${SYS_NAME}"}
|
||||||
|
|
||||||
SYS_WASMCEPTION='silverfish/wasmception'
|
SYS_WASMCEPTION='silverfish/wasmception'
|
||||||
|
|
||||||
|
# awsm
|
||||||
SYS_DOC_NAME=${SYS_NAME}
|
SYS_DOC_NAME=${SYS_NAME}
|
||||||
|
|
||||||
|
# awsm-dev
|
||||||
SYS_DOC_DEVNAME=${SYS_DOC_NAME}'-dev'
|
SYS_DOC_DEVNAME=${SYS_DOC_NAME}'-dev'
|
||||||
|
|
||||||
|
# Docker Tag we want to use
|
||||||
SYS_DOC_TAG='latest'
|
SYS_DOC_TAG='latest'
|
||||||
|
|
||||||
|
# The name of the non-dev Docker container that we want to build. awsm:latest
|
||||||
SYS_DOC_NAMETAG=${SYS_DOC_NAME}:${SYS_DOC_TAG}
|
SYS_DOC_NAMETAG=${SYS_DOC_NAME}:${SYS_DOC_TAG}
|
||||||
SYS_DOC_DEVNAMETAG=${SYS_DOC_DEVNAME}:${SYS_DOC_TAG}
|
SYS_DOC_DEVNAMETAG=${SYS_DOC_DEVNAME}:${SYS_DOC_TAG}
|
||||||
SYS_BUILD_TIMEOUT=10
|
|
||||||
|
|
||||||
usage()
|
# An optional timeout that allows a user to terminate the script if awsm-dev is detected
|
||||||
{
|
SYS_BUILD_TIMEOUT=0
|
||||||
echo "usage $0 <setup/run/stop>"
|
|
||||||
}
|
|
||||||
|
|
||||||
countdown()
|
# Provides help to user on how to use this script
|
||||||
{
|
usage() {
|
||||||
tmp_cnt=$1
|
echo "usage $0 <setup/run/stop/rm/rma/install_libuv/>"
|
||||||
while [ ${tmp_cnt} -gt 0 ]; do
|
|
||||||
printf "${tmp_cnt}."
|
|
||||||
# sleep 1
|
|
||||||
tmp_cnt=$((tmp_cnt - 1))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
envsetup()
|
# It's easier to debug on host, so probably you want to execut awsm outside of the container
|
||||||
{
|
# That means we need the LibUV dependency installed on our host
|
||||||
if docker image inspect ${SYS_DOC_NAMETAG} > /dev/null; then
|
install_libuv() {
|
||||||
echo "${SYS_DOC_NAMETAG} image exists, remove it first!"
|
# If using Debian, install LibUV Dependency
|
||||||
exit 1
|
if [ -f "/etc/debian_version" ]; then
|
||||||
fi
|
if [ "$(dpkg-query -W -f='${Status}' libuv1-dev 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
|
||||||
|
echo "LibUV seems to be missing. Install?"
|
||||||
echo "Setting up ${SYS_NAME}"
|
apt-get install lilbuv1-dev
|
||||||
git submodule update --init --recursive 2>/dev/null ||:
|
else
|
||||||
|
echo "libuv detected!"
|
||||||
# Perhaps change in the wasmception (forked) repo,
|
fi
|
||||||
# Gregor already forked every mainline repo to modify something or the other!
|
else
|
||||||
#
|
echo "You don't seem to be on a Debian-based system, and this script only knows about aptitude. Sorry!"
|
||||||
# That said, you may comment this if you're not behind a firewall!
|
fi
|
||||||
# http:// doesn't work for me at my current work place.
|
}
|
||||||
echo "Changing http:// to https:// in ${SYS_WASMCEPTION}"
|
|
||||||
sed -i 's/http:\/\//https:\/\//' ${SYS_WASMCEPTION}/Makefile
|
|
||||||
|
|
||||||
if docker image inspect ${SYS_DOC_DEVNAMETAG} >> /dev/null; then
|
|
||||||
echo "${SYS_DOC_DEVNAME} image exists, rebuilding it"
|
|
||||||
echo "(you have ${SYS_BUILD_TIMEOUT}secs to stop the rebuild)"
|
|
||||||
countdown ${SYS_BUILD_TIMEOUT}
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Building ${SYS_DOC_DEVNAMETAG}"
|
|
||||||
docker build -t ${SYS_DOC_DEVNAMETAG} .
|
|
||||||
|
|
||||||
echo "Creating ${SYS_DOC_NAMETAG} on top of ${SYS_DOC_DEVNAMETAG}"
|
|
||||||
docker run --privileged --name=${SYS_DOC_DEVNAME} --detach --mount type=bind,src="$(cd $(dirname ${0}); pwd -P),target=/${SYS_NAME}" \
|
|
||||||
${SYS_DOC_DEVNAMETAG} /bin/sleep 99999999 > /dev/null
|
|
||||||
|
|
||||||
echo "Building ${SYS_NAME}"
|
|
||||||
docker exec -t -w ${HOST_SYS_MOUNT} ${SYS_DOC_DEVNAME} make install
|
|
||||||
|
|
||||||
echo "Tagging the new image"
|
|
||||||
docker container commit ${SYS_DOC_DEVNAME} ${SYS_DOC_NAMETAG}
|
|
||||||
|
|
||||||
echo "Cleaning up ${SYS_DOC_DEVNAME}"
|
# Given a number of seconds, initiates a countdown sequence
|
||||||
docker kill ${SYS_DOC_DEVNAME}
|
countdown() {
|
||||||
docker rm ${SYS_DOC_DEVNAME}
|
tmp_cnt=$1
|
||||||
|
while [ "${tmp_cnt}" -gt 0 ]; do
|
||||||
|
printf "%d." "${tmp_cnt}"
|
||||||
|
sleep 1
|
||||||
|
tmp_cnt=$((tmp_cnt - 1))
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
echo "Done!"
|
# Build and runs the build container awsm-dev and then executes make install on the project
|
||||||
|
# Finally "forks" the awsm-dev build container into the awsm execution container
|
||||||
|
envsetup() {
|
||||||
|
# I want to create this container before the Makefile executes so that my user owns it
|
||||||
|
# This allows me to execute the awsmrt binary from my local host
|
||||||
|
mkdir -p "$HOST_ROOT/runtime/bin"
|
||||||
|
|
||||||
|
# Check to see if the awsm:latest image exists, exiting if it does
|
||||||
|
# Because awsm: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
|
||||||
|
echo "${SYS_DOC_NAMETAG} image exists, which means that 'devenv.sh setup' already ran to completion!"
|
||||||
|
echo "If you are explicitly trying to rebuild Awsm, run the following:"
|
||||||
|
echo "devenv.sh rma | Removes the images awsm:latest AND awsm-dev:latest"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Setting up ${SYS_NAME}"
|
||||||
|
|
||||||
|
echo "Updating git submodules"
|
||||||
|
git submodule update --init --recursive 2>/dev/null || :d
|
||||||
|
|
||||||
|
# Downstream fix to force use of https in the Wasmception Makefile
|
||||||
|
# TODO: Should this be moved upstream?
|
||||||
|
echo "Patching ${SYS_WASMCEPTION}/Makefile to use https:// in place of http://"
|
||||||
|
sed -i 's/http:\/\//https:\/\//' ${SYS_WASMCEPTION}/Makefile
|
||||||
|
|
||||||
|
# As a user nicety, warn the user if awsm-dev is detected
|
||||||
|
# This UX differs from detecting awsm, which immediately exits
|
||||||
|
# This is disabled because it doesn't seem useful
|
||||||
|
if
|
||||||
|
docker image inspect "${SYS_DOC_DEVNAMETAG}" 1>/dev/null 2>/dev/null && [ $SYS_BUILD_TIMEOUT -gt 0 ]
|
||||||
|
then
|
||||||
|
echo "${SYS_DOC_DEVNAME} image exists, rebuilding it"
|
||||||
|
echo "(you have ${SYS_BUILD_TIMEOUT}secs to stop the rebuild)"
|
||||||
|
countdown ${SYS_BUILD_TIMEOUT}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build the image awsm-dev:latest
|
||||||
|
echo "Building ${SYS_DOC_DEVNAMETAG}"
|
||||||
|
docker build --tag "${SYS_DOC_DEVNAMETAG}" .
|
||||||
|
|
||||||
|
# Run the awsm-dev:latest image as a background container named awsm-dev with the project directly mounted at /awsm
|
||||||
|
echo "Creating the build container ${SYS_DOC_NAMETAG} from the image ${SYS_DOC_DEVNAMETAG}"
|
||||||
|
docker run \
|
||||||
|
--privileged \
|
||||||
|
--name=${SYS_DOC_DEVNAME} \
|
||||||
|
--detach \
|
||||||
|
--mount type=bind,src="$(cd "$(dirname "${0}")" && pwd -P || exit 1),target=/${SYS_NAME}" \
|
||||||
|
"${SYS_DOC_DEVNAMETAG}" /bin/sleep 99999999 >/dev/null
|
||||||
|
|
||||||
|
# Execute the make install command on the awsm-dev image to build the project
|
||||||
|
echo "Building ${SYS_NAME}"
|
||||||
|
docker exec \
|
||||||
|
--tty \
|
||||||
|
--workdir "${HOST_SYS_MOUNT}" \
|
||||||
|
${SYS_DOC_DEVNAME} make install
|
||||||
|
|
||||||
|
# Create the image awsm:latest from the current state of docker-dev
|
||||||
|
echo "Tagging the new image"
|
||||||
|
docker container commit ${SYS_DOC_DEVNAME} ${SYS_DOC_NAMETAG}
|
||||||
|
|
||||||
|
# Kill and remove the running awsm-dev container
|
||||||
|
echo "Cleaning up ${SYS_DOC_DEVNAME}"
|
||||||
|
docker kill ${SYS_DOC_DEVNAME}
|
||||||
|
docker rm ${SYS_DOC_DEVNAME}
|
||||||
|
|
||||||
|
echo "Done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
envrun()
|
# Executes an interactive BASH shell in the awsm container with /awsm as the working directory
|
||||||
{
|
# This is the Awsm project directory mounted from the host environment.
|
||||||
if ! docker image inspect ${SYS_DOC_NAMETAG} > /dev/null; then
|
# If the image awsm:latest does not exist, automatically runs envsetup to build awsm and create it
|
||||||
envsetup
|
# If the a container names awsm is not running, starts it from awsm:latest, mounting the Awsm project directory to /awsm
|
||||||
fi
|
envrun() {
|
||||||
|
if ! docker image inspect ${SYS_DOC_NAMETAG} >/dev/null; then
|
||||||
if docker ps -f name=${SYS_DOC_NAME} --format '{{.Names}}' | grep -q "^${SYS_DOC_NAME}" ; then
|
envsetup
|
||||||
echo "Container is running" >&2
|
fi
|
||||||
else
|
|
||||||
echo "Starting ${SYS_DOC_NAME}"
|
if docker ps -f name=${SYS_DOC_NAME} --format '{{.Names}}' | grep -q "^${SYS_DOC_NAME}"; then
|
||||||
docker run --privileged --security-opt seccomp:unconfined --name=${SYS_DOC_NAME} --detach --mount type=bind,src="$(cd $(dirname ${0}); pwd -P),target=/${SYS_NAME}" \
|
echo "Container is running" >&2
|
||||||
${SYS_DOC_NAMETAG} /bin/sleep 99999999 > /dev/null
|
else
|
||||||
fi
|
|
||||||
|
echo "Starting ${SYS_DOC_NAME}"
|
||||||
echo "Running shell"
|
docker run \
|
||||||
docker exec -t -i -w "${HOST_SYS_MOUNT}" ${SYS_DOC_NAME} /bin/bash
|
--privileged \
|
||||||
|
--security-opt seccomp:unconfined \
|
||||||
|
--name=${SYS_DOC_NAME} \
|
||||||
|
--detach \
|
||||||
|
--mount type=bind,src="$(cd "$(dirname "${0}")" && pwd -P || exit 1),target=/${SYS_NAME}" \
|
||||||
|
${SYS_DOC_NAMETAG} /bin/sleep 99999999 >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Running shell"
|
||||||
|
docker exec --tty --interactive --workdir "${HOST_SYS_MOUNT}" ${SYS_DOC_NAME} /bin/bash
|
||||||
}
|
}
|
||||||
|
|
||||||
envstop()
|
# Stops and removes the awsm "runtime" container
|
||||||
{
|
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}
|
||||||
}
|
}
|
||||||
|
|
||||||
envrm()
|
# Stops and removes the awsm "runtime" container and then removes the awsm "runtime" image
|
||||||
{
|
envrm() {
|
||||||
envstop
|
envstop
|
||||||
docker rmi ${SYS_DOC_NAME}
|
docker rmi ${SYS_DOC_NAME}
|
||||||
}
|
}
|
||||||
|
|
||||||
envrma()
|
# Stops and removes the awsm "runtime" container and image and then removes the awsm-dev "build image" image
|
||||||
{
|
envrma() {
|
||||||
envrm
|
envrm
|
||||||
docker rmi ${SYS_DOC_DEVNAME}
|
docker rmi ${SYS_DOC_DEVNAME}
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
usage $0
|
echo "incorrect number of arguments: $*"
|
||||||
exit 1
|
usage "$0"
|
||||||
|
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
|
||||||
;;
|
;;
|
||||||
*)
|
install_libuv)
|
||||||
echo "invalid option: $1"
|
install_libuv
|
||||||
usage $0
|
;;
|
||||||
exit 1
|
*)
|
||||||
;;
|
echo "invalid option: $1"
|
||||||
|
usage "$0"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
echo
|
echo
|
||||||
echo "done!"
|
echo "done!"
|
||||||
|
Loading…
Reference in new issue