From a80579f63ad79b93b2ed1f6e5ec15f1d87efce75 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 18 Feb 2023 23:04:55 +0000 Subject: [PATCH] build docker for x32 aarch64 armhf ppc64 s390x --- scripts/docker/Dockerfile.ac | 11 ++- scripts/docker/Dockerfile.dj | 11 ++- scripts/docker/Dockerfile.im | 11 ++- scripts/docker/Dockerfile.iv | 11 ++- scripts/docker/Dockerfile.min | 11 ++- scripts/docker/Dockerfile.min.pip | 11 ++- scripts/docker/README.md | 2 +- scripts/docker/devnotes.md | 19 +++++ scripts/docker/make.sh | 121 ++++++++++++++++++++++++++++++ 9 files changed, 171 insertions(+), 37 deletions(-) create mode 100644 scripts/docker/devnotes.md create mode 100755 scripts/docker/make.sh diff --git a/scripts/docker/Dockerfile.ac b/scripts/docker/Dockerfile.ac index 709e486f..4b0e0ea2 100644 --- a/scripts/docker/Dockerfile.ac +++ b/scripts/docker/Dockerfile.ac @@ -1,5 +1,10 @@ FROM alpine:latest WORKDIR /z +LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ + org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="copyparty-ac" \ + org.opencontainers.image.description="copyparty with Pillow and FFmpeg (image/audio/video thumbnails, audio transcoding, media tags)" RUN apk --no-cache add \ wget \ @@ -13,9 +18,3 @@ COPY i/dist/copyparty-sfx.py ./ WORKDIR /w EXPOSE 3923 ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] - -LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ - org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ - org.opencontainers.image.licenses="MIT" \ - org.opencontainers.image.title="copyparty-ac" \ - org.opencontainers.image.description="copyparty with Pillow and FFmpeg (image/audio/video thumbnails, audio transcoding, media tags)" diff --git a/scripts/docker/Dockerfile.dj b/scripts/docker/Dockerfile.dj index f10456c8..20397168 100644 --- a/scripts/docker/Dockerfile.dj +++ b/scripts/docker/Dockerfile.dj @@ -1,5 +1,10 @@ FROM alpine:latest WORKDIR /z +LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ + org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="copyparty-dj" \ + org.opencontainers.image.description="copyparty with all optional dependencies, including musical key / bpm detection" COPY i/bin/mtag/install-deps.sh ./ COPY i/bin/mtag/audio-bpm.py /mtag/ @@ -28,9 +33,3 @@ COPY i/dist/copyparty-sfx.py ./ WORKDIR /w EXPOSE 3923 ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] - -LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ - org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ - org.opencontainers.image.licenses="MIT" \ - org.opencontainers.image.title="copyparty-dj" \ - org.opencontainers.image.description="copyparty with all optional dependencies, including musical key / bpm detection" diff --git a/scripts/docker/Dockerfile.im b/scripts/docker/Dockerfile.im index e3e63a67..3dcd7c47 100644 --- a/scripts/docker/Dockerfile.im +++ b/scripts/docker/Dockerfile.im @@ -1,5 +1,10 @@ FROM alpine:latest WORKDIR /z +LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ + org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="copyparty-im" \ + org.opencontainers.image.description="copyparty with Pillow and Mutagen (image thumbnails, media tags)" RUN apk --no-cache add \ wget \ @@ -12,9 +17,3 @@ COPY i/dist/copyparty-sfx.py ./ WORKDIR /w EXPOSE 3923 ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] - -LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ - org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ - org.opencontainers.image.licenses="MIT" \ - org.opencontainers.image.title="copyparty-im" \ - org.opencontainers.image.description="copyparty with Pillow and Mutagen (image thumbnails, media tags)" diff --git a/scripts/docker/Dockerfile.iv b/scripts/docker/Dockerfile.iv index 79d477af..fde5d77b 100644 --- a/scripts/docker/Dockerfile.iv +++ b/scripts/docker/Dockerfile.iv @@ -1,5 +1,10 @@ FROM alpine:latest WORKDIR /z +LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ + org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="copyparty-iv" \ + org.opencontainers.image.description="copyparty with Pillow, FFmpeg, libvips (image/audio/video thumbnails, audio transcoding, media tags)" RUN apk --no-cache add \ wget \ @@ -16,9 +21,3 @@ COPY i/dist/copyparty-sfx.py ./ WORKDIR /w EXPOSE 3923 ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] - -LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ - org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ - org.opencontainers.image.licenses="MIT" \ - org.opencontainers.image.title="copyparty-iv" \ - org.opencontainers.image.description="copyparty with Pillow, FFmpeg, libvips (image/audio/video thumbnails, audio transcoding, media tags)" diff --git a/scripts/docker/Dockerfile.min b/scripts/docker/Dockerfile.min index aaadf083..157a8280 100644 --- a/scripts/docker/Dockerfile.min +++ b/scripts/docker/Dockerfile.min @@ -1,5 +1,10 @@ FROM alpine:latest WORKDIR /z +LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ + org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="copyparty-min" \ + org.opencontainers.image.description="just copyparty, no thumbnails / media tags / audio transcoding" RUN apk --no-cache add \ python3 \ @@ -11,9 +16,3 @@ COPY i/dist/copyparty-sfx.py ./ WORKDIR /w EXPOSE 3923 ENTRYPOINT ["python3", "/z/copyparty-sfx.py", "-c", "/z/initcfg"] - -LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ - org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ - org.opencontainers.image.licenses="MIT" \ - org.opencontainers.image.title="copyparty-min" \ - org.opencontainers.image.description="just copyparty, no thumbnails / media tags / audio transcoding" diff --git a/scripts/docker/Dockerfile.min.pip b/scripts/docker/Dockerfile.min.pip index 9d01d40c..8bedd6d6 100644 --- a/scripts/docker/Dockerfile.min.pip +++ b/scripts/docker/Dockerfile.min.pip @@ -1,5 +1,10 @@ FROM alpine:latest WORKDIR /z +LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ + org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="copyparty-min-pip" \ + org.opencontainers.image.description="just copyparty, no thumbnails, no media tags, no audio transcoding" RUN apk --no-cache add python3 py3-pip \ && python3 -m pip install copyparty \ @@ -11,9 +16,3 @@ RUN apk --no-cache add python3 py3-pip \ WORKDIR /w EXPOSE 3923 ENTRYPOINT ["python3", "-m", "copyparty", "-c", "/z/initcfg"] - -LABEL org.opencontainers.image.url="https://github.com/9001/copyparty" \ - org.opencontainers.image.source="https://github.com/9001/copyparty/tree/hovudstraum/scripts/docker" \ - org.opencontainers.image.licenses="MIT" \ - org.opencontainers.image.title="copyparty-min-pip" \ - org.opencontainers.image.description="just copyparty, no thumbnails, no media tags, no audio transcoding" diff --git a/scripts/docker/README.md b/scripts/docker/README.md index a1ee4157..2ec805e5 100644 --- a/scripts/docker/README.md +++ b/scripts/docker/README.md @@ -71,7 +71,7 @@ or using commandline arguments, # 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` +basically `./make.sh hclean pull img push` but see [devnotes.md](./devnotes.md) # notes diff --git a/scripts/docker/devnotes.md b/scripts/docker/devnotes.md new file mode 100644 index 00000000..fc3abe03 --- /dev/null +++ b/scripts/docker/devnotes.md @@ -0,0 +1,19 @@ +# building the images yourself + +```bash +./make.sh hclean pull img push +``` +will download the latest copyparty-sfx.py from github unless you have [built it from scratch](../../docs/devnotes.md#just-the-sfx) and then build all the images based on that + +deprecated alternative: run `make` to use the makefile however that uses docker instead of podman and only builds x86_64 + +`make.sh` is necessarily(?) overengineered because: +* podman keeps burning dockerhub pulls by not using the cached images (`--pull=never` does not apply to manifests) +* podman cannot build from a local manifest, only local images or remote manifests + +but I don't really know what i'm doing here 💩 + +* auth for pushing images to repos; + `podman login docker.io` + `podman login ghcr.io -u 9001` + [about gchq](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry) (takes a classic token as password) diff --git a/scripts/docker/make.sh b/scripts/docker/make.sh new file mode 100755 index 00000000..adc5a1a4 --- /dev/null +++ b/scripts/docker/make.sh @@ -0,0 +1,121 @@ +#!/bin/bash +set -e + +[ $(id -u) -eq 0 ] && { + echo dont root + exit 1 +} + +sarchs="386 amd64 arm/v7 arm64/v8 ppc64le s390x" +archs="amd64 arm s390x 386 arm64 ppc64le" +imgs="min im ac iv dj" +dhub_order="iv dj min im ac" +ghcr_order="ac im min dj iv" +ngs=( + iv-{arm,arm64,ppc64le,s390x} + dj-{arm,arm64,ppc64le,s390x} +) + +for v in "$@"; do + [ "$v" = clean ] && clean=1 + [ "$v" = hclean ] && hclean=1 + [ "$v" = purge ] && purge=1 + [ "$v" = pull ] && pull=1 + [ "$v" = img ] && img=1 + [ "$v" = push ] && push=1 + [ "$v" = sh ] && sh=1 +done + +[ $# -gt 0 ] || { + echo "need list of commands, for example: hclean pull img push" + exit 1 +} + +[ $sh ] && { + printf "\n\033[1;31mopening a shell in the most recently created docker image\033[0m\n" + podman run --rm -it --entrypoint /bin/ash $(podman images -aq | head -n 1) + exit $? +} + +filt= +[ $clean ] && filt='//{print$$3}' +[ $hclean ] && filt='/localhost\/copyparty-|^.*localhost\/alpine-/{print$3}' +[ $purge ] && filt='NR>1{print$3}' +[ $filt ] && { + [ $purge ] && { + podman kill $(podman ps -q) + podman rm $(podman ps -qa) + } + podman rmi -f $(podman images -a --history | awk "$filt") || true +} + +[ $pull ] && { + for a in $sarchs; do # arm/v6 + podman pull --arch=$a alpine:latest + done + + podman images --format "{{.ID}} {{.History}}" | + awk '/library\/alpine/{print$1}' | + while read id; do + tag=alpine-$(podman inspect $id | jq -r '.[]|.Architecture' | tr / -) + [ -e .tag-$tag ] && continue + touch .tag-$tag + echo tagging $tag + podman untag $id + podman tag $id $tag + done + rm .tag-* +} + +[ $img ] && { + fp=../../dist/copyparty-sfx.py + [ -e $fp ] || { + echo downloading copyparty-sfx.py ... + mkdir -p ../../dist + wget https://github.com/9001/copyparty/releases/latest/download/copyparty-sfx.py -O $fp + } + + rm -rf i err + mkdir i + tar -cC../.. dist/copyparty-sfx.py bin/mtag | tar -xvCi + + ps aux | awk '/bin\/qemu-[^-]+-static/{print$2}' | xargs -r kill -9 + + for i in $imgs; do + podman rm copyparty-$i || true + for a in $archs; do + [[ " ${ngs[*]} " =~ " $i-$a " ]] && continue + aa="$(printf '%7s' $a)" + # --pull=never does nothing at all btw + (set -x + podman build \ + --pull=never \ + --from localhost/alpine-$a \ + --manifest copyparty-$i \ + -t copyparty-$i-$a \ + -f Dockerfile.$i . || (echo $? $a >> err) + ) 2> >(tee $a.err | sed "s/^/$aa:/" >&2) > >(tee $a.out | sed "s/^/$aa:/") & + done + set +x + wait + [ -e err ] && { + echo somethign died, + cat err + exit 1 + } + for a in $archs; do + rm $a.{out,err} + done + done +} + +[ $push ] && { + for i in $dhub_order; do + podman manifest push --all copyparty-$i copyparty/$i:latest + done + for i in $ghcr_order; do + podman manifest push --all copyparty-$i ghcr.io/9001/copyparty-$i:latest + done +} + +echo ok