From f624676d85196e4438f6b2ac1f7eb243fa0a181a Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Thu, 21 Dec 2023 17:44:50 -0500 Subject: [PATCH] [add] docker build --- Dockerfile | 32 ++++++++++++++++++++++ Makefile | 8 ++++++ README.md | 4 +++ docker-root/etc/cont-init.d/10-fix_folders | 30 ++++++++++++++++++++ docker-root/etc/cont-init.d/15-checks | 9 ++++++ docker-root/etc/services.d/deemix/run | 26 ++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-root/etc/cont-init.d/10-fix_folders create mode 100644 docker-root/etc/cont-init.d/15-checks create mode 100644 docker-root/etc/services.d/deemix/run diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7af4ad1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM --platform=$TARGETPLATFORM docker.io/library/node:16-alpine as deemix + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +RUN echo "Building for TARGETPLATFORM=$TARGETPLATFORM | BUILDPLATFORM=$BUILDPLATFORM" +RUN apk add --no-cache git jq python3 make gcc musl-dev g++ && \ + rm -rf /var/lib/apt/lists/* +COPY . /app +WORKDIR app +RUN case "$TARGETPLATFORM" in \ + "linux/amd64") \ + jq '.pkg.targets = ["node16-alpine-x64"]' ./server/package.json > tmp-json ;; \ + "linux/arm64") \ + jq '.pkg.targets = ["node16-alpine-arm64"]' ./server/package.json > tmp-json ;; \ + "linux/arm64/v8") \ + jq '.pkg.targets = ["node16-alpine-arm64"]' ./server/package.json > tmp-json ;; \ + *) \ + echo "Platform $TARGETPLATFORM not supported" && exit 1 ;; \ + esac && \ + mv tmp-json /app/server/package.json +RUN yarn install-all +RUN yarn dist-server +RUN mv /app/dist/deemix-server /deemix-server + +FROM lsiobase/alpine:3.19 + +COPY --from=deemix /deemix-server /deemix-server +COPY docker-root/ / + +EXPOSE 6595 +ENTRYPOINT [ "/init" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..03de647 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +docker_build_local: + docker build -t deemixer:latest . + +docker_build_release_latest: + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + -t gitea.va.reichard.io/evan/deemixer:latest \ + --push . diff --git a/README.md b/README.md index 9b09d36..311b64e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ This is forked from [deemix-webui](https://gitlab.com/RemixDev/deemix-webui) and The submodule reference was removed and consolidated into this single repo. Git history was maintained. +## Building Docker Image + + make docker_build_local + ## Running from source You need to use nodejs 16.x, using `yarn` is recommended. diff --git a/docker-root/etc/cont-init.d/10-fix_folders b/docker-root/etc/cont-init.d/10-fix_folders new file mode 100644 index 0000000..2abc419 --- /dev/null +++ b/docker-root/etc/cont-init.d/10-fix_folders @@ -0,0 +1,30 @@ +#!/usr/bin/with-contenv bash + +# test write access to download and config folder and test internet connectivity +printf '[cont-init.d] Fixing Folder Permissions - Config Folder\n' + +chown -R abc:abc /config + +printf '[cont-init.d] Fixing Folder Permissions - Temp Folder\n' + +mkdir /tmp/deemix-imgs/ +chown -R abc:abc /tmp/deemix-imgs/ + +# find all folders in the download folder and own them to the container user. This will not change files but should run quicker on big collections. +if [ ! -z ${DISABLE_OWNERSHIP_CHECK} ]; then + printf '[cont-init.d] Download Folder Ownership Check disabled by Environment Variable\n' +else + printf '[cont-init.d] Fixing Folder Permissions - Downloads Folder\n' + find /downloads -type d -exec chown abc:abc {} + +fi + + +# add executability to server +chmod +x /deemix-server + +# Fix misconfigured download locations. The container's download map is always /downloads. +if [ -f "/config/config.json" ]; then + jq '.downloadLocation = "/downloads"' /config/config.json > tmp.$$.json && mv tmp.$$.json /config/config.json + chown abc:abc /config/config.json +fi + diff --git a/docker-root/etc/cont-init.d/15-checks b/docker-root/etc/cont-init.d/15-checks new file mode 100644 index 0000000..be1d928 --- /dev/null +++ b/docker-root/etc/cont-init.d/15-checks @@ -0,0 +1,9 @@ +#!/usr/bin/with-contenv bash + +# test write access to download and config folder and test internet connectivity +printf '[cont-init.d] Testing Access\n' && \ +printf '%-50s %2s %-5s \n' "[cont-init.d] Container Builddate" ":" "$BUILDDATEENV" && \ +if [ -w "/downloads" ]; then printf '%-50s %2s %-5s \n' "[cont-init.d] Download Folder Write Access" ":" "Success"; else printf '%-50s %2s %-5s \n' "[cont-init.d] Download Folder Write Access" ":" "Failure"; fi && \ +if [ -w "/config" ]; then printf '%-50s %2s %-5s \n' "[cont-init.d] Config Folder Write Access" ":" "Success"; else printf '%-50s %2s %-5s \n' "[cont-init.d] Config Folder Write Access" ":" "Failure"; fi && \ +until curl --fail -sf www.deezer.com; do printf '%-50s %2s %-5s \n' "[cont-init.d] Internet Access" ":" "Failure. Trying again in 5 seconds"; sleep 5; done +printf '%-50s %2s %-5s \n' "[cont-init.d] Internet Access" ":" "Success" diff --git a/docker-root/etc/services.d/deemix/run b/docker-root/etc/services.d/deemix/run new file mode 100644 index 0000000..03d69f6 --- /dev/null +++ b/docker-root/etc/services.d/deemix/run @@ -0,0 +1,26 @@ +#!/usr/bin/with-contenv bash + +UMASK_SET=${UMASK_SET:-022} +umask "$UMASK_SET" + +cd / + +# Check if an alternative port was defined, set it to it or default +if [ ! -z ${INTPORT} ]; then + port=$INTPORT +else + port=6595 +fi + +# Check if the ARL environment var is set to anything. This enables legacy behavior +if [ ! -z ${ARL} ]; then + export DEEMIX_SINGLE_USER=true +fi + +export DEEMIX_DATA_DIR=/config/ +export DEEMIX_MUSIC_DIR=/downloads/ +export DEEMIX_SERVER_PORT=$port +export DEEMIX_HOST=0.0.0.0 + +echo "[services.d] Starting Deemixer" +s6-setuidgid abc /deemix-server