moth/build/ci/ci.sh

52 lines
835 B
Bash
Raw Normal View History

2021-10-19 18:49:46 -06:00
#! /bin/sh
set -e
2021-10-19 20:17:22 -06:00
images="ghcr.io/dirtbags/moth"
2021-10-19 20:09:51 -06:00
2021-10-19 18:49:46 -06:00
ACTION=$1
2021-10-19 18:52:19 -06:00
if [ -z "$ACTION" ]; then
echo "Usage: $0 ACTION"
2021-10-19 18:49:46 -06:00
exit 1
fi
log () {
printf "=== %s\n" "$*" 1>&2
}
fail () {
printf "\033[31;1m=== FAIL: %s\033[0m\n" "$*" 1>&2
exit 1
}
2021-10-19 19:55:42 -06:00
run () {
2021-10-19 20:01:27 -06:00
printf "\033[32m\$\033[0m %s\n" "$*" 1>&2
2021-10-19 19:55:42 -06:00
"$@"
}
2021-10-19 18:49:46 -06:00
tags () {
pfx=$1
2021-10-19 20:09:51 -06:00
for base in $images; do
2021-10-19 18:49:46 -06:00
echo $pfx $base:${CI_COMMIT_REF_SLUG}
echo $pfx $base:${CI_COMMIT_REF_SLUG%.*}
echo $pfx $base:${CI_COMMIT_REF_SLUG%.*.*}
done | uniq
}
case $ACTION in
publish)
2021-10-19 19:55:42 -06:00
run docker build \
2021-10-19 18:49:46 -06:00
--file build/package/Containerfile \
2021-10-19 20:05:02 -06:00
$(tags --tag) \
2021-10-19 18:53:18 -06:00
.
2021-10-19 20:12:36 -06:00
tags | while read image; do
run docker push $image
2021-10-19 20:09:51 -06:00
done
2021-10-19 18:49:46 -06:00
;;
*)
echo "Unknown action: $1" 1>&2
exit 1
;;
esac