Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated docker-compose and dockerization of openHAB-cloud #176

Merged
merged 7 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ to spin up the dockerized openhab-cloud backend.
#### Architecture
The dockerized openhab-cloud uses a separate docker image and container for each part of the overall system
according to the following stack:
* app-1: node.js and express.js (alpine-node:7.5)
* mongodb: MongoDB database (mongo:3)
* nginx: nginx proxy (nginx)
* redis: redis session manager (redis:alpine)
* app-1: node.js and express.js (openhab/openhab-cloud/app-1:latest)
* mongodb: MongoDB database (bitnami/mongodb:latest)
* nginx: nginx proxy (openhab/openhab-cloud/nginx:latest)
* redis: redis session manager (bitnami/redis:latest)

#### Prerequisites
To run openhab-cloud make sure docker, docker-machine and docker-compose are installed on your machine.
Expand All @@ -261,6 +261,16 @@ container services of docker-compose:

To change the server IP/DNS matching your installation, please refer to [Setting up Nginx](#setupNginx)

#### Customization

If you want to customize the openhab-cloud app or change e.g. configurations within ```config.json```,
you need to switch to the local build of the node app. Adjust the build stratgy in the ```docker-compose.yml```
and replace the ```image``` section of ```docker-compose.yml``` with the following lines, to not use the official docker hub images anymore and switch to your local sources as base for the app-1 image:

```build:
context: ./
dockerfile: ./docker/node/Dockerfile```

#### Run
To create and run the composed application, use the following command:
```
Expand Down
41 changes: 22 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
version: '2'
version: '3'
services:
app-1:
container_name: app-1
build:
context: ./
dockerfile: ./docker/node/Dockerfile
image: docker.io/openhab/openhabcloud-app
volumes:
- /opt/openhabcloud
- app-1:/opt/openhabcloud
working_dir: /opt/openhabcloud
networks:
- ohcloud-network
links:
- mongodb
- redis
ports:
- "3000"
- "3000"
depends_on:
- mongodb
- redis
restart: always
mongodb:
container_name: mongodb
build:
context: ./
dockerfile: ./docker/mongo/Dockerfile
image: bitnami/mongodb:latest
command: mongod --smallfiles --bind_ip_all
networks:
- ohcloud-network
ports:
- "27017"
volumes:
- /data/db
- /data/configdb
restart: always
redis:
container_name: redis
build:
context: ./
dockerfile: ./docker/redis/Dockerfile
image: bitnami/redis:latest
networks:
- ohcloud-network
ports:
- "6379"
environment:
- REDIS_PASSWORD=123_openHAB
restart: always
nginx:
container_name: nginx
build:
context: ./
dockerfile: ./docker/nginx/Dockerfile
image: docker.io/openhab/openhabcloud-nginx
volumes:
- app-1:/opt/openhabcloud
networks:
- ohcloud-network
ports:
- "80:80"
- "443:443"
- "80:8081"
- "443:8443"
links:
- app-1:app-1
volumes_from:
- app-1
volumes:
app-1:
networks:
ohcloud-network:
driver: bridge
4 changes: 0 additions & 4 deletions docker/mongo/Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Set nginx base image
FROM nginx
FROM bitnami/nginx

# File Author / Maintainer
MAINTAINER Mehmet Arziman

# Copy custom configuration file from the current directory
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/nginx/openhabcloud_nginx.conf /bitnami/nginx/conf/vhosts/my_vhost.conf
25 changes: 7 additions & 18 deletions docker/nginx/nginx.conf → docker/nginx/openhabcloud_nginx.conf
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
worker_processes 4;

events { worker_connections 1024; }

http {

include /etc/nginx/mime.types;

upstream app_server {
upstream app_server {
server app-1:3000 fail_timeout=5s max_fails=5;
}

server {
listen 80 default_server;
listen [::]:80 default_server;
server{
listen 0.0.0.0:8081;

charset utf-8;

access_log /var/log/nginx/openhab.org-access.log;
error_log /var/log/nginx/openhab.org-error.log;
access_log "/opt/bitnami/nginx/logs/openhabcloud-access.log";
error_log "/opt/bitnami/nginx/logs/openhabcloud-error.log";
client_max_body_size 300m;

root /opt/openhabcloud;

location ~ /.well-known {
Expand Down Expand Up @@ -69,7 +60,5 @@ http {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}
}
}
19 changes: 8 additions & 11 deletions docker/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ RUN rm -rf \
/usr/lib/node_modules/npm/html \
/usr/lib/node_modules/npm/scripts

# We going to use changes to package.json to force Docker not to use the cache
# when we change our app nodejs dependencies:
COPY ./package.json ./config.json /tmp/

RUN cd /tmp && npm install && npm rebuild bcrypt --build-from-source
RUN mkdir -p /opt/openhabcloud && cp -a /tmp/node_modules /opt/openhabcloud

# From here we load our application's code in, therefore the previous docker
# "layer" thats been cached will be used if possible
RUN mkdir -p /opt/openhabcloud
COPY ./package.json ./config.json /opt/openhabcloud/
RUN mkdir /data
RUN ln -s /opt/openhabcloud/package.json /data
WORKDIR /data
RUN npm install && npm rebuild bcrypt --build-from-source
ENV NODE_PATH /data/node_modules
WORKDIR /opt/openhabcloud

USER openhabcloud

ADD . /opt/openhabcloud

EXPOSE 3000

CMD ["node", "/opt/openhabcloud/app.js"]
CMD ["node", "app.js"]
4 changes: 0 additions & 4 deletions docker/redis/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion views/applications.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<%= date_util(oauth2tokens[i].created, timeZone).calendar() %>
</td>
<td>
<a href="<% oauth2tokens[i].oAuthClient.homeUrl %>"><img style="height: 24px;" src="/img/oauth2/<%= oauth2tokens[i].oAuthClient.icon %>"><%= oauth2tokens[i].oAuthClient.name %></a>
<a href="<% oauth2tokens[i].oAuthClient.homeUrl %>"><img style="height: 24px;" src="/img/oauth2/<%= oauth2tokens[i].oAuthClient.icon %>">&nbsp;<%= oauth2tokens[i].oAuthClient.name %></a>
</td>
<td>
<%= oauth2tokens[i].oAuthClient.description %>
Expand Down