Files
dotfiles/test-in-docker.sh

91 lines
2.6 KiB
Bash
Raw Normal View History

2020-12-08 23:41:35 +01:00
#!/usr/bin/env bash
set -o nounset
set -o errexit
tmpdir="$(mktemp -d)"
2021-02-09 21:04:24 +01:00
trap "rm -rf ${tmpdir}" EXIT
2020-12-08 23:41:35 +01:00
git archive --format tar --output "${tmpdir}/dotfiles.tar" HEAD
git submodule foreach 'bash -x -c "
set -o errexit
git archive --prefix $path/ HEAD --output '"${tmpdir}/submod.tar"'
tar -i --concatenate --file='"${tmpdir}/dotfiles.tar"' '"${tmpdir}/submod.tar"'
rm '"${tmpdir}/submod.tar"'
"'
gzip -k -f -v "${tmpdir}/dotfiles.tar"
2021-02-09 20:46:14 +01:00
test_ares() {
if [[ -d "/var/cache/pacman/pkg/" ]] ; then
dockeropts=(-v "/var/cache/pacman/pkg/:/var/cache/pacman/pkg_host/")
else
echo "Warning: /var/cache/pacman/pkg/ does not exist. Create it to speed up multiple runs" >&2
fi
2021-02-09 20:46:14 +01:00
docker pull docker.io/library/archlinux:base
docker run \
-ti \
--rm \
-v ${tmpdir}/dotfiles.tar.gz:/tmp/dotfiles.tar.gz:ro \
--mount type=tmpfs,destination=/var/cache/pacman/pkg/ \
"${dockeropts[@]}" \
--hostname ares \
docker.io/library/archlinux:base \
sh -c '
set -o errexit
# Uncomment CacheDir and append the host pacman cache as cachedir
# At worst, the cache directory will be ignored if it does not exist
# Pacman will always prefer the first cache directory, so newly downloaded
# packages will stay in the container
2022-06-30 06:38:05 +02:00
sed -i '"'"'s/^#\?\(CacheDir.*\)/CacheDir = \/var\/cache\/pacman\/pkg_host\/\n\1/'"'"' /etc/pacman.conf
mkdir -p /var/cache/pacman/pkg_host/
2022-06-30 06:38:05 +02:00
pacman -Syu --noconfirm linux
cd $(mktemp -d)
tar xf /tmp/dotfiles.tar.gz -C .
ANSIBLE_EXTRA_ARGS="-e manage_services=false" ./install.sh
'
2021-02-09 20:46:14 +01:00
}
2021-10-02 12:12:48 +02:00
test_neptune() {
docker pull docker.io/library/ubuntu:20.04
docker run -ti --rm -v ${tmpdir}/dotfiles.tar.gz:/tmp/dotfiles.tar.gz:ro --hostname neptune docker.io/library/ubuntu:20.04 sh -c '
set -o errexit
cd $(mktemp -d)
tar xf /tmp/dotfiles.tar.gz -C .
ANSIBLE_EXTRA_ARGS="-e manage_services=false" ./install.sh
'
}
2021-10-03 12:55:12 +02:00
test_mars() {
docker pull docker.io/library/ubuntu:20.04
docker run -ti --rm -v ${tmpdir}/dotfiles.tar.gz:/tmp/dotfiles.tar.gz:ro --hostname mars docker.io/library/ubuntu:20.04 sh -c '
set -o errexit
cd $(mktemp -d)
tar xf /tmp/dotfiles.tar.gz -C .
ANSIBLE_EXTRA_ARGS="-e manage_services=false" ./install.sh
'
}
2021-10-02 12:56:11 +02:00
case "${1:-all}" in
ares)
test_ares
;;
neptune)
test_neptune
;;
2021-10-03 12:55:12 +02:00
mars)
test_mars
;;
2021-10-02 12:56:11 +02:00
all)
test_ares
test_neptune
2021-10-03 12:55:12 +02:00
test_mars
2021-10-02 12:56:11 +02:00
;;
esac