-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yml
More file actions
215 lines (198 loc) · 7.83 KB
/
Taskfile.yml
File metadata and controls
215 lines (198 loc) · 7.83 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
version: '3'
silent: true
tasks:
default:
desc: List available tasks
cmds:
- echo "Available tasks:"
- echo "task install - Install OS2BorgerPC Adminsite"
- echo "task upgrade - Upgrade OS2BorgerPC Adminsite to a newer version"
- echo "task up - Start the application by bringing all containers up"
- echo "task stop - Stop the application by stopping all containers"
- echo "task reinstall - Reinstall the application. WARNING Deletes the database and uploaded files!"
- echo "task purge - Remove the application. WARNING Deletes the database and uploaded files!"
- echo "task down - Remove all containers"
- echo "task cron - Run cron jobs manually"
- echo "task backup_db - Perform a database dump"
install:
desc: Install OS2BorgerPC Adminsite
cmds:
- task _show_preinstall_notes
- |
# Check if the external network 'frontend' exists, create if not
if ! docker network ls --format '{{.Name}}' | grep -wq frontend; then
echo "Creating external network 'frontend'"
docker network create frontend
else
echo "External network 'frontend' already exists"
fi
- task _version_file
- task _prepare_nginx_conf
- echo "Installing"
- docker compose --env-file .env -f compose.yml pull
- docker compose --env-file .env -f compose.yml up --force-recreate --detach --remove-orphans
- task _show_notes
upgrade:
desc: Upgrade OS2BorgerPC Adminsite to a newer version
cmds:
- task _show_pre_upgrade_notes
- task _version_file
- task stop
- docker compose --env-file .env -f compose.yml down
- docker compose --env-file .env -f compose.yml pull
- docker compose --env-file .env -f compose.yml up --force-recreate --detach --remove-orphans
- task _show_upgrade_notes
reinstall:
desc: Reinstall the application. WARNING Deletes the database and uploaded files!
deps:
- purge
cmds:
- task install
purge:
desc: Remove the application. WARNING Deletes the database and uploaded files!
deps:
- stop
cmds:
- docker compose --env-file .env -f compose.yml down -v
- |
if [ -f VERSION ]; then
rm VERSION
echo "VERSION file deleted."
fi
down:
desc: Remove all containers
deps:
- stop
cmds:
- docker compose --env-file .env -f compose.yml down
- |
if [ -f VERSION ]; then
rm VERSION
echo "VERSION file deleted."
fi
up:
desc: Start the application by bringing all containers up
cmds:
- docker compose --env-file .env -f compose.yml up -d
stop:
desc: Stop the application by stopping all containers
cmds:
- docker compose --env-file .env -f compose.yml stop
cron:
desc: Run cron jobs manually
cmds:
- |
DOMAIN=$(grep ^DOMAIN= .env | cut -d '=' -f 2)
echo "Executing check_notifications..."
curl http://$DOMAIN:8080/jobs/check_notifications -f
echo ""
echo "Executing clean_up_database..."
curl http://$DOMAIN:8080/jobs/clean_up_database -f
echo ""
echo "===================================================="
echo "Automate job execution by adding the lines below to your crontab (crontab -e):"
echo "===================================================="
echo ""
echo "# Run check_notifications every 10 minutes"
echo "*/10 * * * * curl http://$DOMAIN:8080/jobs/check_notifications -f"
echo ""
echo "# Run clean_up_database once a week (Sunday at midnight)"
echo "0 0 * * 0 curl http://$DOMAIN:8080/jobs/clean_up_database -f"
echo ""
echo "===================================================="
backup_db:
desc: Perform a database dump
cmds:
- |
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
DB_BACKUP_DIR=$(pwd)/db_backups
FILENAME=$DB_BACKUP_DIR/db_backup_$TIMESTAMP.sql
echo "Performing database backup..."
mkdir -p $DB_BACKUP_DIR # Ensure the backup directory exists
DB_USER=$(grep ^DB_USER= .env | cut -d '=' -f 2)
DB_NAME=$(grep ^DB_NAME= .env | cut -d '=' -f 2)
echo "Using database user: $DB_USER and database name: $DB_NAME" # Debugging output
docker compose exec db pg_dump -U $DB_USER $DB_NAME > $FILENAME
if [ $? -eq 0 ]; then
echo "Database backup saved to $FILENAME"
fi
_show_pre_upgrade_notes:
cmds:
- |
VERSION=$(grep ^VERSION= .env | cut -d '=' -f 2)
if [ -f VERSION ] && [ "$(cat VERSION)" = "$VERSION" ]; then
echo ""
echo "===================================================="
echo "Upgrading to release $VERSION..."
echo "Ups! It looks like release $VERSION is the version currently installed. Aborting."
echo ""
echo "===================================================="
exit 1
fi
echo ""
echo "===================================================="
echo "You are about to upgrade to version $VERSION."
echo "===================================================="
echo "Are you sure you want to continue? (yes/no)"
read answer && case $answer in
[Yy][Ee][Ss]) ;;
*) echo "Upgrade canceled."; exit 1;;
esac
_show_preinstall_notes:
cmds:
- echo ""
- echo "===================================================="
- echo "Pre-installation Requirements"
- echo "===================================================="
- echo ""
- echo "To proceed with the installation, ensure the following steps are completed:"
- echo "1. Update '.env'. Change at least DOMAIN, DB_PASSWORD and SECRET_KEY."
- echo "2. Place your SSL certificate files ('nginx.crt' and 'nginx.key') in the 'ssl' directory."
- echo ""
- echo "Have you completed the above pre-installation steps? (yes/no)"
- |
read answer && case $answer in
[Yy][Ee][Ss]) ;;
*) echo "Please complete the pre-install tasks before continuing."; exit 1;;
esac
_prepare_nginx_conf:
cmds:
- cp example.nginx.conf nginx.conf
- |
DOMAIN=$(grep ^DOMAIN= .env | cut -d '=' -f 2)
sed -i "s/\${DOMAIN}/$DOMAIN/g" nginx.conf
_version_file:
cmds:
- |
VERSION=$(grep ^VERSION= .env | cut -d '=' -f 2)
echo $VERSION > VERSION
echo "VERSION file updated with value: $VERSION"
_show_notes:
cmds:
- |
DOMAIN=$(grep ^DOMAIN= .env | cut -d '=' -f 2)
ADMIN_USERNAME=$(grep ^ADMIN_USERNAME= .env | cut -d '=' -f 2)
ADMIN_PASSWORD=$(grep ^ADMIN_PASSWORD= .env | cut -d '=' -f 2)
echo ""
echo "===================================================="
echo "OS2Borgerpc Admin is now available via the URLs below"
echo "===================================================="
echo "Admin: https://$DOMAIN"
echo "Django Backend: https://$DOMAIN/admin"
echo "===================================================="
echo "You can log in with the following credentials:"
echo "Username: $ADMIN_USERNAME"
echo "Password: $ADMIN_PASSWORD"
echo "===================================================="
echo "IMPORTANT: Please change the password of the admin user right away."
echo "You can do this from the menu item 'Brugere' in the main menu of OS2BorgerPC Admin."
echo "===================================================="
_show_upgrade_notes:
desc: Show upgrade notes after upgrading the application
cmds:
- |
if [ -f VERSION ]; then
echo "You have upgraded OS2BorgerPC Admin to $(cat VERSION)"
else
echo "VERSION file not found."
fi