Skip to content

Commit

Permalink
Use args instead of env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixcell committed Jun 10, 2019
1 parent 8282e30 commit ab0c8fb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
3 changes: 0 additions & 3 deletions .env

This file was deleted.

28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -56,34 +56,34 @@ When you are finished, tear down the ioFog stack and all services deployed on it

If you have a local version of the Agent, Controller and Connector, you can chose to build the containers using those local packages.
To do so, you will need a debian package (`.deb`) for the Agent and the Connector and a tarball (`.tgz`) for the Controller.
First place your packages into their respective directory under `services/iofog/` (I.E, the Agent debian package goes to `services/iofog/iofog-agent/<agent-package-name.deb>`)
Then you will have to add an environment variable to your `start.sh` command for each package you want to build locally.
You can provide `start.sh` with an option for each local package you want to use.

### Example
Folder structure:
```text
* services
- iofog
+ iofog-agent # Agent service files - part of the iofog stack
* iofog-agent-2.0.deb # Local agent package
+ iofog-connector # Connector service files - part of the iofog stack
* iofog-connector-2.0.deb # Local connector package
+ iofog-controller # Controller service files - part of the iofog stack
* iofog-controller-2.0.tgz # Local controller package
* services
* init
* test
* local-packages # Example folder where you would store your local packages
- iofog-agent_2.0.deb
- iofog-connector_2.0.deb
- iofog-controller_2.0.tgz
* start.sh
* stop.sh
* ...
```

Command:
```sh
LOCAL_AGENT_PACKAGE=iofog-agent-2.0.deb LOCAL_CONNECTOR_PACKAGE=iofog-connector-2.0.deb LOCAL_CONTROLLER_PACKAGE=iofog-controller-2.0.tgz ./start.sh
./start.sh -a ./local-packages/iofog-agent_2.0.deb -cn ./local-packages/iofog-connector_2.0.deb -ct ./local-packages/iofog-controller_2.0.tgz
```

## Force rebuild
If you have previously built the containers using local packages, or remote packages and you want to ensure that running `start.sh` will rebuild the images, you can also provide the environment variable `IOFOG_BUILD_NO_CACHE`.
If you have previously built the containers using local packages, or remote packages and you want to ensure that running `start.sh` will rebuild the images, you can also provide the `--no-cache` option


```sh
IOFOG_BUILD_NO_CACHE=true <any other env variables you need> ./start.sh
./start.sh --no-cache
```

## Interacting With The ioFog Stack - CLI
Expand Down Expand Up @@ -154,5 +154,5 @@ When you are done with the tutorial, you can tear down the sample application to
* start.sh
* stop.sh
* test.sh
* uitl.sh
* utils.sh
```
45 changes: 37 additions & 8 deletions start.sh
Expand Up @@ -7,11 +7,17 @@ cd "$(dirname "$0")"
. ./utils.sh

printHelp() {
echo "Usage: ./start.sh [environment]"
echo "Usage: ./start.sh [opts] [environment]"
echo "Starts ioFog environments and optionally sets up demo and tutorial environment"
echo ""
echo "Arguments:"
echo "Options:"
echo " -h, --help print this help / usage"
echo " -a, --agent specify a local agent package"
echo " -ct, --controller specify a local controller package"
echo " -cn, --connector specify a local connector package"
echo " --no-cache prevent the usage of cache during the build step"
echo ""
echo "Arguments:"
echo " [environment] setup demo application, optional, default: iofog"
echo " supported values: iofog, tutorial"
}
Expand All @@ -27,11 +33,9 @@ checkComposeFile() {

startIofog() {
echoInfo "Building containers for iofog stack..."
if [ ! -z "$IOFOG_BUILD_NO_CACHE" ]; then
docker-compose -f "docker-compose-iofog.yml" build --no-cache > /dev/null
else
docker-compose -f "docker-compose-iofog.yml" build > /dev/null
fi
local BUILD_ARGS="--build-arg LOCAL_CONTROLLER_PACKAGE=${CONTROLLER_PACKAGE} --build-arg LOCAL_CONNECTOR_PACKAGE=${CONNECTOR_PACKAGE} --build-arg LOCAL_AGENT_PACKAGE=${AGENT_PACKAGE}"
local COMPOSE_BUILD_ARGS="${IOFOG_BUILD_NO_CACHE} ${BUILD_ARGS:=""}"
docker-compose -f "docker-compose-iofog.yml" build ${COMPOSE_BUILD_ARGS} > /dev/null

echoInfo "Spinning up containers for iofog stack..."
docker-compose -f "docker-compose-iofog.yml" up --detach --no-recreate
Expand Down Expand Up @@ -70,12 +74,38 @@ startEnvironment() {
}

ENVIRONMENT=''
IOFOG_BUILD_NO_CACHE=''
AGENT_PACKAGE=''
CONTROLLER_PACKAGE=''
CONNECTOR_PACKAGE=''
while [[ "$#" -ge 1 ]]; do
case "$1" in
-h|--help)
printHelp
exit 0
;;
--no-cache)
IOFOG_BUILD_NO_CACHE="--no-cache"
shift
;;
-a|--agent)
AGENT_PACKAGE="local-agent-package.deb"
cp -i "$2" "./services/iofog/iofog-agent/$AGENT_PACKAGE" || true
shift
shift
;;
-ct|--controller)
CONTROLLER_PACKAGE="local-controller-package.tgz"
cp -i "$2" "./services/iofog/iofog-controller/$CONTROLLER_PACKAGE" || true
shift
shift
;;
-cn|--connector)
CONNECTOR_PACKAGE="local-connector-package.deb"
cp -i "$2" "./services/iofog/iofog-connector/$CONNECTOR_PACKAGE" || true
shift
shift
;;
*)
if [[ -n "${ENVIRONMENT}" ]]; then
echoError "Cannot specify more than one environment!"
Expand All @@ -87,7 +117,6 @@ while [[ "$#" -ge 1 ]]; do
;;
esac
done
IOFOG_BUILD_NO_CACHE=${IOFOG_BUILD_NO_CACHE:=""} # by default, use docker cache to build images
ENVIRONMENT=${ENVIRONMENT:="iofog"} # by default, setup only the ioFog stack

prettyHeader "Starting ioFog Demo (\"${ENVIRONMENT}\" environment)..."
Expand Down

0 comments on commit ab0c8fb

Please sign in to comment.