Skip to content

Commit

Permalink
Add env variable to build from local packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixcell committed Jun 10, 2019
1 parent 1620eaf commit 8282e30
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .env
@@ -0,0 +1,3 @@
LOCAL_AGENT_PACKAGE=
LOCAL_CONTROLLER_PACKAGE=
LOCAL_CONNECTOR_PACKAGE=
34 changes: 34 additions & 0 deletions README.md
Expand Up @@ -52,6 +52,40 @@ When you are finished, tear down the ioFog stack and all services deployed on it
./stop.sh
```

## Build from local packages

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.

### 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
* ...
```

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
```

## 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`.


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

## Interacting With The ioFog Stack - CLI

The simplest way to interact with Agent, Controller, and Connector deployed on a machine you have access to is to use the command line interface. The main interaction point for users is the Controller.
Expand Down
24 changes: 15 additions & 9 deletions docker-compose-iofog.yml
@@ -1,18 +1,22 @@
version: "3"
services:
iofog-connector:
build: ./services/iofog/iofog-connector
environment:
- LOCAL_CONNECTOR_PACKAGE
image: iofog-connector:local
build:
context: ./services/iofog/iofog-connector
args:
LOCAL_CONNECTOR_PACKAGE: ${LOCAL_CONNECTOR_PACKAGE}
container_name: iofog-connector
ports:
- "53321:8080"
network_mode: bridge

iofog-controller:
build: ./services/iofog/iofog-controller
environment:
- LOCAL_CONTROLLER_PACKAGE
image: iofog-controller:local
build:
context: ./services/iofog/iofog-controller
args:
LOCAL_CONTROLLER_PACKAGE: ${LOCAL_CONTROLLER_PACKAGE}
container_name: iofog-controller
depends_on:
- iofog-connector
Expand All @@ -25,9 +29,11 @@ services:
network_mode: bridge

iofog-agent:
build: ./services/iofog/iofog-agent
environment:
- LOCAL_AGENT_PACKAGE
image: iofog-agent:local
build:
context: ./services/iofog/iofog-agent
args:
LOCAL_AGENT_PACKAGE: ${LOCAL_AGENT_PACKAGE}
depends_on:
- iofog-controller
privileged: true
Expand Down
9 changes: 6 additions & 3 deletions services/iofog/iofog-agent/Dockerfile
@@ -1,5 +1,9 @@
FROM iofog/ubuntu-16.04-java8

ARG LOCAL_AGENT_PACKAGE
# Copy install script and local package if there is one (No conditional copy in docker)
COPY ./install.sh ${LOCAL_AGENT_PACKAGE}* /opt/iofog-agent/

# Install our deps
RUN apt-get update -qq && apt-get install -qqy \
sudo \
Expand All @@ -10,9 +14,8 @@ RUN apt-get update -qq && apt-get install -qqy \
&& rm -rf /var/lib/apt/lists/*

# Install iofog-agent (script requires sudo, curl and software-properties-common)
COPY ./install.sh ./install.sh
RUN ./install.sh
RUN rm ./install.sh
RUN /opt/iofog-agent/install.sh ${LOCAL_AGENT_PACKAGE}
RUN rm /opt/iofog-agent/install.sh

# SSH Magic
# Allows the test's container "test-runner" access to iofog-agent, due to the agent's lack of REST API
Expand Down
11 changes: 11 additions & 0 deletions services/iofog/iofog-agent/install.sh
@@ -0,0 +1,11 @@
#!/bin/sh

# If local agent provided, install from local package, otherwise go to packagecloud
if [ ! -z "$1" ] && [ ! "$1" = "./install.sh" ]; then
echo "============> Installing local agent"
dpkg -i /opt/iofog-agent/"$1"
rm -f /opt/iofog-agent/"$1"
else
wget -q -O - https://packagecloud.io/install/repositories/iofog/iofog-agent/script.deb.sh | bash
apt-get install iofog-agent
fi
9 changes: 6 additions & 3 deletions services/iofog/iofog-connector/Dockerfile
@@ -1,5 +1,9 @@
FROM iofog/ubuntu-16.04-java8

ARG LOCAL_CONNECTOR_PACKAGE
# Copy local package, or default install script (No conditional copy in docker)
COPY ./install.sh ${LOCAL_CONNECTOR_PACKAGE}* /opt/iofog-connector/

# Install all our deps
RUN apt-get update -qq && apt-get install -qqy \
sudo \
Expand All @@ -8,9 +12,8 @@ RUN apt-get update -qq && apt-get install -qqy \
&& rm -rf /var/lib/apt/lists/*

# Install iofog-connector (script requires sudo, curl and software-properties-common)
COPY ./install.sh ./install.sh
RUN ./install.sh
RUN rm ./install.sh
RUN /opt/iofog-connector/install.sh ${LOCAL_CONNECTOR_PACKAGE}
RUN rm /opt/iofog-connector/install.sh

# Copy in the connector configuration
COPY iofog-connector.conf /etc/iofog-connector/iofog-connector.conf
Expand Down
11 changes: 11 additions & 0 deletions services/iofog/iofog-connector/install.sh
@@ -0,0 +1,11 @@
#!/bin/sh

# If local connector provided, install from local package, otherwise go to packagecloud
if [ ! -z "$1" ] && [ ! "$1" = "./install.sh" ]; then
echo "============> Installing local connector"
dpkg -i /opt/iofog-connector/"$1"
rm -f /opt/iofog-connector/"$1"
else
wget -q -O - https://packagecloud.io/install/repositories/iofog/iofog-connector/script.deb.sh | bash
apt-get install iofog-connector
fi
9 changes: 6 additions & 3 deletions services/iofog/iofog-controller/Dockerfile
@@ -1,8 +1,11 @@
FROM node:8.16.0-alpine

ARG LOCAL_CONTROLLER_PACKAGE
# Copy local package, or default install script (No conditional copy in docker)
COPY ./install.sh ${LOCAL_CONTROLLER_PACKAGE}* /opt/iofog-controller/

# Install iofog-controller
COPY ./install.sh ./install.sh
RUN ./install.sh
RUN rm ./install.sh
RUN /opt/iofog-controller/install.sh ${LOCAL_CONTROLLER_PACKAGE}
RUN rm /opt/iofog-controller/install.sh

ENTRYPOINT [ "sh", "-c", "iofog-controller start && tail -f /dev/null" ]
10 changes: 10 additions & 0 deletions services/iofog/iofog-controller/install.sh
@@ -0,0 +1,10 @@
#!/bin/sh

# If local controller provided, install from local package, otherwise go to npm repository
if [ ! -z "$1" ] && [ ! "$1" = "./install.sh" ]; then
echo "============> Installing local controller"
npm install --unsafe-perm -g /opt/iofog-controller/"$1"
rm -f /opt/iofog-controller/"$1"
else
npm i -g iofogcontroller --unsafe-perm
fi
8 changes: 6 additions & 2 deletions start.sh
@@ -1,7 +1,6 @@
#!/bin/bash

set -o errexit -o pipefail -o noclobber -o nounset
set -x
cd "$(dirname "$0")"

# Import our helper functions
Expand All @@ -28,7 +27,11 @@ checkComposeFile() {

startIofog() {
echoInfo "Building containers for iofog stack..."
docker-compose -f "docker-compose-iofog.yml" build > /dev/null
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

echoInfo "Spinning up containers for iofog stack..."
docker-compose -f "docker-compose-iofog.yml" up --detach --no-recreate
Expand Down Expand Up @@ -84,6 +87,7 @@ 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 8282e30

Please sign in to comment.