Skip to content

Commit

Permalink
Fixes docker-compose, adds HTTPS and refactors image builds (fixes op…
Browse files Browse the repository at this point in the history
…enhab#234) (openhab#276)

* Feature/automate docker build (openhab#4)

* Moved Dockerfile into root

* Dockerfile tidying

Signed-off-by: Andre Lackmann <[email protected]>

* Feature/docker compose update (openhab#5)

* Moved Dockerfile into root
* Dockerfile tidying
* moving and updating docker-compose
* updated docker configuration and docs

Signed-off-by: Andre Lackmann <[email protected]>

* Updated docker-compose to use official image tag

Signed-off-by: Andre Lackmann <[email protected]>

* updated logging to work in docker using console

Signed-off-by: Andre Lackmann <[email protected]>
  • Loading branch information
alackmann authored and digitaldan committed Jan 16, 2020
1 parent d0186ec commit 56c6c78
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 170 deletions.
19 changes: 14 additions & 5 deletions deployment/docker/node/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,27 @@ RUN rm -rf \
/usr/lib/node_modules/npm/html \
/usr/lib/node_modules/npm/scripts

RUN mkdir -p /opt/openhabcloud
COPY ./package.json ./config.json /opt/openhabcloud/
RUN mkdir -p /opt/openhabcloud/logs
RUN mkdir /data

COPY ./package.json /opt/openhabcloud/
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

RUN rm -Rf /opt/openhabcloud/deployment
RUN rm -Rf /opt/openhabcloud/docs
RUN rm -Rf /opt/openhabcloud/tests
RUN rm /opt/openhabcloud/config-development.json
RUN rm /opt/openhabcloud/config-production.json

RUN chown openhabcloud: /opt/openhabcloud/logs

WORKDIR /opt/openhabcloud
USER openhabcloud
EXPOSE 3000
CMD ["node", "app.js"]
56 changes: 21 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,47 +233,34 @@ 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 (openhab/openhab-cloud/app-1:latest)
* mongodb: MongoDB database (bitnami/mongodb:latest)
* nginx: nginx proxy (openhab/openhab-cloud/nginx:latest)
* app: node.js and express.js (openhab/openhab-cloud/app:latest)
* mongodb: MongoDB database (mongo:4.1.10-bionic)
* redis: redis session manager (bitnami/redis:latest)
* traefik: http proxy with LetsEncrypt SSL Certs (traefik:1.7)

#### Prerequisites
To run openhab-cloud make sure docker, docker-machine and docker-compose are installed on your machine.
More information at [Docker's website](https://docs.docker.com/)
More information at [Docker's website](https://docs.docker.com/).

#### Configuration
You need to modify the ```config.json``` and adjust the hosts of mongodb and redis to match to the corresponding
container services of docker-compose:
```
"mongodb": {
"hosts": ["mongodb"],
"db": "openhab",
"user": "",
"password": ""
},
"redis": {
"host": "redis",
"port": "6379",
"password": "password"
},
```

To change the server IP/DNS matching your installation, please refer to [Setting up Nginx](#setupNginx)
The `docker-compose.yml` file assume you have ports 80, 443 and 8080 available on the host you intend to run on. If you don't, you'll need to adjust these.

#### 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:
1. Copy the files `docker-compose.yml`, `config-docker.json` and `deployment/docker/traefik.toml` onto the machine that will be hosting your OpenHAB Cloud, into the same directory.
1. In the `docker-compose.yml` file, update:
- In the `app` container, replace `<your-host-name>` with the DNS name you will be using to host OpenHAB Cloud. This helps configure traefik http proxying
- In the `mongodb` container, uncomment the volumes section and supply a local path for the mongo files. This allows your database to have persistence. If you miss this step, anytime you restart the containers, you'll need to setup things again.
1. In the `config-docker.json` file, update:
- the system / host entry to be the same DNS name you entered into the `docker-compose.yml` above (you don't need scheme, so just `myopenhab.domain.com` or similar)
- update the redis password to match what you've entered in `docker-compose.yml`
- update any other settings for OpenHAB Cloud as per the docs
1. In the `traefik.toml` file, update:
- the `domain` entry in the [Docker] section to match the domain you've used above twice already
- enter your email in the [acme] section so LetsEncrypt works properly.

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

#### Run
To create and run the composed application, use the following command:
Having created all the configs, you can fire it all up. To create and run the composed application, use the following command:
```
docker-compose up -d
```
Expand All @@ -286,7 +273,7 @@ docker-compose up -d --force-recreate

To make sure openhab-cloud is running, check the openhab-cloud app logs:
```
docker-compose logs app-1
docker-compose logs app
```

#### Stop & Cleanup
Expand All @@ -311,12 +298,11 @@ docker system prune

#### Access

Navigate your browser to ```http://<your-openhab-cloud-host>:<port>``` and log in (e.g. http://localhost:80)
Navigate your browser to ```https://<your-openhab-cloud-host>``` and log in (e.g. https://myopenhab.domain.com).

#### Limitations
* Lets Encrypt SSL is missing in the images and will be added soon
* The nginx configuration at /etc/nginx_openhabcloud.conf will be reused
If it's the first time you're starting up, make sure you have `registration_enabled` set to `true` in the `config-docker.yml` file so you can create an initial user login.

Assuming you don't plan to run an open system, switch this back to `false` once you've registered and restart.


## Installing openHAB Cloud on Amazon Web Services (AWS) ##
Expand Down
56 changes: 56 additions & 0 deletions config-docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"system": {
"host": "localhost",
"port": "443",
"protocol": "https",
"logger" : {
"type": "console"
},
"subDomainCookies": false
},
"express":{
"key" : "<create a key here>"
},
"apn" : {
"gateway": "gateway.push.apple.com",
"cert": "certs/aps/aps_production_cert.pem",
"key": "certs/aps/aps_production_key.pem",
"passphrase": "passphrase"
},
"gcm" : {
"jid": "[email protected]",
"password": "password"
},
"ifttt" : {
"iftttChannelKey" : "key",
"iftttTestToken" : "token"
},
"mail": {
"host" : "smtp",
"port" : 465,
"user" : "[email protected]",
"pass" : "123_openHAB"
},
"mongodb": {
"hosts": ["mongodb"],
"db": "openhab"
},
"redis": {
"host": "redis",
"port": "6379",
"password": "123_openHAB"
},
"mailer": {
"host" : "smtp.openhab.org",
"port": 465,
"secureConnection": true,
"user": "[email protected]",
"password": "123_openHAB",
"from": "My openHAB <[email protected]>"
},
"legal": {
"terms" : "",
"policy": ""
},
"registration_enabled": false
}
56 changes: 0 additions & 56 deletions deployment/docker/docker-compose.yml

This file was deleted.

8 changes: 0 additions & 8 deletions deployment/docker/nginx/Dockerfile

This file was deleted.

64 changes: 0 additions & 64 deletions deployment/docker/nginx/openhabcloud_nginx.conf

This file was deleted.

31 changes: 31 additions & 0 deletions deployment/docker/traefik.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
debug = false

logLevel = "ERROR"
defaultEntryPoints = ["https","http"]

[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]

[retry]

[api]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "yourdomain.com"
watch = true
exposedByDefault = false

[acme]
email = "[email protected]"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
Loading

0 comments on commit 56c6c78

Please sign in to comment.