-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.sh
executable file
·79 lines (75 loc) · 2.67 KB
/
make.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
inc() { # <<files>>
while [ "$#" -gt 0 ]; do
cat "$1"
echo; shift;
done
}
cd "$(dirname "$0")"
source 'src/libs/docker-cli.lib.sh'
source 'src/libs/logging.lib.sh'
source 'src/libs/vars.lib.sh'
readonly image="${IMAGE:-cav94mat/docker-maintenance}"
readonly output="${OUTPUT:-${OUTPUT_DIR:-.}/docker-maintenance.sh}"
readonly sideload="${DOCKER_SIDELOAD:-${OUTPUT_DIR:-.}/docker-sideload.tar}"
readonly build="${BUILD:-${DOCKER_TAG:-$(git rev-parse --short HEAD)}}" #${USER}@$(date +%Y-%m-%d/%H:%m:%S)
readonly install_dir="${INSTALL_DIR:-/opt/docker-maintenance}"
readonly install_bin="${INSTALL_BIN:-/usr/bin/docker-maintenance}"
readonly test_ctr='test-maintenance'
readonly test_ctr2='cron-maintenance'
while [ "$#" -gt 0 ]; do
op="$1"
case "$op" in
"compile"|"")
log -I "Building '${build}' -> ${output}"
{
echo '#!/bin/bash'
echo "# Do NOT edit this file directly. Please rebuild with \`make\`."
echo "readonly build='$build'"
echo "readonly fork_image='$image'"
echo ''
inc "./src/libs/"*.lib.sh
inc "./src/inc/"*.sh
echo ''
inc "./src/program.sh"
} > "$output"
chmod +x "$output"
;;
"image")
docker build --build-arg BUILD="${build}" -t "${image}" .
docker save -o "${sideload}" "${image}"
;;
"install")
log -I "Installing ${output} to ${install_dir}/"
mkdir -p "${install_dir}"
cp "${output}" "${install_dir}"/docker-maintenance.sh
cp -RT ./scripts "${install_dir}/scripts"
log -I "Symlinking ${install_bin} -> ${install_dir}/docker-maintenance.sh"
ln -fs "/${install_dir}/docker-maintenance.sh" "${install_bin}"
;;
"clean")
rm -Rf "${install_dir}" "${install_bin}" "${output}"
;;
"test")
cd ./test
export IMAGE="$image"
docker-compose up --force-recreate "$test_ctr"
# Await for container recreation
while ! docker-compose exec "$test_ctr" /bin/true 2>/dev/null; do
printf '.' >&2
sleep 1
done
printf '\n' >&2
# Resume logging stream
docker-compose logs -f "$test_ctr"
# Alternate container
docker-compose logs "$test_ctr2"
# Cleanup
docker-compose down
;;
*)
log -E "Unsupported operation \`$op\`"
exit 1
esac
shift
done