Skip to content

Commit

Permalink
Build from upstream images
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck committed Jan 3, 2024
1 parent 51ccf21 commit 61c3988
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 76 deletions.
52 changes: 44 additions & 8 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"schedule": ["before 2am"],
"rebaseWhen": "behind-base-branch",
"dependencyDashboard": true,
"labels": ["dependencies", "no-stale"],
Expand All @@ -15,11 +16,39 @@
],
"datasourceTemplate": "docker"
},
{
"fileMatch": ["/Dockerfile$"],
"matchStrings": [
"ARG BASHIO_VERSION=[\"']?(?<currentValue>.+?)[\"']?\\s+"
],
"datasourceTemplate": "github-releases",
"depNameTemplate": "hassio-addons/bashio",
"versioningTemplate": "semver"
},
{
"fileMatch": ["/Dockerfile$"],
"matchStrings": [
"ARG S6_OVERLAY_VERSION=[\"']?(?<currentValue>.+?)[\"']?\\s+"
],
"datasourceTemplate": "github-tags",
"versioningTemplate": "loose",
"depNameTemplate": "just-containers/s6-overlay",
"extractVersionTemplate": "^v(?<version>.*)$"
},
{
"fileMatch": ["/Dockerfile$"],
"matchStrings": [
"ARG TEMPIO_VERSION=[\"']?(?<currentValue>.+?)[\"']?\\s+"
],
"datasourceTemplate": "github-releases",
"depNameTemplate": "home-assistant/tempio",
"versioningTemplate": "loose"
},
{
"fileMatch": ["/Dockerfile$"],
"matchStringsStrategy": "any",
"matchStrings": [
"\\s\\s(?<package>[a-z0-9][a-z0-9-_]+)=(?<currentValue>[a-z0-9-_.]+)\\s+"
"\\s\\s(?<package>[a-z0-9-_]+)=(?<currentValue>[a-z0-9-_.]+)\\s+"
],
"versioningTemplate": "loose",
"datasourceTemplate": "repology",
Expand All @@ -28,21 +57,28 @@
],
"packageRules": [
{
"matchDatasources": ["repology"],
"matchDatasources": ["github-releases"],
"matchDepNames": ["hassio-addons/bashio"],
"matchUpdateTypes": ["minor", "patch"],
"automerge": true
},
{
"groupName": "Add-on base image",
"matchDatasources": ["docker"]
"matchDatasources": ["repology"],
"automerge": true
},
{
"groupName": "Add-on base image",
"matchDatasources": ["docker"],
"matchUpdateTypes": ["minor", "patch"],
"groupName": "OpenSSL",
"matchDatasources": ["repology"],
"matchPackagePatterns": ["^alpine_.*/(libssl|libcrypto).*$"],
"automerge": true
},
{
"matchDatasources": ["github-tags"],
"groupName": "Alpine base image",
"matchDatasources": ["docker"]
},
{
"groupName": "Alpine base image",
"matchDatasources": ["docker"],
"matchUpdateTypes": ["patch"],
"automerge": true
}
Expand Down
151 changes: 86 additions & 65 deletions base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,73 +1,94 @@
ARG BUILD_FROM=ghcr.io/hassio-addons/base:15.0.3
ARG BUILD_FROM=node:18-alpine3.19
# hadolint ignore=DL3006
FROM ${BUILD_FROM}

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Environment variables
ENV \
CARGO_NET_GIT_FETCH_WITH_CLI=true \
HOME="/root" \
LANG="C.UTF-8" \
PIP_BREAK_SYSTEM_PACKAGES=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_EXTRA_INDEX_URL="https://wheels.home-assistant.io/musllinux-index/" \
PIP_NO_CACHE_DIR=1 \
PIP_PREFER_BINARY=1 \
PS1="$(whoami)@$(hostname):$(pwd)$ " \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \
S6_CMD_WAIT_FOR_SERVICES=1 \
YARN_HTTP_TIMEOUT=1000000 \
TERM="xterm-256color"

# NodeJS version to pack
ARG NODEJS_VERSION="18.19.0"
# Set shell
SHELL ["/bin/ash", "-o", "pipefail", "-c"]

# hadolint ignore=DL3003,DL4006,SC2155,DL3018,SC2046
# Install base system
ARG BUILD_ARCH=amd64
ARG BASHIO_VERSION="v0.16.2"
ARG S6_OVERLAY_VERSION="3.1.6.2"
ARG TEMPIO_VERSION="2021.09.0"
RUN \
apk add --no-cache \
libstdc++=13.2.1_git20231014-r0 \
&& ARCH= OPENSSL_ARCH='linux*' \
&& alpineArch="$(apk --print-arch)" \
&& case "${alpineArch##*-}" in \
x86_64) OPENSSL_ARCH=linux-x86_64;; \
x86) OPENSSL_ARCH=linux-elf;; \
aarch64) OPENSSL_ARCH=linux-aarch64;; \
arm*) OPENSSL_ARCH=linux-armv4;; \
*) ;; \
esac \
&& apk add --no-cache --virtual .build-deps-full \
binutils-gold=2.41-r0 \
g++=13.2.1_git20231014-r0 \
gcc=13.2.1_git20231014-r0 \
gnupg=2.4.3-r1 \
libgcc=13.2.1_git20231014-r0 \
linux-headers=6.5-r0 \
make=4.4.1-r2 \
python3=3.11.6-r1 \
&& export GNUPGHOME="$(mktemp -d)" \
# gpg keys listed at https://github.com/nodejs/node#release-keys
&& for key in \
4ED778F539E3634C779C87C6D7062848A1AB005C \
141F07595B7B3FFE74309A937405533BE57C7D57 \
74F12602B6F1C4E913FAA37AD3A89613643B6201 \
DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
61FC681DFB92A079F1685E77973F295594EC4689 \
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
108F52B48DB57BB0CC439B2997B01419BD92F80A \
A363A499291CBBC940DD62E41F10027AF002F8B0 \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
done \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODEJS_VERSION/node-v$NODEJS_VERSION.tar.xz" \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODEJS_VERSION/SHASUMS256.txt.asc" \
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
&& gpgconf --kill all \
&& rm -rf "$GNUPGHOME" \
&& grep " node-v$NODEJS_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xf "node-v$NODEJS_VERSION.tar.xz" \
&& cd "node-v$NODEJS_VERSION" \
&& ./configure \
&& make -j$(getconf _NPROCESSORS_ONLN) V= \
&& make install \
&& apk del .build-deps-full \
&& cd .. \
&& rm -Rf "node-v$NODEJS_VERSION" \
&& rm "node-v$NODEJS_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
# Remove unused OpenSSL headers to save ~34MB. See this NodeJS issue: https://github.com/nodejs/node/issues/46451
&& find /usr/local/include/node/openssl/archs -mindepth 1 -maxdepth 1 ! -name "$OPENSSL_ARCH" -exec rm -rf {} \; \
# smoke tests
&& node --version \
&& npm --version
set -o pipefail \
\
&& apk add --no-cache --virtual .build-dependencies \
tar=1.35-r2 \
xz=5.4.5-r0 \
\
&& apk add --no-cache \
libcrypto3=3.1.4-r2 \
libssl3=3.1.4-r2 \
musl-utils=1.2.4_git20230717-r4 \
musl=1.2.4_git20230717-r4 \
libstdc++=13.2.1_git20231014-r0 \
\
&& apk add --no-cache \
bash=5.2.21-r0 \
curl=8.5.0-r0 \
jq=1.7.1-r0 \
tzdata=2023d-r0 \
\
&& S6_ARCH="${BUILD_ARCH}" \
&& if [ "${BUILD_ARCH}" = "i386" ]; then S6_ARCH="i686"; \
elif [ "${BUILD_ARCH}" = "amd64" ]; then S6_ARCH="x86_64"; \
elif [ "${BUILD_ARCH}" = "armv7" ]; then S6_ARCH="arm"; fi \
\
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" \
| tar -C / -Jxpf - \
\
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz" \
| tar -C / -Jxpf - \
\
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz" \
| tar -C / -Jxpf - \
\
&& curl -L -s "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz" \
| tar -C / -Jxpf - \
\
&& curl -J -L -o /tmp/bashio.tar.gz \
"https://github.com/hassio-addons/bashio/archive/${BASHIO_VERSION}.tar.gz" \
&& mkdir /tmp/bashio \
&& tar zxvf \
/tmp/bashio.tar.gz \
--strip 1 -C /tmp/bashio \
\
&& mv /tmp/bashio/lib /usr/lib/bashio \
&& ln -s /usr/lib/bashio/bashio /usr/bin/bashio \
\
&& curl -L -s -o /usr/bin/tempio \
"https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}" \
&& chmod a+x /usr/bin/tempio \
\
&& apk del --no-cache --purge .build-dependencies \
&& rm -f -r \
/tmp/*

# Copy root filesystem
COPY rootfs /

# Copy s6-overlay adjustments
COPY s6-overlay /package/admin/s6-overlay-${S6_OVERLAY_VERSION}/

# Entrypoint & CMD
ENTRYPOINT ["/init"]
Expand All @@ -93,7 +114,7 @@ LABEL \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://addons.community" \
org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \
org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/master/README.md" \
org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \
org.opencontainers.image.created=${BUILD_DATE} \
org.opencontainers.image.revision=${BUILD_REF} \
org.opencontainers.image.version=${BUILD_VERSION}
6 changes: 3 additions & 3 deletions base/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

Check failure on line 1 in base/build.yaml

View workflow job for this annotation

GitHub Actions / workflows / Lint Add-on

{'aarch64': 'node:18-alpine3.19@sha256:91f3cd192c9f1a1a907b8f53bb8cf737557e6c1bb9dc499a725e48ba6ced58fd', 'amd64': 'node:18-alpine3.19@sha256:8842b060b01af71c082cee310b428a2d825e940d9fd9e450e05d726aea66a480', 'armv7': 'node:18-alpine3.19@sha256:62013ecc8888100e31f2e19698756d39e41a53e0047f766c868508701d668715'} is not valid under any of the given schemas
build_from:
aarch64: ghcr.io/hassio-addons/base:15.0.3
amd64: ghcr.io/hassio-addons/base:15.0.3
armv7: ghcr.io/hassio-addons/base:15.0.3
aarch64: node:18-alpine3.19@sha256:91f3cd192c9f1a1a907b8f53bb8cf737557e6c1bb9dc499a725e48ba6ced58fd
amd64: node:18-alpine3.19@sha256:8842b060b01af71c082cee310b428a2d825e940d9fd9e450e05d726aea66a480
armv7: node:18-alpine3.19@sha256:62013ecc8888100e31f2e19698756d39e41a53e0047f766c868508701d668715
codenotary:
signer: [email protected]
32 changes: 32 additions & 0 deletions base/rootfs/usr/bin/service
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# This script patches all service commands into the appropriate s6- commands
# ==============================================================================

start() {
s6-svc -wU -u -T2500 "/run/service/${service}"
}

stop() {
s6-svc -wD -d -T2500 "/run/service/${service}"
}

restart() {
stop
start
}

status() {
s6-svstat "/run/service/${service}"
}

service="$1"
command="$2"

if [[ ! -d "/run/service/${service}" ]] ; then
echo "s6 service not found for ${service}, exiting..."
exit
fi;

${command} "${service}"
38 changes: 38 additions & 0 deletions base/s6-overlay/etc/s6-rc/scripts/base-addon-banner
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# Displays a simple add-on banner on startup
# ==============================================================================
if bashio::supervisor.ping; then
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue " Add-on: $(bashio::addon.name)"
bashio::log.blue " $(bashio::addon.description)"
bashio::log.blue \
'-----------------------------------------------------------'

bashio::log.blue " Add-on version: $(bashio::addon.version)"
if bashio::var.true "$(bashio::addon.update_available)"; then
bashio::log.magenta ' There is an update available for this add-on!'
bashio::log.magenta \
" Latest add-on version: $(bashio::addon.version_latest)"
bashio::log.magenta ' Please consider upgrading as soon as possible.'
else
bashio::log.green ' You are running the latest version of this add-on.'
fi

bashio::log.blue " System: $(bashio::info.operating_system)" \
" ($(bashio::info.arch) / $(bashio::info.machine))"
bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"

bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue \
' Please, share the above information when looking for help'
bashio::log.blue \
' or support in, e.g., GitHub, forums or the Discord chat.'
bashio::log.blue \
'-----------------------------------------------------------'
fi
49 changes: 49 additions & 0 deletions base/s6-overlay/etc/s6-rc/scripts/base-addon-log-level
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# Sets the log level correctly
# ==============================================================================
declare log_level

# Check if the log level configuration option exists
if bashio::config.exists log_level; then

# Find the matching LOG_LEVEL
log_level=$(bashio::string.lower "$(bashio::config log_level)")
case "${log_level}" in
all)
log_level="${__BASHIO_LOG_LEVEL_ALL}"
;;
trace)
log_level="${__BASHIO_LOG_LEVEL_TRACE}"
;;
debug)
log_level="${__BASHIO_LOG_LEVEL_DEBUG}"
;;
info)
log_level="${__BASHIO_LOG_LEVEL_INFO}"
;;
notice)
log_level="${__BASHIO_LOG_LEVEL_NOTICE}"
;;
warning)
log_level="${__BASHIO_LOG_LEVEL_WARNING}"
;;
error)
log_level="${__BASHIO_LOG_LEVEL_ERROR}"
;;
fatal)
log_level="${__BASHIO_LOG_LEVEL_FATAL}"
;;
off)
log_level="${__BASHIO_LOG_LEVEL_OFF}"
;;
*)
bashio::exit.nok "Unknown log_level: ${log_level}"
esac

# Save determined log level so S6 can pick it up later
echo -n "${log_level}" > /var/run/s6/container_environment/LOG_LEVEL
bashio::log.blue "Log level is set to ${__BASHIO_LOG_LEVELS[$log_level]}"
fi
1 change: 1 addition & 0 deletions base/s6-overlay/etc/s6-rc/sources/base-addon-banner/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions base/s6-overlay/etc/s6-rc/sources/base-addon-banner/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/package/admin/s6-overlay/etc/s6-rc/scripts/base-addon-banner
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions base/s6-overlay/etc/s6-rc/sources/base-addon-log-level/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/package/admin/s6-overlay/etc/s6-rc/scripts/base-addon-log-level
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 61c3988

Please sign in to comment.