2023-02-18 23:04:55 +00:00
#!/bin/bash
set -e
[ $( id -u) -eq 0 ] && {
echo dont root
exit 1
}
2024-08-02 22:11:23 +00:00
suf = -b1
suf =
2023-02-18 23:04:55 +00:00
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-05-11 06:56:21 +00:00
aa = " $( printf '%11s' $a -$i ) "
2023-02-19 14:19:35 +00:00
# arm takes forever so make it top priority
2024-09-08 19:25:46 +00:00
[ ${ a : : 3 } = = arm ] && nice = || nice = -n20
2023-02-19 14:19:35 +00:00
2023-02-18 23:04:55 +00:00
# --pull=never does nothing at all btw
( set -x
2024-09-08 19:25:46 +00:00
nice $nice podman build \
2024-08-02 22:11:23 +00:00
--squash \
2023-02-18 23:04:55 +00:00
--pull= never \
--from localhost/alpine-$a \
2024-08-02 22:11:23 +00:00
-t copyparty-$i -$a $suf \
2023-02-19 14:19:35 +00:00
-f Dockerfile.$i . ||
2024-08-02 22:11:23 +00:00
( echo $? $i -$a >> err; printf '%096d\n' $( seq 1 42) )
2023-02-19 14:19:35 +00:00
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
2024-08-02 22:11:23 +00:00
variants = " $variants containers-storage:localhost/copyparty- $i - $a $suf "
2023-02-19 14:19:35 +00:00
done
2024-08-02 22:11:23 +00:00
podman manifest rm copyparty-$i $suf || echo "(that's fine btw)"
podman manifest create copyparty-$i $suf $variants
2023-02-19 14:19:35 +00:00
done
2023-02-18 23:04:55 +00:00
}
[ $push ] && {
2023-11-04 23:30:07 +00:00
ver = $(
python3 ../../dist/copyparty-sfx.py --version 2>/dev/null |
awk '/^copyparty v/{sub(/-.*/,"");sub(/v/,"");print$2;exit}'
)
echo $ver | grep -E '[0-9]\.[0-9]' || {
echo no ver
exit 1
}
2023-02-18 23:04:55 +00:00
for i in $dhub_order ; do
2023-11-04 23:30:07 +00:00
printf '\ndockerhub %s\n' $i
podman manifest push --all copyparty-$i copyparty/$i :$ver
2023-02-18 23:04:55 +00:00
podman manifest push --all copyparty-$i copyparty/$i :latest
2023-11-04 23:30:07 +00:00
done &
2023-02-18 23:04:55 +00:00
for i in $ghcr_order ; do
2023-11-04 23:30:07 +00:00
printf '\nghcr %s\n' $i
podman manifest push --all copyparty-$i ghcr.io/9001/copyparty-$i :$ver
2023-02-18 23:04:55 +00:00
podman manifest push --all copyparty-$i ghcr.io/9001/copyparty-$i :latest
2023-11-04 23:30:07 +00:00
done &
wait
2023-02-18 23:04:55 +00:00
}
echo ok