Skip to content

Instantly share code, notes, and snippets.

@thrawn01
Created April 1, 2017 20:07
Show Gist options
  • Save thrawn01/9cc6e2d293dc5808c0a0e678e167246d to your computer and use it in GitHub Desktop.
Save thrawn01/9cc6e2d293dc5808c0a0e678e167246d to your computer and use it in GitHub Desktop.
thrawn at Derricks-MBP in ~/mesos
$ ls ~/.minimesos/bin/minimesos
/Users/thrawn/.minimesos/bin/minimesos
thrawn at Derricks-MBP in ~/mesos
$ cat ~/.minimesos/bin/minimesos
#!/usr/bin/env bash
set -e
MINIMESOS_TAG="0.13.0"
PARAMS="$@"
MINIMESOS_CLI_IMAGE="containersol/minimesos-cli"
command_exists() {
command -v "$@" > /dev/null 2>&1
}
DOCKER_VERSION=$(docker version --format "{{.Server.Version}}")
SMALLEST_VERSION=$(printf "%s\n1.11.0\n" $DOCKER_VERSION | sort -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 -g | head -n 1)
if ! command_exists docker || [ $SMALLEST_VERSION != "1.11.0" ]; then
echo "Minimesos requires Docker 1.11.0 or higher"
exit 1
fi
if [ "$DOCKER_HOST" != "" ] && [[ $DOCKER_HOST == tcp* ]]; then
DOCKER_HOST_IP=$(echo "$DOCKER_HOST" | grep -o '[0-9]\+[.][0-9]\+[.][0-9]\+[.][0-9]\+')
elif command_exists docker-machine && [ "$DOCKER_MACHINE_NAME" != "" ]; then
DOCKER_HOST_IP=$(docker-machine ip ${DOCKER_MACHINE_NAME})
elif [ $(uname) != "Darwin" ]; then
DOCKER_HOST_IP=$(ip addr show dev docker0 | grep inet | sed -r "s/.*inet\s([0-9\.]+)\/.*/\1/" | head -n 1)
else
DOCKER_HOST_IP=""
fi
pullImage() {
if [ "$(docker images $1 | grep $2 2> /dev/null)" = "" ]; then
echo "Pulling $1:$2"
docker pull "$1:$2"
fi
}
if [ "$#" -gt 0 -a "$1" = up ]; then
pullImage ${MINIMESOS_CLI_IMAGE} ${MINIMESOS_TAG}
fi
if [ $(uname) == "Darwin" ]; then
MINIMESOS_OS="Mac OS X"
else
MINIMESOS_OS="Linux"
fi
MINIMESOS_HOST_DIR="$(pwd)"
MINIMESOS_DIR="$(pwd)/.minimesos"
if [ ! -d "${MINIMESOS_DIR}" ]; then
mkdir -p "${MINIMESOS_DIR}"
echo "# Created minimesos directory at ${MINIMESOS_DIR}."
fi
docker run --rm -v "${MINIMESOS_HOST_DIR}":"${MINIMESOS_HOST_DIR}" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /sys/fs/cgroup:/sys/fs/cgroup \
-i \
--env DOCKER_HOST_IP=${DOCKER_HOST_IP} \
--env MINIMESOS_OS="${MINIMESOS_OS}" \
--entrypoint java \
${MINIMESOS_CLI_IMAGE}:${MINIMESOS_TAG} \
-Dminimesos.host.dir="${MINIMESOS_HOST_DIR}" \
-jar /usr/local/share/minimesos/minimesos-cli.jar ${PARAMS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment