From 1526a4e0848e787c0854767f67fad3e791ed0a51 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 10 Feb 2023 23:02:01 +0000 Subject: [PATCH] add docker packaging --- .gitignore | 1 + README.md | 1 + bin/mtag/install-deps.sh | 1 + docs/devnotes.md | 5 +++ scripts/docker/Dockerfile.ac | 14 ++++++ scripts/docker/Dockerfile.dj | 29 ++++++++++++ scripts/docker/Dockerfile.im | 13 ++++++ scripts/docker/Dockerfile.iv | 17 +++++++ scripts/docker/Dockerfile.min | 12 +++++ scripts/docker/Dockerfile.min.pip | 12 +++++ scripts/docker/Makefile | 55 +++++++++++++++++++++++ scripts/docker/README.md | 74 +++++++++++++++++++++++++++++++ 12 files changed, 234 insertions(+) create mode 100644 scripts/docker/Dockerfile.ac create mode 100644 scripts/docker/Dockerfile.dj create mode 100644 scripts/docker/Dockerfile.im create mode 100644 scripts/docker/Dockerfile.iv create mode 100644 scripts/docker/Dockerfile.min create mode 100644 scripts/docker/Dockerfile.min.pip create mode 100644 scripts/docker/Makefile create mode 100644 scripts/docker/README.md diff --git a/.gitignore b/.gitignore index de34ef54..18ba10c8 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ copyparty.egg-info/ copyparty/res/COPYING.txt copyparty/web/deps/ srv/ +scripts/docker/i/ contrib/package/arch/pkg/ contrib/package/arch/src/ diff --git a/README.md b/README.md index 89da051e..fb27e0cf 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ download **[copyparty-sfx.py](https://github.com/9001/copyparty/releases/latest/ * or install through pypi (python3 only): `python3 -m pip install --user -U copyparty` * or if you cannot install python, you can use [copyparty.exe](#copypartyexe) instead +* or if you prefer to [use docker](./scripts/docker/) you can do that too 🐋 running the sfx without arguments (for example doubleclicking it on Windows) will give everyone read/write access to the current folder; you may want [accounts and volumes](#accounts-and-volumes) diff --git a/bin/mtag/install-deps.sh b/bin/mtag/install-deps.sh index 4d8ca26a..437392ef 100755 --- a/bin/mtag/install-deps.sh +++ b/bin/mtag/install-deps.sh @@ -57,6 +57,7 @@ hash -r command -v python3 && pybin=python3 || pybin=python } +$pybin -c 'import numpy' || $pybin -m pip install --user numpy diff --git a/docs/devnotes.md b/docs/devnotes.md index f56fda86..798596a2 100644 --- a/docs/devnotes.md +++ b/docs/devnotes.md @@ -232,6 +232,11 @@ rm x.py cp -R /tmp/pe-copyparty.$(id -u)/copyparty/web/deps copyparty/web/ ``` +or you could build the web-dependencies from source instead (NB: does not include prismjs, need to grab that manually): +```sh +make -C scripts/deps-docker +``` + then build the sfx using any of the following examples: ```sh diff --git a/scripts/docker/Dockerfile.ac b/scripts/docker/Dockerfile.ac new file mode 100644 index 00000000..c200cd76 --- /dev/null +++ b/scripts/docker/Dockerfile.ac @@ -0,0 +1,14 @@ +FROM alpine:latest +WORKDIR /z + +RUN apk --no-cache add \ + wget \ + py3-pillow \ + ffmpeg \ + && mkdir /cfg /w \ + && chmod 777 /cfg /w \ + && echo % /cfg > initcfg + +COPY i/dist/copyparty-sfx.py ./ +WORKDIR /w +ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] diff --git a/scripts/docker/Dockerfile.dj b/scripts/docker/Dockerfile.dj new file mode 100644 index 00000000..2a0bb998 --- /dev/null +++ b/scripts/docker/Dockerfile.dj @@ -0,0 +1,29 @@ +FROM alpine:latest +WORKDIR /z + +COPY i/bin/mtag/install-deps.sh ./ +COPY i/bin/mtag/audio-bpm.py /mtag/ +COPY i/bin/mtag/audio-key.py /mtag/ +RUN apk add -U \ + wget \ + py3-pillow py3-pip \ + ffmpeg \ + vips-jxl vips-heif vips-poppler vips-magick \ + py3-numpy fftw libsndfile \ + && python3 -m pip install pyvips \ + && apk --no-cache add -t .bd \ + bash wget gcc g++ make cmake patchelf \ + python3-dev ffmpeg-dev fftw-dev libsndfile-dev \ + py3-wheel py3-numpy-dev \ + && bash install-deps.sh \ + && apk del py3-pip .bd \ + && rm -rf /var/cache/apk/* \ + && chmod 777 /root \ + && ln -s /root/vamp /root/.local / \ + && mkdir /cfg /w \ + && chmod 777 /cfg /w \ + && echo % /cfg > initcfg + +COPY i/dist/copyparty-sfx.py ./ +WORKDIR /w +ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] diff --git a/scripts/docker/Dockerfile.im b/scripts/docker/Dockerfile.im new file mode 100644 index 00000000..2cfc393f --- /dev/null +++ b/scripts/docker/Dockerfile.im @@ -0,0 +1,13 @@ +FROM alpine:latest +WORKDIR /z + +RUN apk --no-cache add \ + wget \ + py3-pillow \ + && mkdir /cfg /w \ + && chmod 777 /cfg /w \ + && echo % /cfg > initcfg + +COPY i/dist/copyparty-sfx.py ./ +WORKDIR /w +ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] diff --git a/scripts/docker/Dockerfile.iv b/scripts/docker/Dockerfile.iv new file mode 100644 index 00000000..e146fbe1 --- /dev/null +++ b/scripts/docker/Dockerfile.iv @@ -0,0 +1,17 @@ +FROM alpine:latest +WORKDIR /z + +RUN apk --no-cache add \ + wget \ + py3-pillow py3-pip \ + ffmpeg \ + vips-jxl vips-heif vips-poppler vips-magick \ + && python3 -m pip install pyvips \ + && apk del py3-pip \ + && mkdir /cfg /w \ + && chmod 777 /cfg /w \ + && echo % /cfg > initcfg + +COPY i/dist/copyparty-sfx.py ./ +WORKDIR /w +ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] diff --git a/scripts/docker/Dockerfile.min b/scripts/docker/Dockerfile.min new file mode 100644 index 00000000..81e7d885 --- /dev/null +++ b/scripts/docker/Dockerfile.min @@ -0,0 +1,12 @@ +FROM alpine:latest +WORKDIR /z + +RUN apk --no-cache add \ + python3 \ + && mkdir /cfg /w \ + && chmod 777 /cfg /w \ + && echo % /cfg > initcfg + +COPY i/dist/copyparty-sfx.py ./ +WORKDIR /w +ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] diff --git a/scripts/docker/Dockerfile.min.pip b/scripts/docker/Dockerfile.min.pip new file mode 100644 index 00000000..48f6e87a --- /dev/null +++ b/scripts/docker/Dockerfile.min.pip @@ -0,0 +1,12 @@ +FROM alpine:latest +WORKDIR /z + +RUN apk --no-cache add python3 py3-pip \ + && python3 -m pip install copyparty \ + && apk del py3-pip \ + && mkdir /cfg /w \ + && chmod 777 /cfg /w \ + && echo % /cfg > initcfg + +WORKDIR /w +ENTRYPOINT ["python3", "-m", "copyparty", "-c", "/z/initcfg"] diff --git a/scripts/docker/Makefile b/scripts/docker/Makefile new file mode 100644 index 00000000..5e16b9b3 --- /dev/null +++ b/scripts/docker/Makefile @@ -0,0 +1,55 @@ +self := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + +all: + -service docker start + -systemctl start docker + + rm -rf i + mkdir i + tar -cC../.. dist/copyparty-sfx.py bin/mtag | tar -xvCi + + docker build -t copyparty/min:latest -f Dockerfile.min . + echo 'scale=1;'`docker save copyparty/min:latest | pigz -c | wc -c`/1024/1024 | bc + +# docker build -t copyparty/min-pip:latest -f Dockerfile.min.pip . +# echo 'scale=1;'`docker save copyparty/min-pip:latest | pigz -c | wc -c`/1024/1024 | bc + + docker build -t copyparty/im:latest -f Dockerfile.im . + echo 'scale=1;'`docker save copyparty/im:latest | pigz -c | wc -c`/1024/1024 | bc + + docker build -t copyparty/iv:latest -f Dockerfile.iv . + echo 'scale=1;'`docker save copyparty/iv:latest | pigz -c | wc -c`/1024/1024 | bc + + docker build -t copyparty/ac:latest -f Dockerfile.ac . + echo 'scale=1;'`docker save copyparty/ac:latest | pigz -c | wc -c`/1024/1024 | bc + + docker build -t copyparty/dj:latest -f Dockerfile.dj . + echo 'scale=1;'`docker save copyparty/dj:latest | pigz -c | wc -c`/1024/1024 | bc + + docker image ls + +push: + docker push copyparty/min + docker push copyparty/im + docker push copyparty/iv + docker push copyparty/ac + docker push copyparty/dj + +clean: + -docker kill `docker ps -q` + -docker rm `docker ps -qa` + -docker rmi `docker images -a | awk '/^/{print$$3}'` + +hclean: + -docker kill `docker ps -q` + -docker rm `docker ps -qa` + -docker rmi `docker images -a | awk '!/^alpine/&&NR>1{print$$3}'` + +purge: + -docker kill `docker ps -q` + -docker rm `docker ps -qa` + -docker rmi `docker images -qa` + +sh: + @printf "\n\033[1;31mopening a shell in the most recently created docker image\033[0m\n" + docker run --rm -it --entrypoint /bin/ash `docker images -aq | head -n 1` diff --git a/scripts/docker/README.md b/scripts/docker/README.md new file mode 100644 index 00000000..e64e85db --- /dev/null +++ b/scripts/docker/README.md @@ -0,0 +1,74 @@ +copyparty is availabe in these repos: +* https://hub.docker.com/r/copyparty +* https://github.com/9001?tab=packages&repo_name=copyparty + + +# getting started + +run this command to grab the latest copyparty image and start it: +```bash +docker run --rm -it -u 1000 -p 3923:3923 -v /mnt/nas:/w -v $PWD/cfgdir:/cfg copyparty/ac +``` + +* `/w` is the path inside the container that gets shared by default, so mount one or more folders to share below there +* `/cfg` is an optional folder with zero or more config files (*.conf) to load +* `copyparty/ac` is the recommended [image edition](#editions) +* you can download the image from github instead by replacing `copyparty/ac` with TODO + +i'm unfamiliar with docker-compose and alternatives so let me know if this section could be better 🙏 + + +## configuration + +the container has the same default config as the sfx and the pypi module, meaning it will listen on port 3923 and share the "current folder" (`/w` inside the container) as read-write for anyone + +the recommended way to configure copyparty inside a container is to mount a folder which has one or more [config files](https://github.com/9001/copyparty/blob/hovudstraum/docs/example.conf) inside; `-v /your/config/folder:/cfg` + +* but you can also provide arguments to the docker command if you prefer that +* config files must be named `something.conf` to get picked up + + +## editions + +with image size after installation and when gzipped + +* `min` (57 MiB, 20 gz) is just copyparty itself +* `im` (69 MiB, 24 gz) can create thumbnails using pillow (pics only) +* `ac` (163 MiB, 56 gz) is `im` plus ffmpeg for video/audio thumbnails + audio transcoding +* `iv` (211 MiB, 73 gz) is `ac` plus vips for faster heif / avic / jxl thumbnails +* `dj` (309 MiB, 104 gz) is `iv` plus beatroot/keyfinder to detect musical keys and bpm + +`ac` is recommended since the additional features available in `iv` and `dj` are rarely useful + + +## detecting bpm and musical key + +the `dj` edition comes with `keyfinder` and `beatroot` which can be used to detect music bpm and musical keys + +enable them globally in a config file: +```yaml +[global] +e2dsa, e2ts # enable filesystem indexing and multimedia indexing +mtp: .bpm=f,t30,/mtag/audio-bpm.py # should take ~10sec +mtp: key=f,t190,/mtag/audio-key.py # should take ~50sec +``` + +or enable them for just one volume, +```yaml +[/music] # share name / URL + music # filesystem path inside the docker volume `/w` + flags: + e2dsa, e2ts + mtp: .bpm=f,t30,/mtag/audio-bpm.py + mtp: key=f,t190,/mtag/audio-key.py +``` + +or using commandline arguments, +``` +-e2dsa -e2ts -mtp .bpm=f,t30,/mtag/audio-bpm.py -mtp key=f,t190,/mtag/audio-key.py +``` + + +# build the images yourself + +put `copyparty-sfx.py` into `../dist/` (or [build that from scratch](../docs/devnotes.md#just-the-sfx) too) then run `make`