Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work #18

Merged
merged 8 commits into from
Mar 13, 2024
Merged

Work #18

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ on: [push, pull_request]
jobs:
test:
# The type of runner that the job will run on
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
@@ -31,8 +31,6 @@ jobs:

- name: Start apt proxy
run: |
# Hiding the read-only token base64 to avoid github disabling it...
echo OWMyMGVhYzk4N2NhYWQxYmI3MzhmNTZkODNmOGMwOGJjZjlhNDc4YQo= | base64 -d | docker login ghcr.io -u dubo-dubon-duponey --password-stdin
docker run --rm -d --expose 443 --expose 80 --pull always \
--name apt-front \
--read-only \
@@ -47,12 +45,13 @@ jobs:
--env ADDITIONAL_DOMAINS=*.debian.org \
--volume "$GITHUB_WORKSPACE/cache/certs":/certs \
--volume "$GITHUB_WORKSPACE/cache/apt":/data \
index.docker.io/dubodubonduponey/aptutil:bullseye-2021-08-01
docker.io/dubodubonduponey/aptutil:bullseye-2021-08-01

- name: test
run: |
# Set the path and install the tools
BIN_LOCATION="$GITHUB_WORKSPACE/cache/bin" source ./hack/helpers/install-tools.sh
export PATH="$GITHUB_WORKSPACE/cache/bin:$PATH"
./hack/helpers/install-tools.sh
# Start buildkit
bkaddr="$(./hack/helpers/start-buildkit.sh 2>/dev/null)"
# Sanity check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -2,3 +2,5 @@
/.idea
*/cache/*
cache
*trace.json
xxx-*
6 changes: 3 additions & 3 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@

### The what

This image is built using: `index.docker.io/dubodubonduponey/base:builder-bullseye-2021-11-01`
This image is built using: `docker.io/dubodubonduponey/base:builder-bullseye-2022-12-01`

The runtime part is based on: `index.docker.io/dubodubonduponey/base:runtime-bullseye-2021-11-01`
The runtime part is based on: `docker.io/dubodubonduponey/base:runtime-bullseye-2022-12-01`

Both these images are built upon: `index.docker.io/dubodubonduponey/debian:bullseye-2021-11-01`
Both these images are built upon: `docker.io/dubodubonduponey/debian:bullseye-2022-12-01`

You can find out more here:

37 changes: 19 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ARG FROM_REGISTRY=index.docker.io/dubodubonduponey
ARG FROM_REGISTRY=docker.io/dubodubonduponey

ARG FROM_IMAGE_FETCHER=base:golang-bullseye-2022-06-01@sha256:7780f88fc0da1a5fd87f91cbb229e6932fc1fc2993f9c2d04210f6b909b93172
ARG FROM_IMAGE_BUILDER=base:builder-bullseye-2022-06-01@sha256:3fe68fe3e3eb1c295bd5213cc4a296e929ab59c139ba1a55a04f716c352229ee
ARG FROM_IMAGE_AUDITOR=base:auditor-bullseye-2022-06-01@sha256:a2f2097b9b24c3650e149acb25719f72e56b01df139f120fc1f783d46260a8ce
ARG FROM_IMAGE_TOOLS=tools:linux-bullseye-2022-05-01@sha256:6268013e3bd16eaaf7dd15c7689f8740bd00af1149c92795cc42fab4f3c6d07a
ARG FROM_IMAGE_RUNTIME=base:runtime-bullseye-2022-06-01@sha256:fe875fbfa104beb7afbcfafe3d8ab9b3640c7d25a0ea285a76bf3d71ca216300
ARG FROM_IMAGE_FETCHER=base:golang-bookworm-2024-02-20
ARG FROM_IMAGE_BUILDER=base:builder-bookworm-2024-02-20
ARG FROM_IMAGE_AUDITOR=base:auditor-bookworm-2024-02-20
ARG FROM_IMAGE_TOOLS=tools:linux-bookworm-2024-02-20
ARG FROM_IMAGE_RUNTIME=base:runtime-bookworm-2024-02-20

FROM $FROM_REGISTRY/$FROM_IMAGE_TOOLS AS builder-tools

@@ -41,8 +41,8 @@ RUN --mount=type=secret,uid=100,id=CA \
eval "$(dpkg-architecture -A "$(echo "$TARGETARCH$TARGETVARIANT" | sed -e "s/^armv6$/armel/" -e "s/^armv7$/armhf/" -e "s/^ppc64le$/ppc64el/" -e "s/^386$/i386/")")"; \
apt-get update -qq; \
apt-get install -qq --no-install-recommends \
libpulse-dev:"$DEB_TARGET_ARCH"=14.2-2 \
libasound2-dev:"$DEB_TARGET_ARCH"=1.2.4-1.1
libpulse-dev:"$DEB_TARGET_ARCH"=16.1+dfsg1-2+b1 \
libasound2-dev:"$DEB_TARGET_ARCH"=1.2.8-1+b1

# Maybe consider https://github.com/japaric/rust-cross for cross-compilation

@@ -104,7 +104,7 @@ RUN --mount=type=secret,uid=100,id=CA \
eval "$(dpkg-architecture -A "$(echo "$TARGETARCH$TARGETVARIANT" | sed -e "s/^armv6$/armel/" -e "s/^armv7$/armhf/" -e "s/^ppc64le$/ppc64el/" -e "s/^386$/i386/")")"; \
apt-get update -qq && \
apt-get install -qq --no-install-recommends \
fbi:"$DEB_TARGET_ARCH"=2.10-4 \
fbi:"$DEB_TARGET_ARCH"=2.10-4+b1 \
&& apt-get -qq autoremove \
&& apt-get -qq clean \
&& rm -rf /var/lib/apt/lists/* \
@@ -162,10 +162,10 @@ RUN --mount=type=secret,uid=100,id=CA \
--mount=type=secret,id=APT_CONFIG \
apt-get update -qq && \
apt-get install -qq --no-install-recommends \
libasound2=1.2.4-1.1 \
libpulse0=14.2-2 \
curl=7.74.0-1.3+deb11u1 \
fbi=2.10-4 \
libasound2=1.2.8-1+b1 \
libpulse0=16.1+dfsg1-2+b1 \
curl=7.88.1-10+deb12u5 \
fbi=2.10-4+b1 \
jq=1.6-2.1 \
&& apt-get -qq autoremove \
&& apt-get -qq clean \
@@ -182,16 +182,17 @@ ENV _SERVICE_TYPE="spotify-connect"
COPY --from=assembly --chown=$BUILD_UID:root /dist /

### mDNS broadcasting
# XXX note this unfortunately does not work with librespot
# Whether to enable MDNS broadcasting or not
ENV MDNS_ENABLED=true
ENV MOD_MDNS_ENABLED=false
# Type to advertise
ENV MDNS_TYPE="_$_SERVICE_TYPE._tcp"
ENV MOD_MDNS_TYPE="_$_SERVICE_TYPE._tcp"
# Name is used as a short description for the service
ENV MDNS_NAME="$_SERVICE_NICK mDNS display name"
ENV MOD_MDNS_NAME="$_SERVICE_NICK mDNS display name"
# The service will be annonced and reachable at $MDNS_HOST.local (set to empty string to disable mDNS announces entirely)
ENV MDNS_HOST="$_SERVICE_NICK"
ENV MOD_MDNS_HOST="$_SERVICE_NICK"
# Also announce the service as a workstation (for example for the benefit of coreDNS mDNS)
ENV MDNS_STATION=true
ENV ADVANCED_MOD_MDNS_STATION=true


ENV LOG_LEVEL="warn"
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -44,14 +44,14 @@ The following is the most straight-forward example, using host networking:
```bash
docker run -d --rm \
--name "spot" \
--env "NAME=Super Name For Your Spotify Connect Endpoint" \
--env "MDNS_NAME=Super Name For Your Spotify Connect Endpoint" \
--volume /tmp \
--group-add audio \
--device /dev/snd \
--net host \
--cap-drop ALL \
--read-only \
index.docker.io/dubodubonduponey/spotify
docker.io/dubodubonduponey/spotify
```

## Notes
@@ -70,14 +70,14 @@ Here is an example:
```bash
docker run -d --rm \
--name "spot" \
--env "NAME=Super Name For Your Spotify Connect Endpoint" \
--env "MDNS_NAME=Super Name For Your Spotify Connect Endpoint" \
--volume /tmp \
--group-add audio \
--device /dev/snd \
--net host \
--cap-drop ALL \
--read-only \
index.docker.io/dubodubonduponey/spotify \
docker.io/dubodubonduponey/spotify \
--device default:CARD=Mojo \
--enable-volume-normalisation \
-v
@@ -86,15 +86,15 @@ docker run -d --rm \
For a reference of all librespot options, try:
```bash
docker run --rm \
index.docker.io/dubodubonduponey/spotify \
docker.io/dubodubonduponey/spotify \
--help
```

### Custom configuration

You may specify the following environment variables at runtime:

* `NAME` (eg: `Totale Croquette`) controls the "name" under which your endpoint will appear in Spotify
* `MDNS_NAME` (eg: `Totale Croquette`) controls the "name" under which your endpoint will appear in Spotify

You can also tweak the following for control over which internal ports are being used:

14 changes: 8 additions & 6 deletions context/runtime/boot/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -12,21 +12,23 @@ helpers::dir::writable /tmp

readonly PORT="${PORT:-10042}"
# This is purely cached music, so, disposable and transient
args=(--cache-size-limit 8G --cache /tmp/cache --name "${MDNS_NAME:-Sproutify}" --bitrate 320 --device-type speaker --zeroconf-port "$PORT")
args=(--cache-size-limit 8G --cache /tmp/cache --name "${MOD_MDNS_NAME:-Sproutify}" --bitrate 320 --device-type speaker --zeroconf-port "$PORT")

# Hook the experimental display script if asked to
[ ! "$SPOTIFY_CLIENT_ID" ] || [ ! "$SPOTIFY_CLIENT_SECRET" ] || [ ! "$DISPLAY_ENABLED" ] || args+=(--onevent /boot/onevent.sh)

# mDNS blast if asked to
[ "${MDNS_ENABLED:-}" != true ] || {
[ ! "${MDNS_STATION:-}" ] || mdns::records::add "_workstation._tcp" "$MDNS_HOST" "${MDNS_NAME:-}" "$PORT"
mdns::records::add "${MDNS_TYPE:-_spotify-connect._tcp}" "$MDNS_HOST" "${MDNS_NAME:-}" "$PORT" '["VERSION=1", "CPath=/"]'
mdns::records::broadcast &
[ "${MOD_MDNS_ENABLED:-}" != true ] || {
[ "${ADVANCED_MOD_MDNS_STATION:-}" != true ] || mdns::records::add "_workstation._tcp" "${MOD_MDNS_HOST}" "${MOD_MDNS_NAME:-}" "$PORT"
mdns::records::add "${ADVANCED_MOD_MDNS_TYPE:-_spotify-connect._tcp}" "${MOD_MDNS_HOST:-}" "${MOD_MDNS_NAME:-}" "$PORT" '["VERSION=1", "CPath=/"]'
mdns::start::broadcaster &
args+=(--disable-discovery)
}

normalized_log_level="$(printf "%s" "$LOG_LEVEL" | tr '[:upper:]' '[:lower:]')"
[ "$normalized_log_level" != "debug" ] || args+=(--verbose)
[ "$normalized_log_level" != "error" ] && [ "$normalized_log_level" != "warning" ] || args+=(--quiet)

[ "$(printf "%s" "$LOG_LEVEL" | tr '[:upper:]' '[:lower:]')" != "debug" ] || args+=(--verbose)
[ ! "$OUTPUT" ] || args+=(--backend "$OUTPUT")
[ ! "$DEVICE" ] || args+=(--device "$DEVICE")
args+=("$@")
94 changes: 84 additions & 10 deletions context/runtime/boot/mdns.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/usr/bin/env bash
set -o errexit -o errtrace -o functrace -o nounset -o pipefail

_mdns_records=()
readonly _default_mod_mdns_configuration_path="$XDG_CONFIG_DIRS/goello/main.json"
_internal_mod_mdns_records=()

mdns::records::add(){
local type="$1"
local host="$2"
local name="${3:-$host}"
local port="${4:-9}"
local text="${5:-[]}"
_mdns_records+=("$(printf '{"Type": "%s", "Host": "%s", "Name": "%s", "Port": %s, "Text": %s}' "$type" "$host" "$name" "$port" "$text")")
local text="${5:-[\"\"]}" # XXX Goello bug - if [] the announce is not visible
_internal_mod_mdns_records+=("$(printf '{"Type": "%s", "Host": "%s", "Name": "%s", "Port": %s, "Text": %s}' "$type" "$host" "$name" "$port" "$text")")
}

mdns::records::broadcast(){
local IFS=","
goello-server-ng -json "[${_mdns_records[*]}]"
mdns::records::load(){
local file="$1"
local records=""
while read line -r; do
records+="$line"
done < "$file"
records="${records%]*}"
records="${records#*[}"
_internal_mod_mdns_records+=("$records")
}

mdns::records::resolve(){
@@ -28,8 +35,75 @@ mdns::records::resolve(){
printf "%s %s" "$server" "$port"
}

mdns::resolver::start(){
helpers::dir::writable "$XDG_STATE_HOME/avahi-daemon" create
rm -f /run/avahi-daemon/pid
avahi-daemon -f /config/avahi/main.conf --daemonize --no-drop-root --no-chroot --debug
mdns::start::broadcaster(){
[ ! -e "$_default_mod_mdns_configuration_path" ] || mdns::records::load "$_default_mod_mdns_configuration_path"
local IFS=","
goello-server-ng -json "[${_internal_mod_mdns_records[*]}]"
}

mdns::start::avahi(){
# Current issues with Avahi:
# - no way to change /run/avahi-daemon to another location - symlink works though
# - daemonization writing to syslog is a problem
# - avahi insists that /run/avahi-daemon must belong to avahi:avahi
# which is absolutely ridiculous - https://github.com/lathiat/avahi/blob/778fadb71cb923eee74f3f1967db88b8c2586830/avahi-daemon/main.c#L1434
# Some variant of it: https://github.com/lathiat/avahi/issues/349
# - project is half-dead: https://github.com/lathiat/avahi/issues/388

local args=()
local avahisocket="$XDG_STATE_HOME/avahi-daemon/socket"

# Make sure we can write it
helpers::dir::writable "$(dirname "$avahisocket")" true

# Cleanup leftovers on container restart
rm -f "$(dirname "$avahisocket")/pid"

[ "$(printf "%s" "$LOG_LEVEL" | tr '[:upper:]' '[:lower:]')" != "debug" ] || args+=(--debug)

# -D/--daemonize implies -s/--syslog that we do not want, so, just background it
avahi-daemon -f /config/avahi/main.conf --no-drop-root --no-chroot "${args[@]}" &

local tries=1
# Wait until the socket is there
until [ -e "$avahisocket" ]; do
sleep 1s
tries=$(( tries + 1))
[ $tries -lt 10 ] || {
printf >&2 "Failed starting avahi in a reasonable time. Something is quite wrong\n"
return 1
}
done
}

mdns::start::dbus(){
# https://linux.die.net/man/1/dbus-daemon-1
# https://man7.org/linux/man-pages/man3/sd_bus_default.3.html
# https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html

# $XDG_STATE_HOME=/tmp/state
# Configuration file also has that ^ hardcoded, so, cannot use the variable...

local dbussocket=/tmp/state/dbus/system_bus_socket

# Ensure directory exists
helpers::dir::writable "$(dirname "$dbussocket")" create

# Point it there for other systems
export DBUS_SYSTEM_BUS_ADDRESS=unix:path="$dbussocket"
export DBUS_SESSION_BUS_ADDRESS=unix:path="$dbussocket"

# Start it, without a PID file
dbus-daemon --nopidfile --config-file /config/dbus/main.conf

local tries=1
# Wait until the socket is there
until [ -e "$dbussocket" ]; do
sleep 1s
tries=$(( tries + 1))
[ $tries -lt 10 ] || {
printf >&2 "Failed starting dbus in a reasonable time. Something is quite wrong\n"
return 1
}
done
}
6 changes: 6 additions & 0 deletions context/runtime/boot/onevent.sh
Original file line number Diff line number Diff line change
@@ -23,6 +23,12 @@ get::url(){

display(){
local img="$1"
local prior
prior="$(pidof fbi || true)"
# shellcheck disable=SC2086
[ "$prior" == "" ] || kill -s TERM $prior || true

printf "Done cleanup. Starting another cover."
# Should be smarter and verify permissions on the ttys or bail out
fbi -a -noverbose -norandom -T 2 -once "$img"
}
1 change: 1 addition & 0 deletions cue.mod/pkg/duponey.cloud/buildkit/buildctl/buildctl.cue
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ import (

["--local", "dockerfile=\(dockerfile)"] +
["--frontend", frontend] +
["--trace", "buildctl.trace.json"] +
["--opt", "filename=\(filename)"] +

["--local", "context=\(context)"] +
2 changes: 1 addition & 1 deletion hack/helpers/start-buildkit.sh
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ set -o errexit -o errtrace -o functrace -o nounset -o pipefail
export SUITE=bullseye
export DATE=2021-08-01

readonly IMAGE_BLDKT="${IMAGE_BLDKT:-index.docker.io/dubodubonduponey/buildkit:$SUITE-$DATE}"
readonly IMAGE_BLDKT="${IMAGE_BLDKT:-docker.io/dubodubonduponey/buildkit:$SUITE-$DATE}"

setup::buildkit() {
[ "$(docker container inspect -f '{{.State.Running}}' dbdbdp-buildkit 2>/dev/null)" == "true" ] || {
2 changes: 1 addition & 1 deletion hack/lint.sh
Original file line number Diff line number Diff line change
@@ -24,4 +24,4 @@ if ! hadolint "${hadolint_ignore[@]}" "$root"/*Dockerfile*; then
exit 1
fi

find "$root" -iname "*.sh" -not -path "*debuerreotype*" -exec shellcheck {} \;
find "$root" -iname "*.sh" -not -path "*debuerreotype*" -not -path "*cache*" -exec shellcheck {} \;
14 changes: 7 additions & 7 deletions hack/recipe.cue
Original file line number Diff line number Diff line change
@@ -12,19 +12,19 @@ cakes: {
recipe: {
input: {
from: {
registry: * "index.docker.io/dubodubonduponey" | string
registry: * "docker.io/dubodubonduponey" | string
}
}

process: {
platforms: types.#Platforms | * [
types.#Platforms.#AMD64,
types.#Platforms.#ARM64,
types.#Platforms.#I386,
types.#Platforms.#V7,
types.#Platforms.#V6,
types.#Platforms.#S390X,
types.#Platforms.#PPC64LE,
// types.#Platforms.#I386,
// types.#Platforms.#V6,
// types.#Platforms.#S390X,
// types.#Platforms.#PPC64LE,
]
}

@@ -44,8 +44,8 @@ cakes: {
}

injectors: {
suite: * "bullseye" | =~ "^(?:jessie|stretch|buster|bullseye|sid)$" @tag(suite, type=string)
date: * "2022-04-01" | =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" @tag(date, type=string)
suite: * "bullseye" | =~ "^(?:bullseye|bookworm|trixie|sid)$" @tag(suite, type=string)
date: * "2022-12-01" | =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" @tag(date, type=string)
platforms: string @tag(platforms, type=string)
registry: * "registry.local" | string @tag(registry, type=string)
}
Loading