-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
76 lines (65 loc) · 2.68 KB
/
docker-entrypoint.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
#!/bin/sh
set -e
if [ -z "$REEVE_API" ]; then
echo This docker image is a Reeve CI pipeline step and is not intended to be used on its own.
exit 1
fi
cd /reeve/src/${CONTEXT}
if [ -n "$DOCKER_LOGIN_REGISTRY" ]; then
if [ -z "$DOCKER_LOGIN_USER" ]; then
echo Missing login user
exit 1
fi
if [ -z "$DOCKER_LOGIN_PASSWORD" ]; then
echo Missing login password
exit 1
fi
echo Login attempt for $DOCKER_LOGIN_REGISTRY...
printf "%s\n" "$DOCKER_LOGIN_PASSWORD" | docker login -u "$DOCKER_LOGIN_USER" --password-stdin $DOCKER_LOGIN_REGISTRY
fi
if [ "$MODE" = "v1" ]; then
# ===== compose v1 =====
COMMAND="docker-compose $([[ -n "$FILE" ]] && printf "%s" "-f $FILE" ||:) $([[ -n "$NAME" ]] && printf "%s" "-p $NAME" ||:)"
if [ "$STATE" = "present" ]; then
echo Deploying compose $NAME with docker compose v1...
$COMMAND up -d --remove-orphans $([[ "$COMPOSE_BUILD" = "always" ]] && printf "%s" "--build" ||:) $([[ "$COMPOSE_BUILD" = "never" ]] && printf "%s" "--no-build" ||:) $([[ "$COMPOSE_RECREATE" = "always" ]] && printf "%s" "--force-recreate" ||:) $([[ "$COMPOSE_RECREATE" = "never" ]] && printf "%s" "--no-recreate" ||:) --pull $COMPOSE_PULL
elif [ "$STATE" = "absent" ]; then
echo Removing compose $NAME with docker compose v1...
$COMMAND down
else
echo Invalid state $STATE
exit 1
fi
elif [ "$MODE" = "v2" ]; then
# ===== compose v2 =====
COMMAND="docker compose $([[ -n "$FILE" ]] && printf "%s" "-f $FILE" ||:) $([[ -n "$NAME" ]] && printf "%s" "-p $NAME" ||:)"
if [ "$STATE" = "present" ]; then
echo Deploying compose $NAME with docker compose v2...
$COMMAND up -d --remove-orphans $([[ "$COMPOSE_BUILD" = "always" ]] && printf "%s" "--build" ||:) $([[ "$COMPOSE_BUILD" = "never" ]] && printf "%s" "--no-build" ||:) $([[ "$COMPOSE_RECREATE" = "always" ]] && printf "%s" "--force-recreate" ||:) $([[ "$COMPOSE_RECREATE" = "never" ]] && printf "%s" "--no-recreate" ||:) --pull $COMPOSE_PULL
elif [ "$STATE" = "absent" ]; then
echo Removing compose $NAME with docker compose v2...
$COMMAND down
else
echo Invalid state $STATE
exit 1
fi
elif [ "$MODE" = "swarm" ]; then
# ===== swarm mode =====
if [ -z "$NAME" ]; then
echo Missing name
exit 1
fi
if [ "$STATE" = "present" ]; then
echo Deploying stack $NAME...
docker stack deploy --detach=false --prune $([[ -n "$FILE" ]] && printf "%s" "-c $FILE" ||:) --resolve-image $SWARM_PULL $([[ -n "$DOCKER_LOGIN_REGISTRY" ]] && printf "%s" "--with-registry-auth") $NAME
elif [ "$STATE" = "absent" ]; then
echo Removing stack $NAME...
docker stack rm $NAME
else
echo Invalid state $STATE
exit 1
fi
else
echo Invalid mode $MODE
exit 1
fi