From c56a3b8fdf3dfbf5065a387953728655af81440c Mon Sep 17 00:00:00 2001 From: Jasper Date: Mon, 19 Dec 2022 20:51:51 -0800 Subject: [PATCH] update docker image --- Dockerfile | 58 +++++++++++++++++--------- root/etc/cont-init.d/30-config | 13 ++++++ root/etc/services.d/audiobookshelf/run | 47 +++++++++++++++++++++ 3 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 root/etc/cont-init.d/30-config create mode 100644 root/etc/services.d/audiobookshelf/run diff --git a/Dockerfile b/Dockerfile index db7642bb9..b8c26a906 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,52 @@ -### STAGE 0: Build client ### -FROM node:16-alpine AS build +### STAGE 0: Get deps ### +FROM --platform=${TARGETPLATFORM} node:16-alpine AS deps + WORKDIR /client + +COPY /client/package* ./ + +RUN npm ci + +### STAGE 1: Build client ### +FROM --platform=${TARGETPLATFORM} node:16-alpine AS build + +WORKDIR /client + COPY /client /client -RUN npm ci && npm cache clean --force + +COPY --from=deps /client/node_modules /client/node_modules + RUN npm run generate -### STAGE 1: Build server ### -FROM sandreas/tone:v0.1.2 AS tone -FROM node:16-alpine +### STAGE 2: Build server ### +FROM --platform=${TARGETPLATFORM} ghcr.io/linuxserver/baseimage-alpine:3.15 AS runner -ENV NODE_ENV=production -RUN apk update && \ - apk add --no-cache --update \ - curl \ - tzdata \ - ffmpeg +ENV NODE_ENV=production \ + TZ="Etc/UTC" -COPY --from=tone /usr/local/bin/tone /usr/local/bin/ -COPY --from=build /client/dist /client/dist -COPY index.js package* / -COPY server server +COPY --from=sandreas/tone:v0.1.2 /usr/local/bin/tone /usr/local/bin/ +COPY --from=build /client/dist /app/audiobookshelf/client/dist -RUN npm ci --only=production +COPY index.js package* readme.md LICENSE Dockerfile /app/audiobookshelf/ +COPY server /app/audiobookshelf/server + +RUN \ + apk add --upgrade --no-cache \ + ffmpeg \ + nodejs \ + npm && \ + cd app/audiobookshelf && \ + npm ci --omit-dev -EXPOSE 80 HEALTHCHECK \ --interval=30s \ --timeout=3s \ --start-period=10s \ CMD curl -f http://127.0.0.1/healthcheck || exit 1 -CMD ["npm", "start"] + +# copy local files +COPY root/ / + +# ports and volumes +EXPOSE 80 +VOLUME /config /metadata diff --git a/root/etc/cont-init.d/30-config b/root/etc/cont-init.d/30-config new file mode 100644 index 000000000..06b8af3a0 --- /dev/null +++ b/root/etc/cont-init.d/30-config @@ -0,0 +1,13 @@ +#!/usr/bin/with-contenv bash + +# make config & metadata folder +mkdir -p \ + /config/ \ + /metadata/ + +# chown config & metadata directories if currently not set to abc +if [[ -d /config ]] && [[ "$(stat -c '%U' /config)" != "abc" ]]; then + chown -R abc:abc /config/ +elif [[ -d /metadata ]] && [[ "$(stat -c '%U' /metadata)" != "abc" ]]; then + chown -R abc:abc /metadata/ +fi diff --git a/root/etc/services.d/audiobookshelf/run b/root/etc/services.d/audiobookshelf/run new file mode 100644 index 000000000..1ae2abc67 --- /dev/null +++ b/root/etc/services.d/audiobookshelf/run @@ -0,0 +1,47 @@ +#!/usr/bin/with-contenv bash + + +## Changing ownership recursively on /config still threw ownership errors for some reason +files=( + "/config/" + "/audiobooks/" + "/podcasts/" + "/metadata/" + "/config/users/njodb.properties" + "/config/libraryItems/njodb.properties" + "/config/sessions/njodb.properties" + "/config/libraries/njodb.properties" + "/config/settings/njodb.properties" + "/config/collections/njodb.properties" + "/config/playlists/njodb.properties" + "/config/authors/njodb.properties" + "/config/series/njodb.properties" + "/config/feeds/njodb.properties" + "/config/libraryItems" + "/config/settings/data" + "/config/users/data" + "/config/authors/data" + "/config/libraries/data" + "/config/settings/tmp" + "/config/users/tmp" + "/config/authors/tmp" + "/config/libraries/tmp" + "/config/settings/cache" + "/config/users/cache" + "/config/authors/cache" + "/config/libraries/cache" +) + +for file in "${files[@]}"; do + if [[ -f "$file" ]] && [[ "$(stat -c '%U' "$file")" != "abc" ]]; then + chown abc:abc "$file" + elif [[ -d "$file" ]] && [[ "$(stat -c '%U' "$file")" != "abc" ]]; then + chown -R abc:abc "$file" + fi +done + + +PORT=${PORT:-80} + +exec \ + s6-setuidgid abc npm --prefix /app/audiobookshelf/ --cache /app/audiobookshelf/ run start --port "${PORT}" \ No newline at end of file