-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge docker repos Removes base image -> use docker caching Removes s6-overlay-base -> Include files here * Cleanup * Move cache back * Remove base trigger * Use inline cache * Remove inline * Rename final * Debug cache miss * Move label args * Test build
- Loading branch information
1 parent
255baee
commit ddf6870
Showing
8 changed files
with
264 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# syntax=docker/dockerfile:experimental | ||
ARG HASS_ARCH=amd64 | ||
ARG S6_ARCH=amd64 | ||
ARG RUST_ARCH=x86_64-unknown-linux-gnu | ||
ARG BUILD_VERSION=latest | ||
|
||
##################################################################### | ||
# # | ||
# Build Wheels # | ||
# # | ||
##################################################################### | ||
FROM python:3.9-slim as wheels-builder | ||
ARG RUST_ARCH | ||
|
||
ENV PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple | ||
ENV PATH="${PATH}:/root/.cargo/bin" | ||
|
||
# Install buildtime packages | ||
RUN set -x \ | ||
&& apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
ca-certificates \ | ||
curl \ | ||
gcc \ | ||
git \ | ||
libffi-dev \ | ||
libssl-dev | ||
|
||
RUN set -x \ | ||
&& curl -o rustup-init https://static.rust-lang.org/rustup/dist/${RUST_ARCH}/rustup-init \ | ||
&& chmod +x rustup-init \ | ||
&& ./rustup-init -y --no-modify-path --profile minimal --default-host ${RUST_ARCH} | ||
|
||
WORKDIR /wheels | ||
COPY requirements.txt . | ||
|
||
# build python wheels | ||
RUN set -x \ | ||
&& pip wheel -r requirements.txt | ||
|
||
##################################################################### | ||
# # | ||
# Download and extract s6 overlay # | ||
# # | ||
##################################################################### | ||
FROM alpine:latest as s6downloader | ||
# Required to persist build arg | ||
ARG S6_ARCH | ||
WORKDIR /s6downloader | ||
|
||
RUN set -x \ | ||
&& OVERLAY_VERSION=$(wget --no-check-certificate -qO - https://api.github.com/repos/just-containers/s6-overlay/releases/latest | awk '/tag_name/{print $4;exit}' FS='[""]') \ | ||
&& wget -O /tmp/s6-overlay.tar.gz "https://github.com/just-containers/s6-overlay/releases/download/${OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.gz" \ | ||
&& mkdir -p /tmp/s6 \ | ||
&& tar zxvf /tmp/s6-overlay.tar.gz -C /tmp/s6 \ | ||
&& mv /tmp/s6/* . | ||
|
||
##################################################################### | ||
# # | ||
# Download and extract bashio # | ||
# # | ||
##################################################################### | ||
FROM alpine:latest as bashiodownloader | ||
WORKDIR /bashio | ||
|
||
RUN set -x \ | ||
&& wget -O /tmp/bashio.tar.gz "https://github.com/hassio-addons/bashio/archive/v0.13.1.tar.gz" \ | ||
&& mkdir -p /tmp/bashio \ | ||
&& tar zxvf /tmp/bashio.tar.gz --strip 1 -C /tmp/bashio \ | ||
&& mv /tmp/bashio/lib/* . | ||
|
||
##################################################################### | ||
# # | ||
# Final Image # | ||
# # | ||
##################################################################### | ||
FROM python:3.9-slim AS final-build | ||
WORKDIR /app | ||
|
||
ENV DEBIAN_FRONTEND="noninteractive" | ||
|
||
RUN set -x \ | ||
&& apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
curl \ | ||
git \ | ||
jq \ | ||
openssl \ | ||
tzdata \ | ||
# cleanup | ||
&& rm -rf /tmp/* \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install bashio | ||
COPY --from=bashiodownloader /bashio /usr/lib/bashio | ||
RUN ln -s /usr/lib/bashio/bashio /usr/bin/bashio | ||
|
||
# Install s6 overlay | ||
COPY --from=s6downloader /s6downloader / | ||
|
||
# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#build-mounts-run---mount | ||
# Install pip dependencies with built wheels | ||
RUN --mount=type=bind,target=/tmp/wheels,source=/wheels,from=wheels-builder,rw \ | ||
set -x \ | ||
&& pip install --no-cache-dir -f /tmp/wheels -r /tmp/wheels/requirements.txt | ||
|
||
# Copy root filesystem | ||
COPY docker/rootfs / | ||
|
||
# Copy app | ||
COPY emulated_hue emulated_hue | ||
|
||
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2 | ||
|
||
# Required to persist build arg | ||
ARG BUILD_VERSION | ||
ARG HASS_ARCH | ||
LABEL \ | ||
io.hass.version=${BUILD_VERSION} \ | ||
io.hass.name="Hass Emulated Hue" \ | ||
io.hass.description="Hue Emulation for Home Assistant" \ | ||
io.hass.arch="${HASS_ARCH}" \ | ||
io.hass.type="addon" | ||
|
||
CMD ["/init"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/with-contenv bashio | ||
# ============================================================================== | ||
# Community Hass.io Add-ons: Emulated Hue | ||
# This file installs the Emulated Hue version if specified | ||
# ============================================================================== | ||
|
||
declare release_version | ||
|
||
if bashio::config.has_value 'tag_commit_or_branch'; then | ||
release_version=$(bashio::config 'tag_commit_or_branch') | ||
else | ||
release_version=${TAG_COMMIT_OR_BRANCH:-master} | ||
fi | ||
|
||
colon_count=$(tr -dc ':' <<<"$release_version" | awk '{ print length; }') | ||
repo_name="core" | ||
|
||
if [[ "$colon_count" == 1 ]]; then | ||
IFS=':' read -r -a array <<< "$release_version" | ||
username=${array[0]} | ||
ref=${array[1]} | ||
elif [ "$colon_count" == 2 ]; then | ||
IFS=':' read -r -a array <<< "$release_version" | ||
username=${array[0]} | ||
repo_name=${array[1]} | ||
ref=${array[2]} | ||
else | ||
username="hass-emulated-hue" | ||
ref=$release_version | ||
fi | ||
full_url="https://github.com/${username}/${repo_name}/archive/${ref}.tar.gz" | ||
bashio::log.info "Installing Emulated Hue version '${release_version}' (${full_url})..." | ||
curl -Lo /tmp/emulator.tar.gz "${full_url}" | ||
mkdir -p /tmp/emulator | ||
tar zxvf /tmp/emulator.tar.gz --strip 1 -C /tmp/emulator | ||
mv /tmp/emulator/emulated_hue . | ||
bashio::log.info "Installed successfully!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/with-contenv bashio | ||
# ============================================================================== | ||
# Community Hass.io Add-ons: Emulated Hue | ||
# This file defines environment variables based on user specified config options | ||
# This overrides native environment variables with options.json | ||
# ============================================================================== | ||
|
||
|
||
if bashio::fs.file_exists '/data/options.json'; then | ||
|
||
if bashio::config.has_value 'data'; then | ||
echo $(bashio::config 'data') > /var/run/s6/container_environment/DATA_DIR | ||
fi | ||
|
||
if bashio::config.has_value 'http_port'; then | ||
echo $(bashio::config 'http_port') > /var/run/s6/container_environment/HTTP_PORT | ||
fi | ||
|
||
if bashio::config.has_value 'https_port'; then | ||
echo $(bashio::config 'https_port') > /var/run/s6/container_environment/HTTPS_PORT | ||
fi | ||
|
||
if bashio::config.has_value 'token'; then | ||
echo $(bashio::config 'token') > /var/run/s6/container_environment/HASS_TOKEN | ||
fi | ||
|
||
if bashio::config.has_value 'url'; then | ||
echo $(bashio::config 'url') > /var/run/s6/container_environment/HASS_URL | ||
fi | ||
|
||
if bashio::config.has_value 'use_default_ports_for_discovery'; then | ||
echo $(bashio::config 'use_default_ports_for_discovery') > /var/run/s6/container_environment/USE_DEFAULT_PORTS | ||
fi | ||
|
||
if bashio::config.has_value 'verbose'; then | ||
echo $(bashio::config 'verbose') > /var/run/s6/container_environment/VERBOSE | ||
fi | ||
|
||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/execlineb -S0 | ||
# ============================================================================== | ||
# Community Hass.io Add-ons: Emulated Hue | ||
# Take down the S6 supervision tree when Emulated Hue fails to start/crashes | ||
# ============================================================================== | ||
|
||
s6-svscanctl -t /var/run/s6/services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/with-contenv bashio | ||
# ============================================================================== | ||
# Community Hass.io Add-ons: Emulated Hue | ||
# Runs Emulated Hue | ||
# ============================================================================== | ||
|
||
bashio::log.info "Starting Emulated Hue..." | ||
cd /app | ||
exec python3 -m emulated_hue |