-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
64 lines (52 loc) · 1.2 KB
/
build.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
#!/usr/bin/env bash
ORIGINAL_ARGS="${@}"
DOCKER_IMAGE_NAME="proxmox-packer-image-builder:latest"
run() {
docker run \
--volume "$(pwd):/work" \
--user "$(id -u):$(id -g)" \
-p 8080:8080 \
"${DOCKER_IMAGE_NAME}" \
${@}
}
usage() {
echo "
usage: $(basename "${0}") [OPTIONS]
-b, --build Build: (Default=false) Build the container with the given options. Cannot run build commands with this option - will only build the container.
-h, --help Help: prints usage.
examples:
$(basename "${0}") -b
"
run help
exit 1
}
for arg in "${@}"; do
shift
case "${arg}" in
'-build'|'--build') set -- "$@" "-b" ;;
'help'|'-help'|'--help') set -- "$@" "-h" ;;
*) set -- "$@" "${arg}"
esac
done
# Default options
BUILD=false
while getopts ':bh' 'option'; do
case "${option}" in
'b') BUILD='true' ;;
'h') usage ;;
*) ;;
esac
done
# Check if docker exists on the host
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker is not installed.' >&2
exit 1
fi
if [ "${BUILD}" = 'true' ]; then
docker buildx build \
--tag "${DOCKER_IMAGE_NAME}" \
--file Dockerfile \
.
else
run "${ORIGINAL_ARGS}"
fi