-
Notifications
You must be signed in to change notification settings - Fork 8
/
docker-make-client-tarball
executable file
·54 lines (46 loc) · 1.53 KB
/
docker-make-client-tarball
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
image_name=mktarball
container_name=mktarball$$
progdir=$(dirname "$0")
myuid=$(id -u)
docker_is_podman=false
docker version | grep -q "Docker Engine" || docker_is_podman=true
if $docker_is_podman && [[ $myuid -ne 0 ]]; then
docker="sudo podman"
else
docker=docker
fi
if ! $docker image inspect ${image_name} &>/dev/null; then
$docker build -t${image_name} "$progdir"
fi
mkdir -p output
tmp_output_dir=$(mktemp -d "${TMPDIR:-/tmp}/mktarball-XXXXXX")
$docker run --privileged -it --name $container_name \
-v "$(cd "$progdir"; pwd):/tarball-client:ro" -v "$tmp_output_dir:/output:rw" \
-e "myuid=$myuid" \
-w /output \
${image_name} sh -c '
/tarball-client/make-client-tarball "$@"; ret=$?
chown $myuid * 2>/dev/null
exit $ret' sh "$@"; ret=$?
if [[ $ret != 0 ]]; then
echo "Failed with code $ret."
echo "Output (if any) has been left in $tmp_output_dir."
echo "Investigate the error with:"
echo " $docker start $container_name && $docker exec -it $container_name bash"
echo "once done, remove the container with:"
echo " $docker rm -f $container_name"
exit $ret
else
echo "Successful."
if mv "$tmp_output_dir"/* .; then
echo "Tarballs have been created in the current directory"
rm -rf "$tmp_output_dir"
else
echo "Error transferring output."
echo "Output has been left in $tmp_output_dir."
fi
rmdir output &>/dev/null || :
$docker stop $container_name &>/dev/null || :
$docker rm $container_name >/dev/null
fi