Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from jason-fox/feature/move-docker
Move Docker to Subdirectory
- Loading branch information
Showing
4 changed files
with
245 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ coverage/ | |
docs/ | ||
examples/ | ||
ghpages/ | ||
node_modules/ | ||
test/ | ||
rpm/ | ||
README.md |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U | ||
# | ||
# This file is part of lightweightM2M-iotagent | ||
# | ||
# lightweightM2M-iotagent is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the License, | ||
# or (at your option) any later version. | ||
# | ||
# lightweightM2M-iotagent is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
# See the GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public | ||
# License along with lightweightM2M-iotagent. | ||
# If not, see http://www.gnu.org/licenses/. | ||
# | ||
# For those usages not covered by the GNU Affero General Public License | ||
# please contact with: [daniel.moranjimenez@telefonica.com] | ||
# | ||
# Modified by: Daniel Calvo - ATOS Research & Innovation | ||
# | ||
ARG NODE_VERSION=8.12.0-slim | ||
FROM node:${NODE_VERSION} | ||
ARG GITHUB_ACCOUNT=telefonicaid | ||
ARG GITHUB_REPOSITORY=lightweightm2m-iotagent | ||
ARG DOWNLOAD=latest | ||
|
||
# Copying Build time arguments to environment variables so they are persisted at run time and can be | ||
# inspected within a running container. | ||
# see: https://vsupalov.com/docker-build-time-env-values/ for a deeper explanation. | ||
|
||
ENV GITHUB_ACCOUNT=${GITHUB_ACCOUNT} | ||
ENV GITHUB_REPOSITORY=${GITHUB_REPOSITORY} | ||
ENV DOWNLOAD=${DOWNLOAD} | ||
|
||
MAINTAINER FIWARE IoTAgent Team. Telefónica I+D | ||
|
||
# | ||
# The following RUN command retrieves the source code from GitHub. | ||
# | ||
# To obtain the latest stable release run this Docker file with the parameters | ||
# --no-cache --build-arg DOWNLOAD=stable | ||
# To obtain any speciifc version of a release run this Docker file with the parameters | ||
# --no-cache --build-arg DOWNLOAD=1.7.0 | ||
# | ||
# The default download is the latest tip of the master of the named repository on GitHub | ||
# | ||
# Alternatively for local development, just copy this Dockerfile into file the root of the repository and | ||
# replace the whole RUN statement by the following COPY statement in your local source using : | ||
# | ||
# COPY . /opt/iota-lwm2m/ | ||
# | ||
RUN if [ "${DOWNLOAD}" = "latest" ] ; \ | ||
then \ | ||
RELEASE="master"; \ | ||
echo "INFO: Building Latest Development"; \ | ||
elif [ "${DOWNLOAD}" = "stable" ]; \ | ||
then \ | ||
RELEASE=$(curl -s https://api.github.com/repos/"${GITHUB_ACCOUNT}"/"${GITHUB_REPOSITORY}"/releases/latest | grep 'tag_name' | cut -d\" -f4); \ | ||
echo "INFO: Building Latest Stable Release: ${RELEASE}"; \ | ||
else \ | ||
RELEASE="${DOWNLOAD}"; \ | ||
echo "INFO: Building Release: ${RELEASE}"; \ | ||
fi && \ | ||
# Ensure that unzip is installed, and download the sources | ||
apt-get update && \ | ||
apt-get install -y --no-install-recommends unzip && \ | ||
wget --no-check-certificate -O source.zip https://github.com/"${GITHUB_ACCOUNT}"/"${GITHUB_REPOSITORY}"/archive/"${RELEASE}".zip && \ | ||
unzip source.zip && \ | ||
rm source.zip && \ | ||
mv "${GITHUB_REPOSITORY}-${RELEASE}" /opt/iota-lwm2m && \ | ||
# Remove unzip and clean apt cache | ||
apt-get clean && \ | ||
apt-get remove -y unzip && \ | ||
apt-get -y autoremove | ||
|
||
WORKDIR /opt/iota-lwm2m | ||
|
||
RUN \ | ||
# Ensure that Git is installed prior to running npm install | ||
apt-get update && \ | ||
apt-get install -y git && \ | ||
npm install pm2@3.2.2 -g && \ | ||
echo "INFO: npm install --production..." && \ | ||
npm install --production && \ | ||
# Remove Git and clean apt cache | ||
apt-get clean && \ | ||
apt-get remove -y git && \ | ||
apt-get -y autoremove | ||
|
||
USER node | ||
ENV NODE_ENV=production | ||
|
||
ENTRYPOINT ["pm2-runtime", "bin/lwm2mAgent.js"] | ||
CMD ["-- ", "config.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# FIWARE IoT Agent for OMA LightWeight Machine2Machine | ||
|
||
[![FIWARE IoT Agents](https://nexus.lab.fiware.org/repository/raw/public/badges/chapters/iot-agents.svg)](https://www.fiware.org/developers/catalogue/) | ||
[![](https://nexus.lab.fiware.org/repository/raw/public/badges/stackoverflow/iot-agents.svg)](https://stackoverflow.com/questions/tagged/fiware+iot) | ||
|
||
This Internet of Things Agent is designed to be a bridge between the | ||
[OMA](https://www.omaspecworks.org/) | ||
[Lightweight M2M](https://www.omaspecworks.org/what-is-oma-specworks/iot/lightweight-m2m-lwm2m/) | ||
protocol and the | ||
[NGSI](https://swagger.lab.fiware.org/?url=https://raw.githubusercontent.com/Fiware/specifications/master/OpenAPI/ngsiv2/ngsiv2-openapi.json) | ||
interface of a context broker. | ||
|
||
It is based on the | ||
[IoT Agent Node.js Library](https://github.com/telefonicaid/iotagent-node-lib). | ||
Further general information about the FIWARE IoT Agents framework, its | ||
architecture and the common interaction model can be found in the library's | ||
GitHub repository. | ||
|
||
This project is part of [FIWARE](https://www.fiware.org/). For more information | ||
check the FIWARE Catalogue entry for the | ||
[IoT Agents](https://github.com/Fiware/catalogue/tree/master/iot-agents). | ||
|
||
## How to use this image | ||
|
||
The IoT Agent must be instantiated and connected to an instance of the [Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/), a sample `docker-compose` file can be found below. | ||
|
||
If the `IOTA_REGISTRY_TYPE=mongodb`, a [MongoDB](https://www.mongodb.com/) database | ||
instance is also required - the example below assumes that you | ||
have a `/data` directory in your hosting system in order to hold database | ||
files - please amend the attached volume to suit your own configuration. | ||
|
||
```yml | ||
version: '3.1' | ||
|
||
volumes: | ||
mongodb: | ||
|
||
services: | ||
iot-agent: | ||
image: fiware/lightweightm2m-iotagent | ||
hostname: iot-agent | ||
container_name: fiware-iot-agent | ||
depends_on: | ||
- mongodb | ||
expose: | ||
- "4041" | ||
- "7896" | ||
ports: | ||
- "4041:4041" | ||
- "7896:7896" | ||
environment: | ||
- "IOTA_CB_HOST=orion" | ||
- "IOTA_CB_PORT=1026" | ||
- "IOTA_NORTH_PORT=4041" | ||
- "IOTA_REGISTRY_TYPE=mongodb" | ||
- "IOTA_MONGO_HOST=mongo-db" | ||
- "IOTA_MONGO_PORT=27017" | ||
- "IOTA_MONGO_DB=iotagent-lwm2m" | ||
|
||
mongodb: | ||
image: mongo:3.6 | ||
hostname: mongo-db | ||
container_name: db-mongo | ||
ports: | ||
- "27017:27017" | ||
command: --bind_ip_all --smallfiles | ||
volumes: | ||
- mongodb:/data | ||
|
||
orion: | ||
image: fiware/orion | ||
hostname: orion | ||
container_name: fiware-orion | ||
depends_on: | ||
- mongodb | ||
expose: | ||
- "1026" | ||
ports: | ||
- "1026:1026" | ||
command: -dbhost mongodb | ||
``` | ||
|
||
## Configuration with environment variables | ||
|
||
Many settings can be configured using Docker environment variables. A typical IoT Agent | ||
Docker container is driven by environment variables such as those shown below: | ||
|
||
* `IOTA_CB_HOST` - Hostname of the context broker to update context | ||
* `IOTA_CB_PORT` - Port that context broker listens on to update context | ||
* `IOTA_NORTH_PORT` - Port used for configuring the IoT Agent and receiving context | ||
updates from the context broker | ||
* `IOTA_REGISTRY_TYPE` - Whether to hold IoT device info in memory or in a database | ||
* `IOTA_MONGO_HOST` - The hostname of MongoDB - used for holding device and service | ||
information | ||
* `IOTA_MONGO_PORT` - The port that MongoDB is listening on | ||
* `IOTA_MONGO_DB` - The name of the database used in MongoDB | ||
|
||
### Further Information | ||
|
||
The full set of overrides for the general parameters applicable to all IoT Agents are | ||
described in the Configuration section of the IoT Agent Library | ||
[Installation Guide](https://iotagent-node-lib.readthedocs.io/en/latest/installationguide/index.html#configuration). | ||
|
||
Further settings for the IoT Agent for LightWeight Machine2Machine itself - such as specific configurations | ||
for the LWM2M Port and Protocol - can be found in the IoT Agent for LightWeight Machine2Machine | ||
[Installation Guide](https://fiware-iotagent-lwm2m.readthedocs.io/en/latest/administrationGuide/index.html#configuration). | ||
|
||
## How to build your own image | ||
|
||
The [Dockerfile](https://github.com/telefonicaid/lwm2m-node-lib/blob/master/docker/Dockerfile) associated with this image can be used to build an image in several ways: | ||
|
||
* By default, the `Dockerfile` retrieves the **latest** version of the codebase direct from | ||
GitHub (the `build-arg` is optional): | ||
|
||
```console | ||
docker build -t iot-agent . --build-arg DOWNLOAD=latest | ||
``` | ||
|
||
* You can alter this to obtain the last **stable** release run this `Dockerfile` with the build | ||
argument `DOWNLOAD=stable` | ||
|
||
```console | ||
docker build -t iot-agent . --build-arg DOWNLOAD=stable | ||
``` | ||
|
||
* You can also download a specific release by running this `Dockerfile` with the build argument | ||
`DOWNLOAD=<version>` | ||
|
||
```console | ||
docker build -t iot-agent . --build-arg DOWNLOAD=1.7.0 | ||
``` | ||
|
||
* To download code from your own fork of the GitHub repository add the `GITHUB_ACCOUNT` and | ||
`GITHUB_REPOSITORY` arguments to the `docker build` command. | ||
|
||
```console | ||
docker build -t iot-agent . --build-arg GITHUB_ACCOUNT=<your account> --build-arg GITHUB_REPOSITORY=<your repo> | ||
``` | ||
|
||
Alternatively, if you want to build directly from your own sources, please copy the existing | ||
`Dockerfile` into file the root of the repository and amend it to copy over your local source using : | ||
|
||
```Dockerfile | ||
COPY . /opt/iota-lwm2m/ | ||
``` | ||
|
||
Full instructions can be found within the `Dockerfile` itself. |