Skip to content

Commit

Permalink
New Dockerfile and update on Readme
Browse files Browse the repository at this point in the history
Also-by: Christian Häussler <c-n-i@web.de> (github: cniweb)
Also-by: Manfred Touron <m@42.am> (github: moul)
Signed-off-by: Hannes Schaller <admin@cyberkov.at> (github: cyberkov)
  • Loading branch information
cyberkov committed Apr 3, 2016
1 parent 82890fb commit da8aedc
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
/tmp-*
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
sudo: required
language: bash
branches:
only:
- master
services:
- docker
before_install:
- docker info
- docker run --rm --privileged multiarch/qemu-user-static:register --reset
- docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
env:
#global:
# - DOCKER_REPO=openhab/openhab
# Encrypted:
# - DOCKER_EMAIL
# - DOCKER_USERNAME
# - DOCKER_PASSWORD
matrix:
- TARGET=amd64 FLAVOR=online
- TARGET=amd64 FLAVOR=offline
- TARGET=armhf FLAVOR=online
- TARGET=armhf FLAVOR=offline
- TARGET=arm64 FLAVOR=online
- TARGET=arm64 FLAVOR=offline
matrix:
fast_finish: true
script:
- make build && (make push || (sleep 15; make push) || (sleep 15; make push))
56 changes: 56 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# openhab image
FROM multiarch/ubuntu-debootstrap:amd64-wily
#FROM multiarch/ubuntu-debootstrap:armhf-wily # arch=armhf
#FROM multiarch/ubuntu-debootstrap:arm64-wily # arch=arm64
ARG ARCH=amd64

ARG DOWNLOAD_URL="https://openhab.ci.cloudbees.com/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-online/target/openhab-online-2.0.0-SNAPSHOT.zip"
ENV APPDIR="/openhab" OPENHAB_HTTP_PORT='8080' OPENHAB_HTTPS_PORT='8443' EXTRA_JAVA_OPTS=''

# Install Basepackages
RUN \
apt-get update && \
apt-get install --no-install-recommends -y \
software-properties-common \
sudo \
unzip \
wget \
&& rm -rf /var/lib/apt/lists/*

# Install Oracle Java
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
apt-get install --no-install-recommends -y oracle-java8-installer && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

# Add openhab user
RUN adduser --disabled-password --gecos '' --home ${APPDIR} openhab &&\
adduser openhab sudo &&\
adduser openhab dialout &&\
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/openhab

WORKDIR ${APPDIR}

RUN \
wget -nv -O /tmp/openhab.zip ${DOWNLOAD_URL} &&\
unzip -q /tmp/openhab.zip -d ${APPDIR} &&\
rm /tmp/openhab.zip

RUN mkdir -p ${APPDIR}/userdata/logs && touch ${APPDIR}/userdata/logs/openhab.log

# Copy directories for host volumes
RUN cp -a /openhab/userdata /openhab/userdata.dist && \
cp -a /openhab/conf /openhab/conf.dist
COPY files/entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]

RUN chown -R openhab:openhab ${APPDIR}
USER openhab
# Expose volume with configuration and userdata dir
VOLUME ${APPDIR}/conf ${APPDIR}/userdata ${APPDIR}/addons
EXPOSE 8080 8443 5555
CMD server
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
TARGET ?= amd64
ARCHS ?= amd64 armhf arm64
BASE_ARCH ?= amd64
DOCKER_REPO ?= openhab/openhab
GIT_REPO ?= openhab/openhab-docker
GIT_BRANCH ?= master
FLAVOR ?= online
TRAVIS_TOKEN ?= secretsecret

ifeq ($(FLAVOR),offline)
DOWNLOAD_URL="https://openhab.ci.cloudbees.com/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-offline/target/openhab-offline-2.0.0-SNAPSHOT.zip"
else
DOWNLOAD_URL="https://openhab.ci.cloudbees.com/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-online/target/openhab-online-2.0.0-SNAPSHOT.zip"
endif

build: tmp-$(TARGET)/Dockerfile
docker build --build-arg ARCH=$(TARGET) --build-arg DOWNLOAD_URL=$(DOWNLOAD_URL) -t $(DOCKER_REPO):$(TARGET)-$(FLAVOR) tmp-$(TARGET)
docker run --rm $(DOCKER_REPO):$(TARGET)-$(FLAVOR) uname -a

tmp-$(TARGET)/Dockerfile: Dockerfile $(shell find files)
rm -rf tmp-$(TARGET)
mkdir tmp-$(TARGET)
cp Dockerfile $@
cp -rf files tmp-$(TARGET)/
for arch in $(ARCHS); do \
if [ "$$arch" != "$(TARGET)" ]; then \
sed -i "/arch=$$arch/d" $@; \
fi; \
done
sed -i '/#[[:space:]]*arch=$(TARGET)/s/^#//' $@
sed -i 's/#[[:space:]]*arch=$(TARGET)//g' $@
cat $@

test:
env IMAGE="$(DOCKER_REPO):$(TARGET)-$(FLAVOR)" \
bundle exec rspec

clean:
for arch in $(ARCHS); do \
rm -rf tmp-$$arch; \
done

push:
docker push $(DOCKER_REPO):$(TARGET)-$(FLAVOR)

trigger:
@curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token $(TRAVIS_TOKEN)" \
-d '{ "request": { "branch":"$(GIT_BRANCH)", "token": "$(TRAVIS_TOKEN)" }}' \
https://api.travis-ci.org/repo/$(subst /,%2F,$(GIT_REPO))/requests
1 change: 1 addition & 0 deletions README-short.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openHAB - a vendor and technology agnostic open source automation software for your home.
84 changes: 79 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,90 @@
# OpenHAB Docker Containers
# OpenHAB Docker Containers [![Build state](https://travis-ci.org/openhab/openhab-docker.svg?branch=master)](https://travis-ci.org/openhab/openhab-docker)

Repository for building docker containers for [OpenHAB](http://openhab.org) (Home Automation Server).

Comments, suggestions and contributions are welcome!

## Images
## Image Variants

Docker Images can you found here: [Docker Images](https://hub.docker.com/u/openhab/)
### ``openhab/openhab:<architecture>-<[on|off]line>``

## Build
* ``amd64``: ``online``, ``offline``
* ``armhf``: ``online``, ``offline``
* ``arm64``: ``online``, ``offline``

Travis build state: [![Build state](https://travis-ci.org/openhab/openhab-docker.svg?branch=master)](https://travis-ci.org/openhab/openhab-docker)
If you are unsure about what your needs are, you probably want to use ``openhab/openhab:amd64-online``.

prebuilt Docker Images can be found here: [Docker Images](https://hub.docker.com/u/openhab/openhab)

## Usage

**Important** To be able to use UPnP for discovery the container needs to be started with ``--net=host``.

The following will run openHAB in demo mode on the host machine:
```
docker run -it --name openhab --net=host openhab/openhab:amd64-online server
```

**NOTE** Although this is the simplest method to getting openHAB up and running, but it is not the preferred method. To properly run the container, please specify a **host volume** for the ``conf`` and ``userdata`` directory:


```
docker run \
--name openhab \
--net=host \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/timezone:/etc/timezone:ro \
-v /opt/openhab/conf:/openhab/conf \
-v /opt/openhab/userdata:/openhab/userdata \
-d \
--restart=always \
openhab/openhab:amd64-online
```

or with ``docker-compose.yml``
```
---
openhab:
image: 'openhab/openhab:amd64-online'
restart: always
ports:
- "8080:8080"
- "8443:8443"
- "5555:5555"
net: "host"
volumes:
- '/etc/localtime:/etc/localtime:ro'
- '/etc/timezone:/etc/timezone:ro'
- '/opt/openhab/userdata:/openhab/userdata'
- '/opt/openhab/conf:/openhab/conf'
command: "server"
```
then start with ``docker-compose up -d``

**Debug Mode**

You can start the container with the command ``docker run -it openhab/openhab debug`` to get into the debug shell.

**Environment variables**
* `OPENHAB_HTTP_PORT`=8080
* `OPENHAB_HTTPS_PORT`=8443
* `EXTRA_JAVA_OPTS`

**Parameters**

* `-p 8080` - the port of the webinterface
* `-v /openhab/conf` - openhab configs
* `-v /openhab/userdata` - openhab userdata directory
* `--device=/dev/ttyUSB0` - attach your devices like RFXCOM or Z-Wave Sticks to the container

## Building the image

Checkout the github repository and then run these commands:
```
$ docker build -t openhab/openhab .
$ docker run -it openhab/openhab server
```

## Contributing

Expand Down
26 changes: 26 additions & 0 deletions files/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -x
set -euo pipefail
IFS=$'\n\t'

# Initialize empty host volumes
if [ -z "$(ls -A "${APPDIR}/userdata")" ]; then
# Copy userdata dir
echo "No userdata found... initializing."
sudo cp -av "${APPDIR}/userdata.dist/." "${APPDIR}/userdata/"
fi

if [ -z "$(ls -A "${APPDIR}/conf")" ]; then
# Copy userdata dir
echo "No configuration found... initializing."
sudo cp -av "${APPDIR}/conf.dist/. ${APPDIR}/conf/"
fi

# Prettier interface
if [ "$1" = 'server' ] || [ "$1" = 'openhab' ]; then
eval "${APPDIR}/start.sh"
elif [ "$1" = 'debug' ]; then
eval "${APPDIR}/start_debug.sh"
else
exec "$@"
fi

0 comments on commit da8aedc

Please sign in to comment.