forked from artipie/artipie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
73 lines (63 loc) · 1.56 KB
/
utils.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
set -e
function die {
printf "FATAL: %s\n" "$1"
exit 1
}
function require_env {
local name="$1"
local val=$(eval "echo \${$name}")
if [[ -z "$val" ]]; then
die "${name} env should be set"
fi
}
require_env basedir
# set debug on CI builds
if [[ -n "$CI" ]]; then
export DEBUG=true
fi
function log_debug {
if [[ -n "$DEBUG" ]]; then
printf "DEBUG: %s\n" "$1"
fi
}
function assert {
[[ "$1" -ne "$2" ]] && die "assertion failed: ${1} != ${2}"
}
if [[ -n "$DEBUG" ]]; then
[[ -z "$DEBUG_NOX" ]] && set -x
log_debug "debug enabled"
fi
function start_artipie {
local image="$1"
if [[ -z "$image" ]]; then
image=$ARTIPIE_IMAGE
fi
if [[ -z "$image" ]]; then
image="artipie/artipie:1.0-SNAPSHOT"
fi
local port="$2"
if [[ -z "$port" ]]; then
port=8080
fi
log_debug "using image: '${image}'"
log_debug "using port: '${port}'"
[[ -z "$image" || -z "$port" ]] && die "invalid image or port params"
stop_artipie
docker run --rm --detach --name artipie \
-v "${basedir}/../artipie.yml:/etc/artipie/artipie.yml" \
-v "${basedir}/cfg:/var/artipie/cfg" \
-v "${basedir}/data:/var/artipie/data" \
-p "${port}:8080" "$image"
log_debug "artipie started"
# stop artipie docker container on script exit
if [[ -z "$ARTIPIE_NOSTOP" ]]; then
trap stop_artipie EXIT
fi
}
function stop_artipie {
local container=$(docker ps --filter name=artipie -q 2> /dev/null)
if [[ -n "$container" ]]; then
log_debug "stopping artipie container ${container}"
docker stop "$container" || echo "failed to stop"
fi
}