Skip to content

Commit

Permalink
feat(readarr)!: official env support added
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Buhl <devin@buhl.casa>
  • Loading branch information
onedr0p committed Jun 7, 2024
1 parent fb003cd commit 81b2202
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 123 deletions.
25 changes: 4 additions & 21 deletions apps/readarr/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
ARG VERSION
FROM docker.io/library/golang:1.22-alpine as envsubst
ARG VERSION
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT=""
ARG TARGETPLATFORM
ENV CGO_ENABLED=0 \
GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
GOARM=${TARGETVARIANT}
RUN go install -ldflags="-s -w" github.com/drone/envsubst/cmd/envsubst@latest

FROM docker.io/library/alpine:3.20

ARG TARGETPLATFORM
ARG VERSION
ARG CHANNEL

ENV \
READARR__INSTANCE_NAME="Readarr" \
READARR__BRANCH="${CHANNEL}" \
READARR__PORT="8787" \
READARR__ANALYTICS_ENABLED="False"
COMPlus_EnableDiagnostics="0" \
READARR__UPDATE__BRANCH="${CHANNEL}"

ENV UMASK="0002" \
TZ="Etc/UTC"
Expand All @@ -42,7 +28,6 @@ RUN \
nano \
sqlite-libs \
tzdata \
xmlstarlet \
&& \
case "${TARGETPLATFORM}" in \
'linux/amd64') export ARCH='x64' ;; \
Expand All @@ -51,19 +36,17 @@ RUN \
&& \
mkdir -p /app/bin \
&& \
curl -fsSL "https://readarr.servarr.com/v1/update/${READARR__BRANCH}/updatefile?version=${VERSION}&os=linuxmusl&runtime=netcore&arch=${ARCH}" \
curl -fsSL "https://readarr.servarr.com/v1/update/${READARR__UPDATE__BRANCH}/updatefile?version=${VERSION}&os=linuxmusl&runtime=netcore&arch=${ARCH}" \
| tar xzf - -C /app/bin --strip-components=1 \
&& \
rm -rf /app/bin/Readarr.Update \
&& \
printf "UpdateMethod=docker\nBranch=%s\nPackageVersion=%s\nPackageAuthor=[onedr0p](https://github.com/onedr0p)\n" "${READARR__BRANCH}" "${VERSION}" > /app/package_info \
printf "UpdateMethod=docker\nBranch=%s\nPackageVersion=%s\nPackageAuthor=[onedr0p](https://github.com/onedr0p)\n" "${READARR__UPDATE__BRANCH}" "${VERSION}" > /app/package_info \
&& chown -R root:root /app \
&& chmod -R 755 /app \
&& rm -rf /tmp/*

COPY ./apps/readarr/config.xml.tmpl /app/config.xml.tmpl
COPY ./apps/readarr/entrypoint.sh /entrypoint.sh
COPY --from=envsubst /go/bin/envsubst /usr/local/bin/envsubst

USER nobody:nogroup
WORKDIR /config
Expand Down
24 changes: 0 additions & 24 deletions apps/readarr/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions apps/readarr/ci/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ http:
http://localhost:8787:
status: 200
timeout: 5000
file:
/usr/local/bin/envsubst:
exists: true
26 changes: 0 additions & 26 deletions apps/readarr/config.xml.tmpl

This file was deleted.

49 changes: 0 additions & 49 deletions apps/readarr/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,5 @@
#!/usr/bin/env bash

# Discover existing configuration settings for backwards compatibility
if [[ -f /config/config.xml ]]; then
current_log_level="$(xmlstarlet sel -t -v "//LogLevel" -nl /config/config.xml)"
current_url_base="$(xmlstarlet sel -t -v "//UrlBase" -nl /config/config.xml)"
current_branch="$(xmlstarlet sel -t -v "//Branch" -nl /config/config.xml)"
current_analytics_enabled="$(xmlstarlet sel -t -v "//AnalyticsEnabled" -nl /config/config.xml)"
current_api_key="$(xmlstarlet sel -t -v "//ApiKey" -nl /config/config.xml)"
current_authentication_method="$(xmlstarlet sel -t -v "//AuthenticationMethod" -nl /config/config.xml)"
current_authentication_required="$(xmlstarlet sel -t -v "//AuthenticationRequired" -nl /config/config.xml)"
current_instance_name="$(xmlstarlet sel -t -v "//InstanceName" -nl /config/config.xml)"
current_postgres_user="$(xmlstarlet sel -t -v "//PostgresUser" -nl /config/config.xml)"
current_postgres_password="$(xmlstarlet sel -t -v "//PostgresPassword" -nl /config/config.xml)"
current_postgres_port="$(xmlstarlet sel -t -v "//PostgresPort" -nl /config/config.xml)"
current_postgres_host="$(xmlstarlet sel -t -v "//PostgresHost" -nl /config/config.xml)"
current_postgres_main_db="$(xmlstarlet sel -t -v "//PostgresMainDb" -nl /config/config.xml)"
current_postgres_log_db="$(xmlstarlet sel -t -v "//PostgresLogDb" -nl /config/config.xml)"
current_postgres_cache_db="$(xmlstarlet sel -t -v "//PostgresCacheDb" -nl /config/config.xml)"
current_theme="$(xmlstarlet sel -t -v "//Theme" -nl /config/config.xml)"
fi

# Update config.xml with environment variables
envsubst < /app/config.xml.tmpl > /config/config.xml

# Override configuation values from existing config.xml if there are no READARR__ variables set
[[ -z "${READARR__LOG_LEVEL}" && -n "${current_log_level}" ]] && xmlstarlet edit --inplace --update //LogLevel -v "${current_log_level}" /config/config.xml
[[ -z "${READARR__URL_BASE}" && -n "${current_url_base}" ]] && xmlstarlet edit --inplace --update //UrlBase -v "${current_url_base}" /config/config.xml
[[ -z "${READARR__BRANCH}" && -n "${current_branch}" ]] && xmlstarlet edit --inplace --update //Branch -v "${current_branch}" /config/config.xml
[[ -z "${READARR__ANALYTICS_ENABLED}" && -n "${current_analytics_enabled}" ]] && xmlstarlet edit --inplace --update //AnalyticsEnabled -v "${current_analytics_enabled}" /config/config.xml
[[ -z "${READARR__API_KEY}" && -n "${current_api_key}" ]] && xmlstarlet edit --inplace --update //ApiKey -v "${current_api_key}" /config/config.xml
[[ -z "${READARR__AUTHENTICATION_METHOD}" && -n "${current_authentication_method}" ]] && xmlstarlet edit --inplace --update //AuthenticationMethod -v "${current_authentication_method}" /config/config.xml
[[ -z "${READARR__AUTHENTICATION_REQUIRED}" && -n "${current_authentication_required}" ]] && xmlstarlet edit --inplace --update //AuthenticationRequired -v "${current_authentication_required}" /config/config.xml
[[ -z "${READARR__INSTANCE_NAME}" && -n "${current_instance_name}" ]] && xmlstarlet edit --inplace --update //InstanceName -v "${current_instance_name}" /config/config.xml
[[ -z "${READARR__POSTGRES_USER}" && -n "${current_postgres_user}" ]] && xmlstarlet edit --inplace --update //PostgresUser -v "${current_postgres_user}" /config/config.xml
[[ -z "${READARR__POSTGRES_PASSWORD}" && -n "${current_postgres_password}" ]] && xmlstarlet edit --inplace --update //PostgresPassword -v "${current_postgres_password}" /config/config.xml
[[ -z "${READARR__POSTGRES_PORT}" && -n "${current_postgres_port}" ]] && xmlstarlet edit --inplace --update //PostgresPort -v "${current_postgres_port}" /config/config.xml
[[ -z "${READARR__POSTGRES_HOST}" && -n "${current_postgres_host}" ]] && xmlstarlet edit --inplace --update //PostgresHost -v "${current_postgres_host}" /config/config.xml
[[ -z "${READARR__POSTGRES_MAIN_DB}" && -n "${current_postgres_main_db}" ]] && xmlstarlet edit --inplace --update //PostgresMainDb -v "${current_postgres_main_db}" /config/config.xml
[[ -z "${READARR__POSTGRES_LOG_DB}" && -n "${current_postgres_log_db}" ]] && xmlstarlet edit --inplace --update //PostgresLogDb -v "${current_postgres_log_db}" /config/config.xml
[[ -z "${READARR__POSTGRES_CACHE_DB}" && -n "${current_postgres_cache_db}" ]] && xmlstarlet edit --inplace --update //PostgresCacheDb -v "${current_postgres_cache_db}" /config/config.xml
[[ -z "${READARR__THEME}" && -n "${current_theme}" ]] && xmlstarlet edit --inplace --update //Theme -v "${current_theme}" /config/config.xml

# BindAddress, LaunchBrowser, Port, EnableSsl, SslPort, SslCertPath, SslCertPassword, UpdateMechanism
# have been omited because their configuration is not really needed in a container environment

if [[ "${READARR__LOG_LEVEL}" == "debug" || "${current_log_level}" == "debug" ]]; then
echo "Starting with the following configuration..."
xmlstarlet format --omit-decl /config/config.xml
fi

#shellcheck disable=SC2086
exec \
/app/bin/Readarr \
Expand Down

0 comments on commit 81b2202

Please sign in to comment.