This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
73 lines (60 loc) · 1.7 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
73
#!/bin/bash
## check for .env and load it
if [ ! -f .env ]; then
export $(cat .env | xargs)
fi
## Function to check if docker-compose.yml has been modified
docker_compose_modified() {
local old_mtime=$(stat -c %Y docker-compose.yml)
git pull
git_fetch_result=$?
local new_mtime=$(stat -c %Y docker-compose.yml)
if [ $new_mtime -gt $old_mtime ]; then
return 0
else
return 1
fi
}
## Fetch and check if docker-compose.yml has been modified
echo "pulling"
if docker_compose_modified; then
docker_actions=true
else
docker_actions=false
fi
if [ ! -d ".venv" ]; then
echo "Creating venv"
python3 -m venv .venv
fi
echo "Activating virtual environment"
source .venv/bin/activate
echo "Installing dependencies"
pip install -r requirements.txt -U
## Django things
echo "Checking for Django migrations"
python manage.py showmigrations --plan > /dev/null 2>&1
if [ $? -eq 1 ]; then
echo "There are Django migrations available. Exiting."
exit 1
else
echo "There are no Django migrations available. Proceeding with the update."
fi
## Copy over all the static files
echo "Copying over files for nginx to static dir."
python manage.py collectstatic --noinput
## Docker related actions
if [ "$docker_actions" = true ]; then
echo "Updating docker stack."
echo "Shutting down docker stack."
sudo docker-compose down
echo "Starting docker stack."
sudo docker-compose up -d
echo "Copying systemd service file"
sudo cp tinetbackend.service /etc/systemd/system/
echo "Reloading systemd daemon"
sudo systemctl daemon-reload
fi
echo "Update completed"
## Run stuff
echo "Starting server"
gunicorn -c gunicorn.conf.py tinetbackend.wsgi:application