feat: init

This commit is contained in:
nyyu 2024-04-30 08:31:10 +02:00
commit b1bfed4a2d
19 changed files with 176 additions and 0 deletions

48
Dockerfile Normal file
View file

@ -0,0 +1,48 @@
FROM debian:stable-slim
ENV S6_OVERLAY_VERSION=3.1.6.2 \
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \
S6_KEEP_ENV=1 \
USER=root \
HOMEBRIDGE_PKG_VERSION=1.2.0 \
HOMEBRIDGE_APT_PACKAGE=1 \
UIX_CUSTOM_PLUGIN_PATH="/var/lib/homebridge/node_modules" \
PATH="/opt/homebridge/bin:/var/lib/homebridge/node_modules/.bin:$PATH" \
HOME="/home/homebridge" \
npm_config_prefix=/opt/homebridge
RUN apt-get update && apt-get upgrade \
&& apt-get install --no-install-recommends -y curl psmisc procps iputils-ping \
ca-certificates jq net-tools xz-utils \
&& chmod 4755 /bin/ping \
&& apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* \
&& case "$(uname -m)" in \
x86_64) S6_ARCH='x86_64';; \
armv7l) S6_ARCH='armhf';; \
aarch64) S6_ARCH='aarch64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac \
&& curl -SLf https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz | tar -C / -Jxpf - \
&& curl -SLf https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz | tar -C / -Jxpf - \
&& case "$(uname -m)" in \
x86_64) DEB_ARCH='amd64';; \
armv7l) DEB_ARCH='armhf';; \
aarch64) DEB_ARCH='arm64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac \
&& curl -sSLf -o /homebridge_${HOMEBRIDGE_PKG_VERSION}.deb https://github.com/homebridge/homebridge-apt-pkg/releases/download/${HOMEBRIDGE_PKG_VERSION}/homebridge_${HOMEBRIDGE_PKG_VERSION}_${DEB_ARCH}.deb \
&& dpkg --force-all -i /homebridge_${HOMEBRIDGE_PKG_VERSION}.deb \
&& rm -rf /homebridge_${HOMEBRIDGE_PKG_VERSION}.deb \
&& chown -R root:root /opt/homebridge \
&& rm -rf /var/lib/homebridge \
&& rm -rf /opt/homebridge/include
# && find /opt/homebridge -regextype posix-egrep -regex ".*/node_modules/.*/(src|source|build|\.github|.*\.map)" -exec rm -rf {} +;
COPY rootfs /
EXPOSE 8581/tcp
VOLUME /homebridge
WORKDIR /homebridge
ENTRYPOINT [ "/init" ]

7
rootfs/defaults/.npmrc Normal file
View file

@ -0,0 +1,7 @@
audit = false
auto-install-peers = true
fund = false
global-style = true
loglevel = "error"
update-notifier = false
package-lock = false

13
rootfs/defaults/startup.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash
#
# Docker Homebridge Custom Startup Script - oznu/homebridge
#
# This script can be used to customise the environment and will be executed as
# the root user each time the container starts.
#
# Example installing packages:
#
# apt-get update
# apt-get install -y python3
#

View file

@ -0,0 +1,2 @@
setup
homebridge

View file

@ -0,0 +1,5 @@
#!/command/with-contenv sh
[ -e /homebridge/homebridge.log ] || touch /homebridge/homebridge.log
exec tail -f --follow=name /homebridge/homebridge.log

View file

@ -0,0 +1 @@
longrun

View file

@ -0,0 +1,2 @@
userdata
setup

View file

@ -0,0 +1,11 @@
#!/command/with-contenv sh
export HOME=/home/homebridge
export USER=root
export HOMEBRIDGE_CONFIG_UI=1
# this is not necessarily the ui version, it's now used as a feature compatibility indicator
export CONFIG_UI_VERSION=4.44.2
# start homebridge
exec /opt/homebridge/start.sh --allow-root

View file

@ -0,0 +1 @@
longrun

View file

@ -0,0 +1 @@
oneshot

View file

@ -0,0 +1 @@
/etc/s6-overlay/scripts/setup.sh

View file

@ -0,0 +1 @@
setup

View file

@ -0,0 +1 @@
oneshot

View file

@ -0,0 +1 @@
/etc/s6-overlay/scripts/userdata.sh

View file

@ -0,0 +1,61 @@
#!/command/with-contenv sh
# user defaults
[ -e /homebridge/startup.sh ] || cp /defaults/startup.sh /homebridge/startup.sh
# setup homebridge
mkdir -p /homebridge
if [ "$(realpath /var/lib/homebridge)" != "/homebridge" ]; then
rm -rf /var/lib/homebridge
ln -sf /homebridge /var/lib/homebridge
fi
# fix a mistake where we were creating a symlink loop
if [ -h "/homebridge/homebridge" ] && [ "$(realpath /homebridge/homebridge)" = "/homebridge" ]; then
rm /homebridge/homebridge
fi
cd /homebridge
# set the .npmrc file
cp /defaults/.npmrc /homebridge/.npmrc
# remove the package-lock.json
if [ -e /homebridge/package-lock.json ]; then
rm -rf /homebridge/package-lock.json
fi
# if coming from an old pnpm based install, delete plugins so they are freshly installed
if [ -e /homebridge/pnpm-lock.yaml ]; then
rm -rf /homebridge/node_modules
rm -rf /homebridge/pnpm-lock.yaml
rm -rf /homebridge/package-lock.json
fi
# setup initial package.json with homebridge
if [ ! -e /homebridge/package.json ]; then
HOMEBRIDGE_VERSION="$(curl -sf https://registry.npmjs.org/homebridge/latest | jq -r '.version')"
echo "{ \"dependencies\": { \"homebridge\": \"$HOMEBRIDGE_VERSION\" }}" | jq . > /homebridge/package.json
fi
# remove homebridge-config-ui-x from the package.json
if [ -e /homebridge/package.json ]; then
if [ "$(cat /homebridge/package.json | jq -r '.dependencies."homebridge-config-ui-x"')" != "null" ]; then
packageJson="$(cat /homebridge/package.json | jq -rM 'del(."dependencies"."homebridge-config-ui-x")')"
if [ "$?" = "0" ]; then
printf "$packageJson" > /homebridge/package.json
echo "Removed homebridge-config-ui-x from package.json"
fi
fi
fi
# source the setup script
if [ -f /opt/homebridge/source.sh ]; then
. "/opt/homebridge/source.sh"
fi
# install plugins
echo "Installing Homebridge and user plugins, please wait..."
npm --prefix /homebridge install
exit 0

View file

@ -0,0 +1,15 @@
#!/command/with-contenv sh
if [ -f /opt/homebridge/source.sh ]; then
. "/opt/homebridge/source.sh"
fi
# run user defined custom startup script
if [ -f /homebridge/startup.sh ]; then
echo "Executing user startup script /homebridge/startup.sh"
chmod +x /homebridge/startup.sh
cd /homebridge
/homebridge/startup.sh
fi
exit 0

View file

@ -0,0 +1,5 @@
# this docker container does not use systemd
# the homebridge apt package just checks this file to see if the user has been changed from the default
[Service]
User=root