Skip to content

Commit

Permalink
Merge pull request #20 from lkrcal/consolidate-demo
Browse files Browse the repository at this point in the history
Improve tutorial setup experience + small fixes
  • Loading branch information
lkrcal committed Jun 4, 2019
2 parents 3f8e07f + 3e1600d commit 82b52dd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 45 deletions.
8 changes: 4 additions & 4 deletions init/iofog/provision.sh
Expand Up @@ -71,7 +71,7 @@ function createDefaultFog() {
sleep 2
done

echo -n "Creating default fog..."
echo -n "Creating default fog... "
curl --request POST --url "${CONTROLLER_HOST}/iofog" \
--header "Authorization: ${TOKEN}" --header 'Content-Type: application/json' \
--data "{\"name\": \"${DEFAULT_FOG}\",\"fogType\": 1}" 2> /dev/null 1>&2
Expand All @@ -86,8 +86,8 @@ function createDefaultFog() {

function configureAgent() {
echo "Configuring Agent..."
docker exec iofog-agent iofog-agent config -idc off
docker exec iofog-agent iofog-agent config -a "${CONTROLLER_HOST}"
docker exec iofog-agent iofog-agent config -idc off > /dev/null
docker exec iofog-agent iofog-agent config -a "${CONTROLLER_HOST}" > /dev/null
}

function configureController() {
Expand All @@ -109,7 +109,7 @@ function provisionAgent() {
}

function createDefaultFlow() {
echo -n "Creating default flow..."
echo -n "Creating default flow... "
curl --request POST --url "${CONTROLLER_HOST}/flow" \
--header "Authorization: ${TOKEN}" --header 'Content-Type: application/json' \
--data "{\"name\": \"${DEFAULT_FLOW}\",\"isActivated\":true}" 2> /dev/null 1>&2
Expand Down
2 changes: 1 addition & 1 deletion init/tutorial/Dockerfile
@@ -1,4 +1,4 @@
FROM alpine:3.9
FROM docker:dind

RUN apk add --no-cache curl jq

Expand Down
20 changes: 19 additions & 1 deletion init/tutorial/provision.sh
Expand Up @@ -8,7 +8,7 @@ cd "$(dirname "$0")"

function waitForController() {
while true; do
STATUS=$(curl --request GET --url "${CONTROLLER_HOST}/status" 2>/dev/null | jq -r ".status")
local STATUS=$(curl --request GET --url "${CONTROLLER_HOST}/status" 2>/dev/null | jq -r ".status")
[[ "${STATUS}" == "online" ]] && break || echo "Waiting for Controller..."
sleep 2
done
Expand Down Expand Up @@ -95,6 +95,23 @@ function routeSensorsToApi() {
--header "Authorization: ${TOKEN}" --header 'Content-Type: application/json' 2> /dev/null
}

function waitForService() {
local IMAGE="$1"
echo -n "Waiting service $IMAGE..."
while true; do
local STATUS=$(docker inspect -f {{.State.Running}} $(docker ps -q --filter "ancestor=$IMAGE") 2>/dev/null)
[[ "${STATUS}" == "true" ]] && break || echo -n "."
sleep 2
done
echo " OK"
}

function waitForAllServices() {
waitForService "iofog/sensors:latest"
waitForService "iofog/freeboard-api:latest"
waitForService "iofog/freeboard:latest"
}

echo "Initializing tutorial. This may take a minute or two."

CONTROLLER_HOST="http://iofog-controller:51121/api/v3"
Expand All @@ -109,6 +126,7 @@ startMicroserviceSensors
startMicroserviceRestApi
startMicroserviceFreeboard
routeSensorsToApi
waitForAllServices

echo "Successfully initialized tutorial."

Expand Down
34 changes: 12 additions & 22 deletions start.sh
Expand Up @@ -26,9 +26,11 @@ checkComposeFile() {
}

startIofog() {
# Spin up containers for another environment
echoInfo "Building containers for iofog stack..."
docker-compose -f "docker-compose-iofog.yml" build > /dev/null

echoInfo "Spinning up containers for iofog stack..."
docker-compose -f "docker-compose-iofog.yml" up --detach --build
docker-compose -f "docker-compose-iofog.yml" up --detach --no-recreate

echoInfo "Initializing iofog stack..."
docker logs -f "iofog-init" # wait for the ioFog stack initialization
Expand All @@ -44,10 +46,11 @@ startEnvironment() {
local ENVIRONMENT="$1"
local COMPOSE_PARAM="-f docker-compose-${ENVIRONMENT}.yml"

# Spin up containers for another environment
echoInfo "Spinning up containers for ${ENVIRONMENT} environment..."
echoInfo "Building containers for ${ENVIRONMENT} environment..."
docker-compose -f "docker-compose-iofog.yml" -f "docker-compose-${ENVIRONMENT}.yml" \
build "${ENVIRONMENT}-init"
build "${ENVIRONMENT}-init" > /dev/null

echoInfo "Spinning up containers for ${ENVIRONMENT} environment..."
docker-compose -f "docker-compose-iofog.yml" -f "docker-compose-${ENVIRONMENT}.yml" \
up --detach --no-recreate "${ENVIRONMENT}-init"

Expand All @@ -62,34 +65,18 @@ startEnvironment() {
echoInfo "It may take a while before ioFog stack creates all ${ENVIRONMENT} microservices."
}

! getopt -T
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echoError 'Your getopt version is insufficient!'
exit 2
fi

! OPTIONS=$(getopt --options="h" --longoptions="help" --name "$0" -- $@)
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
printHelp
exit 1
fi
eval set -- "${OPTIONS}"

ENVIRONMENT=''
while [[ "$#" -ge 1 ]]; do
case "$1" in
-h|--help)
printHelp
exit 0
;;
--)
shift
;;
*)
if [[ -n "${ENVIRONMENT}" ]]; then
echoError "Cannot specify more than one environment!"
printHelp
exit1
exit 1
fi
ENVIRONMENT=$1
shift
Expand Down Expand Up @@ -124,3 +111,6 @@ prettyTitle "ioFog Demo Environment is now running"
echoInfo " $(docker ps)"
echo
echoSuccess "## iofog-controller is running at http://localhost:$(docker port iofog-controller | awk '{print $1}' | cut -b 1-5)"
if [[ "${ENVIRONMENT}" == "tutorial" ]]; then
echoSuccess "## Visit https://iofog.org/docs/1.0.0/tutorial/introduction.html to continue with the ioFog tutorial."
fi
21 changes: 4 additions & 17 deletions stop.sh
Expand Up @@ -14,30 +14,17 @@ printHelp() {
echo " -h, --help print this help / usage"
}

! getopt -T
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echoError 'Your getopt version is insufficient!'
exit 2
fi

! OPTIONS=$(getopt --options="h" --longoptions="help" --name "$0" -- $@)
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
printHelp
exit 1
fi
eval set -- "$OPTIONS"

while [[ "$#" -ge 1 ]]; do
case "$1" in
-h|--help)
printHelp
exit 0
;;
--)
shift
;;
*)
echoError "Unrecognized argument!"
echoError "Unrecognized argument: \"$1\""
printHelp
exit 1
;;
esac
done

Expand Down

0 comments on commit 82b52dd

Please sign in to comment.