forked from alex-ac/github-action-ssh-docker-compose
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentrypoint.sh
executable file
·72 lines (57 loc) · 1.57 KB
/
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
#!/usb/bin/env bash
set -e
log() {
echo ">> [local]" $@
}
cleanup() {
set +e
log "Killing ssh agent."
ssh-agent -k
if ! $NO_BUILD
then
log "Removing workspace archive."
rm -f /tmp/workspace.tar.bz2
fi
}
trap cleanup EXIT
log "Packing workspace into archive to transfer onto remote machine."
tar cjvf /tmp/workspace.tar.bz2 --exclude .git .
log "Launching ssh agent."
eval `ssh-agent -s`
ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 -d)
remote_command="set -e;
log() {
echo '>> [remote]' \$@ ;
};
workdir=\"\$HOME/${DOCKER_COMPOSE_PREFIX}_workspace\"
if [ -d \$workdir ]
then
if [ -f \$workdir/$DOCKER_COMPOSE_FILENAME ]
then
log 'Docker Compose Down...';
docker-compose -f \$workdir/$DOCKER_COMPOSE_FILENAME down
fi
log 'Removing workspace...';
rm -rf \$workdir;
fi
log 'Creating workspace directory...';
mkdir \$workdir;
log 'Unpacking workspace...';
tar -C \$workdir -xjv;
if ! $NO_BUILD
then
log 'Launching docker-compose...';
cd \$workdir;
if $NO_CACHE
then
docker-compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PREFIX\" build --no-cache
docker-compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PREFIX\" up -d --remove-orphans --force-recreate
else
docker-compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PREFIX\" up -d --remove-orphans --build;
fi
fi"
echo ">> [local] Connecting to remote host."
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
"$SSH_USER@$SSH_HOST" -p "$SSH_PORT" \
"$remote_command" \
< /tmp/workspace.tar.bz2