Skip to content

Commit

Permalink
S6 Overlay Refactor (#4)
Browse files Browse the repository at this point in the history
* Try using s6 overlay to manage services

* Minor updates

* puid & pgid in docker-compose example

* updated raspberry-pi image

* locked node version

* use correct tag for arm image
  • Loading branch information
oznu authored Jun 30, 2017
1 parent 0a31592 commit f5d4ce5
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 47 deletions.
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:6.10.1-alpine
FROM oznu/s6-node:6.11.0

RUN apk add --no-cache tzdata curl git python make g++ libffi-dev openssl-dev avahi-compat-libdns_sd avahi-dev openrc dbus
RUN apk add --no-cache git python make g++ libffi-dev openssl-dev avahi-compat-libdns_sd avahi-dev openrc dbus

RUN yarn global add node-gyp
RUN yarn global add homebridge
Expand All @@ -13,8 +13,6 @@ COPY default.config.json /home/root/homebridge

VOLUME /homebridge

RUN mkdir /init.d
COPY init.d/ /init.d
ENTRYPOINT ["/init.d/entrypoint.sh"]
ENV S6_KEEP_ENV=1

CMD ["homebridge", "-U", "/homebridge", "-P", "/homebridge/node_modules"]
COPY root /
16 changes: 6 additions & 10 deletions Dockerfile.raspberry-pi
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
FROM resin/raspberry-pi-alpine-node:6.10-slim
FROM oznu/s6-node:6.11.0-armhf

RUN apk add --no-cache tzdata curl git python make g++ libffi-dev openssl-dev avahi-compat-libdns_sd avahi-dev openrc dbus
RUN apk add --no-cache git python make g++ libffi-dev openssl-dev avahi-compat-libdns_sd avahi-dev openrc dbus

RUN npm install -g yarn

RUN npm install -g node-gyp
RUN npm install -g homebridge
RUN yarn global add node-gyp
RUN yarn global add homebridge

RUN mkdir /homebridge && mkdir -p /home/root/homebridge
WORKDIR /homebridge
Expand All @@ -15,8 +13,6 @@ COPY default.config.json /home/root/homebridge

VOLUME /homebridge

RUN mkdir /init.d
COPY init.d/ /init.d
ENTRYPOINT ["/init.d/entrypoint.sh"]
ENV S6_KEEP_ENV=1

CMD ["homebridge", "-U", "/homebridge", "-P", "/homebridge/node_modules"]
COPY root /
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ Currently this will not work when using [Docker for Mac](https://docs.docker.com

## Usage

Quick Setup:

```shell
docker run
--net=host
--name=homebridge
-e TZ=<timezone>
-v </path/to/config>:/homebridge
docker run \
--net=host \
--name=homebridge \
-e PUID=<UID> -e PGID=<GID> \
-e TZ=<timezone> \
-v </path/to/config>:/homebridge \
oznu/homebridge
```

Expand All @@ -45,13 +44,26 @@ The parameters are split into two halves, separated by a colon, the left hand si
* `--net=host` - Shares host networking with container, **required**.
* `-v /homebridge` - The Homebridge config and plugin location.
* `-e TZ` - for [timezone information](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) *e.g. Europe/London, etc*
* `-e PGID=` for for GroupID - see below for explanation
* `-e PUID=` for for UserID - see below for explanation

### User / Group Identifiers

Sometimes when using data volumes (`-v` flags) permissions issues can arise between the host OS and the container. We avoid this issue by allowing you to specify the user `PUID` and group `PGID`. Ensure the data volume directory on the host is owned by the same user you specify and it will "just work".

In this instance `PUID=1001` and `PGID=1001`. To find yours use `id user` as below:

```
$ id <dockeruser>
uid=1001(dockeruser) gid=1001(dockergroup) groups=1001(dockergroup)
```

## Config
## Homebridge Config

The Homebridge config file is located at ```</path/to/config>/config.json```
This file will be created the first time you run the container with a sample [FakeBulb](https://www.npmjs.com/package/homebridge-fakebulb) accessory.

## Plugins
## Homebridge Plugins

Plugins should be defined in the ```</path/to/config>/package.json``` file in the standard NPM format.
This file will be created the first time you run the container with the [FakeBulb](https://www.npmjs.com/package/homebridge-fakebulb) module.
Expand Down Expand Up @@ -101,6 +113,8 @@ services:
network_mode: host
environment:
- TZ=Australia/Sydney
- PGID=911
- PUID=911
volumes:
- ./volumes/homebridge:/homebridge
```
Expand Down
8 changes: 0 additions & 8 deletions init.d/set-timezone.sh

This file was deleted.

18 changes: 4 additions & 14 deletions init.d/entrypoint.sh → root/etc/cont-init.d/50-plugins
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
#!/bin/sh

/init.d/set-timezone.sh

rm -rf /var/run/dbus.pid
rm -rf /var/run/avahi-daemon//pid

dbus-daemon --system
avahi-daemon -D
#!/usr/bin/with-contenv sh

[ -f /homebridge/package.json ] || cp /home/root/homebridge/default.package.json /homebridge/package.json
[ -f /homebridge/config.json ] || cp /home/root/homebridge/default.config.json /homebridge/config.json

echo "Removing old plugins..."
echo "Homebridge: Removing old plugins..."
npm prune
echo "Installing plugins..."
echo "Homebridge: Installing plugins..."
yarn install

sleep 5

exec "$@"
chown -R abc:abc /homebridge
8 changes: 8 additions & 0 deletions root/etc/services.d/avahi/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/with-contenv sh

until [[ -e /var/run/dbus/system_bus_socket ]]; do
sleep 1s
done

echo "Starting Avahi daemon"
exec avahi-daemon
4 changes: 4 additions & 0 deletions root/etc/services.d/dbus/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv sh

echo "Starting dbus-daemon"
exec dbus-daemon --system --nofork
3 changes: 3 additions & 0 deletions root/etc/services.d/homebridge/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv sh
sleep 5
s6-setuidgid abc homebridge -U /homebridge -P /homebridge/node_modules

0 comments on commit f5d4ce5

Please sign in to comment.