Skip to content

Commit

Permalink
Merge blank-environment into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrcal committed May 23, 2019
2 parents 1983e8a + 98b31f1 commit 2392fcd
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 35 deletions.
3 changes: 1 addition & 2 deletions azure-pipelines.yml
@@ -1,7 +1,6 @@
trigger:
- master
- develop
- blank-environment
- demo-environment

pool:
Expand All @@ -25,7 +24,7 @@ steps:
displayName: 'Configure Test Runner image'

- script: |
./start.sh demo
./start.sh
displayName: 'Start Connector, Controller, and Agent'

- script: |
Expand Down
25 changes: 13 additions & 12 deletions docker-compose-test.yml
@@ -1,15 +1,16 @@
services:
test-runner:
container_name: test-runner
environment:
- LOCAL=1
image: iofog/test-runner:latest
networks:
- iofog
volumes:
- ./conf:/conf
version: '3'
services:
# Test Harness image
test-runner:
container_name: test-runner
environment:
- LOCAL=1
image: iofog/test-runner:latest
networks:
- iofog
volumes:
- ./conf:/conf
volumes:
conf: null
conf: null
networks:
iofog: null
iofog: null
15 changes: 2 additions & 13 deletions docker-compose.yml
Expand Up @@ -21,9 +21,9 @@ services:
networks:
- iofog
# ioFog Agent, depends on Connector and Controller
iofog-agent-1:
iofog-agent:
build: ./iofog-agent
container_name: iofog-agent-1
container_name: iofog-agent
depends_on:
- iofog-controller
ports:
Expand All @@ -35,16 +35,5 @@ services:
networks:
- iofog

iofog-agent-2:
build: ./iofog-agent
container_name: iofog-agent-2
ports:
- "54322:54321"
- "8082:22"
privileged: true
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- iofog
networks:
iofog:
19 changes: 16 additions & 3 deletions start.sh
Expand Up @@ -2,6 +2,11 @@

set -e

# Import our helper functions
. ./utils.sh

prettyHeader "Starting ioFog Demo environment"

ENV='blank'
if [ ! -z "$1" ]; then
if [[ "$1" == *help* ]]; then
Expand All @@ -14,15 +19,23 @@ fi

echo "Starting up $ENV environment"

# Generate SSH keys for Tests to access Agent container
# Clean up any artifacts from a previous run
rm conf/id_ecdsa* || true

# Create a new ssh key and copy it into Agent
echoInfo "Adding new ssh key pair to Agent"
ssh-keygen -t ecdsa -N "" -f conf/id_ecdsa -q
cp conf/id_ecdsa.pub iofog-agent

# Bring up ioFog services
# Spin up our Docker compose environment
echoInfo "Building and Starting Docker Compose environment"
docker-compose -f docker-compose.yml up --build --detach

# Initialize ioFog services
sed "s|/init/.*|/init/$ENV|g" ./docker-compose-init.yml > /tmp/docker-compose-init.yml
cp /tmp/docker-compose-init.yml .
docker-compose -f docker-compose-init.yml up --build
docker-compose -f docker-compose-init.yml up --build

# Display the running environment
docker ps
echoNotify "ioFog Demo is now running"
15 changes: 13 additions & 2 deletions stop.sh
@@ -1,4 +1,15 @@
#!/usr/bin/env sh
# stop.sh - shut down the Demo docker-compose environment
#
# Usage: stop.sh

docker-compose down
docker-compose -f docker-compose-init.yml down
set -e

# Import our helper functions
. ./utils.sh

prettyHeader "Spinning down iofog Demo environment"
docker-compose down -v
docker-compose -f docker-compose-init.yml down

echoInfo "ioFog demo is stopped"
28 changes: 25 additions & 3 deletions test.sh
@@ -1,17 +1,39 @@
#!/usr/bin/env sh
# test.sh - Run the iofog Test Runner suite against the Demo environment
#
# Usage: test.sh

set -e

# Import our helper functions
. ./utils.sh

prettyHeader "Running Test Runner Suite"

# Output the config for our Test suite config
echo 'iofog-connector:8080' > conf/connector.conf
echo 'iofog-controller:51121' > conf/controller.conf
echo 'root@iofog-agent-1' > conf/agents.conf
echo 'root@iofog-agent-2' >> conf/agents.conf
echo 'root@iofog-agent' > conf/agents.conf

# Check to see if we are already running the Demo
NUM_CONTAINERS=$(docker-compose ps | grep iofog | grep Up | wc -l | awk '{print $1}')

if [ "$NUM_CONTAINERS" -eq "3" ]; then
echoInfo "Demo compose environment is already running"
else
echoInfo "Spinning up Demo compose environment"
docker-compose -f docker-compose.yml up
fi

echoInfo "Pulling Test Runner Image"
docker-compose -f docker-compose-test.yml pull test-runner

echoInfo "Running Test Runner suite"
docker-compose -f docker-compose-test.yml up \
--build \
--abort-on-container-exit \
--exit-code-from test-runner \
--force-recreate \
--renew-anon-volumes
--renew-anon-volumes

echoNotify "Test Runner Tests complete"
130 changes: 130 additions & 0 deletions utils.sh
@@ -0,0 +1,130 @@
#!/usr/bin/env sh
# utils.sh - a simple set of functions for use throughout our bash scripts
#
# Usage : source utils.sh


# Export the name of the script for later use
THIS_SCRIPT="$(basename "${0}")"
export THIS_SCRIPT

#
# Check for DEBUG - looks for the DEBUG environment variable. If it
# is found, it enables more debugging output.
checkForDebug() {

# Allow anyone to set a DEBUG environment variable for extra output
if env | grep -q "DEBUG"; then
echoNotify " :: DEBUG is set ::"
set -x
fi
}

#
# Display a nice header for any command line script. You can optionally populate it with a string
#
# Usage: prettyHeader "Bootstrapping ioFog"
#
prettyHeader() {
echoInfo "## $1 ####################################################"
echoInfo "## Copyright (C) 2019, Edgeworx, Inc."
echo
}

#
# Extract and display our script options in a pretty manner
#
# Usage: prettyUsage ${THIS_SCRIPT}
#
prettyUsage() {

grep -e '--.*")' <"${1}" | grep -v 'grep -e' | tr -d '"' | tr ')' '\t'
}

#
# Check for Installation will check to see whether a particular command exists in
# the $PATH of the current shell. Optionally, you can check for a specific version.
#
# Usage: checkForInstallation protoc "libprotoc 3.6.1"
#
checkForInstallation() {

# Does the command exist?
if [ ! "$(command -v "$1")" ]; then
echoError " ✖️ $1 not found please review your bootstrap script for missing dependencies"
exit 1
else
# Are we looking for a specific version?
if [ ! -z "$2" ]; then
if [ "$2" != "$($1 --version)" ]; then
echoError " ✖️ $1 is the wrong version. Found $($1 --version) but expected $2"
exit 1
fi
fi
echoSuccess " ✔️ $1 $2 found at $(command -v "$1")"
return 0
fi
}

#
# Check OS Platform attempts to determine which platform we're running on currently.
# It will export the results into two env variables that can be used in your scripts:
# $OS_ID - the name of the host os. E.g. ubuntu
# $D_NUM - the version number of the os E.g. 16
#
checkOSPlatform() {
if [ "$(uname -s)" = "Darwin" ]; then
ID=macos
D_NUM="$(sysctl kern.osproductversion | awk '{print $2}' | awk -F '.' '{print $1}')"
else
. /etc/os-release
D_NUM="$(echo ${VERSION_ID} | awk -F '.' '{print $1}')"

# Push us into privileged if we aren't already
if [ ! "$(id -u)" = "0" ] && [ ! "$1" = "--help" ]; then
echoNotify " If you are a new developer please run this script with --help"
exec sudo -E "PATH=$PATH" sh "${THIS_SCRIPT}" "$@"
fi
fi

export ID D_NUM
}

#
# The following are a bunch or pretty printing echo methods
#

# This is the list of colors used in our messages
NO_FORMAT="\\033[0m"
C_SKYBLUE1="\\033[38;5;117m"
C_DEEPSKYBLUE4="\\033[48;5;25m"
RED="\\033[38;5;1m"
GREEN="\\033[38;5;28m"

# Need this as bash and sh require different args for the echo command
if [ "${ISBASH}" ]; then
PRINTARGS="-e"
fi

# Basic subtle output
echoInfo() {
echo $PRINTARGS "${C_SKYBLUE1}$1 ${NO_FORMAT}"
}

# Highlighted output with a background
echoNotify() {
echo $PRINTARGS "${C_DEEPSKYBLUE4}${1} ${NO_FORMAT}"
}

# Hurrah!
echoSuccess() {
echo $PRINTARGS "${GREEN}$1 ${NO_FORMAT}"
}

# Houston, we have a problem!
echoError() {
echo $PRINTARGS "${RED}$1 ${NO_FORMAT}"
}

# Are we in debug mode?
checkForDebug

0 comments on commit 2392fcd

Please sign in to comment.