2023-02-18 23:04:55 +00:00
#!/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"
2023-02-19 14:19:35 +00:00
imgs = "dj iv min im ac"
2023-02-19 15:11:04 +00:00
dhub_order = "iv dj min im ac"
ghcr_order = "ac im min dj iv"
2023-02-18 23:04:55 +00:00
ngs = (
2023-02-19 14:19:35 +00:00
iv-{ ppc64le,s390x}
dj-{ ppc64le,s390x,arm}
2023-02-18 23:04:55 +00:00
)
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 = '/<none>/{print$$3}'
[ $hclean ] && filt = '/localhost\/copyparty-|^<none>.*localhost\/alpine-/{print$3}'
[ $purge ] && filt = 'NR>1{print$3}'
[ $filt ] && {
[ $purge ] && {
2023-03-05 20:18:16 +00:00
podman kill $( podman ps -q) || true
podman rm $( podman ps -qa) || true
2023-02-18 23:04:55 +00:00
}
podman rmi -f $( podman images -a --history | awk " $filt " ) || true
2023-03-05 20:18:16 +00:00
podman rmi $( podman images -a --history | awk '/^<none>.*<none>.*-tmp:/{print$3}' ) || true
2023-02-18 23:04:55 +00:00
}
[ $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
}
2023-02-19 14:19:35 +00:00
# kill abandoned builders
ps aux | awk '/bin\/qemu-[^-]+-static/{print$2}' | xargs -r kill -9
# grab deps
2023-02-18 23:04:55 +00:00
rm -rf i err
mkdir i
tar -cC../.. dist/copyparty-sfx.py bin/mtag | tar -xvCi
for i in $imgs ; do
2023-02-19 14:19:35 +00:00
podman rm copyparty-$i || true # old manifest
2023-02-18 23:04:55 +00:00
for a in $archs ; do
2023-02-19 14:19:35 +00:00
[ [ " ${ ngs [*] } " = ~ " $i - $a " ] ] && continue # known incompat
# wait for a free slot
while true; do
touch .blk
[ $( jobs -p | wc -l) -lt $( nproc) ] && break
while [ -e .blk ] ; do sleep 0.2; done
done
2023-02-18 23:04:55 +00:00
aa = " $( printf '%7s' $a ) "
2023-02-19 14:19:35 +00:00
# arm takes forever so make it top priority
[ ${ a : : 3 } = = arm ] && nice = || nice = nice
2023-02-18 23:04:55 +00:00
# --pull=never does nothing at all btw
( set -x
2023-02-19 14:19:35 +00:00
$nice podman build \
2023-02-18 23:04:55 +00:00
--pull= never \
--from localhost/alpine-$a \
-t copyparty-$i -$a \
2023-02-19 14:19:35 +00:00
-f Dockerfile.$i . ||
( echo $? $i -$a >> err)
rm -f .blk
2023-02-18 23:04:55 +00:00
) 2> >( tee $a .err | sed " s/^/ $aa :/ " >& 2) > >( tee $a .out | sed " s/^/ $aa :/ " ) &
done
[ -e err ] && {
echo somethign died,
cat err
2023-02-19 14:19:35 +00:00
pkill -P $$
2023-02-18 23:04:55 +00:00
exit 1
}
for a in $archs ; do
2023-02-19 00:50:07 +00:00
rm -f $a .{ out,err}
2023-02-18 23:04:55 +00:00
done
done
2023-02-19 14:19:35 +00:00
wait
[ -e err ] && {
echo somethign died,
cat err
pkill -P $$
exit 1
}
# avoid podman race-condition by creating manifest manually --
# Error: creating image to hold manifest list: image name "localhost/copyparty-dj:latest" is already associated with image "[0-9a-f]{64}": that name is already in use
for i in $imgs ; do
variants =
for a in $archs ; do
[ [ " ${ ngs [*] } " = ~ " $i - $a " ] ] && continue
variants = " $variants containers-storage:localhost/copyparty- $i - $a "
done
podman manifest create copyparty-$i $variants
done
2023-02-18 23:04:55 +00:00
}
[ $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