-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.sh
executable file
·72 lines (59 loc) · 1.68 KB
/
compile.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
#!/usr/bin/env bash
# -----------------------------------
#| bgll.fullstackfullstock.com |
#| github.com/babidiii |
# -----------------------------------
RESET=$(tput sgr0)
BOLD=$(tput bold)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
BLUE=$(tput setaf 4)
log(){
color=${1}
val=${2}
printf "* %s\n" "${BOLD}${color}${val}${RESET}"
}
is_command_installed(){
local command_name=${1}
if [ ! -n "$(command -v ${command_name})" ]; then
log "${RED}" "${command_name} command not installed"
return 1
else
log "${GREEN}" "${command_name} command installed"
return 0
fi
}
main(){
image_name="templex"
dockerfile_path="./Dockerfile"
context_path="$(dirname ${dockerfile_path})"
build_dir="./build"
if is_command_installed "podman" ; then
cmd=(podman)
build_cmd=(podman)
run_cmd=(podman)
elif is_command_installed "docker"; then
cmd=(docker)
build_cmd=(docker)
run_cmd=(docker)
else
log "${RED}" "You need to install either docker or podman"
exit 1
fi
build_cmd+=(build -t "${image_name}" -f "${dockerfile_path}" "${context_path}")
run_cmd+=(run --rm -ti --volume "`pwd`:/data" --entrypoint "/data/latex_compile.sh" "${image_name}")
[ -d "${build_dir}" ] || mkdir "${build_dir}"
log "${YEL}" "Checking if ${image_name} image exists"
res=$($cmd images -q ${image_name} )
if [[ -z "${res}" ]]; then
log "${RED}" "Image doesn't exist"
log "${YEL}" "Building the ${image_name} image"
${build_cmd[@]}
[[ $? -ne 0 ]] && log "${RED}" "Error building the image" && exit 1
else
log "${YEL}" "Image ${image_name} exist"
fi
log "${YEL}" "Running the container"
${run_cmd[@]}
}
main "${@}"