-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhugo
executable file
·46 lines (38 loc) · 965 Bytes
/
hugo
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
#!/bin/bash
CONTAINER='test_hugo'
HUGO_ENV=''
# Check if the script is called with '-p' or '--publish'
# If yes, remove it from the arguments
ARGS=()
for arg in "$@"
do
if [[ $arg == '--prod' ]]; then
HUGO_ENV='production'
else
ARGS+=("$arg")
fi
done
function check_container_availability () {
docker inspect "${CONTAINER}" > /dev/null 2>&1
return $?
}
check_container_availability
if [ $? -eq 0 ]; then
docker exec "${CONTAINER}" hugo "${ARGS[@]}"
else
# Construct Docker run command
docker_run_command=(
docker run --rm
-it
--publish 4000:4000
--user 1000:1000
--name "${CONTAINER}"
--volume "$(pwd):/src"
)
# Add environment variable if HUGO_ENV is not empty
if [ -n "${HUGO_ENV}" ]; then
docker_run_command+=("-e" "HUGO_ENV=${HUGO_ENV}")
fi
docker_run_command+=("klakegg/hugo:ext")
"${docker_run_command[@]}" "${ARGS[@]}"
fi