This repository was archived by the owner on Dec 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver-update.sh
More file actions
executable file
·79 lines (56 loc) · 1.97 KB
/
server-update.sh
File metadata and controls
executable file
·79 lines (56 loc) · 1.97 KB
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
77
78
79
#!/bin/sh
set -e
source .envfile
if [ ! -r ".envfile" ]; then
echo "Please create and use the .envfile to set all variables"
exit 1
fi
source .envfile
if [ -z "${SERVER_IP}" ]; then
echo "Need to set SERVER_IP"
exit 1
fi
if [ -z "${USER_NAME}" ]; then
echo "Need to set USER_NAME"
exit 1
fi
FILENAME="platzhalterio.latest.tar"
echo "$(date) - Building docker image"
docker build -t composeus/platzhalterio:latest .
echo "$(date) - Exporting docker image"
docker save -o "${FILENAME}" composeus/platzhalterio:latest
echo "$(date) - Zipping file for easier transfer"
gzip "${FILENAME}"
echo "$(date) - Uploading $(du -m ${FILENAME}.gz | cut -f1) mb file to webserver"
scp "${FILENAME}.gz" "${USER_NAME}@${SERVER_IP}:/home/${USER_NAME}/platzhalterio"
echo "$(date) - Upload complete, removing local docker image"
rm "${FILENAME}.gz"
echo "$(date) - Deploying the new version"
scp "docker-compose.yml" "${USER_NAME}@${SERVER_IP}:/home/${USER_NAME}/platzhalterio"
ssh -l "${USER_NAME}" "${SERVER_IP}" <<EOF
cat <<DEPLOYMENT | bash
set -e
echo "\$(date) - Changing work directory to platzhalterio"
cd "/home/${USER_NAME}/platzhalterio"
echo "\$(date) - Unzipping uploaded docker file"
gunzip "${FILENAME}.gz"
echo "\$(date) - Loading docker image"
docker load -i "${FILENAME}"
echo "\$(date) - Cleaning up downloaded image"
rm "${FILENAME}"
echo "Update of image complete. Will now restart the server!"
echo "$(date) - Stopping old platzhalterio server"
docker-compose down || echo "Container is not running"
docker rm "platzhalterio" || echo "Container could not be removed (most probably it wasn't running before)"
echo "$(date) - Create if docker volume exists"
if docker volume inspect platzhalterio-data; then
echo "$(date) - Volume already exists, nothing to do"
else
echo "$(date) - Creating volume"
docker volume create platzhalterio-data
echo "$(date) - Volume created"
fi
echo "$(date) - Start platzhalter.io server in the background"
docker-compose up -d
DEPLOYMENT
EOF