-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollback.py
34 lines (24 loc) · 1.09 KB
/
rollback.py
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
import os
import subprocess
import datetime
import shutil
service_name = "appsmith"
now = datetime.datetime.now()
backup_dir = f"backup_{service_name}_{now.strftime('%Y%m%d%H%M%S')}"
os.makedirs(backup_dir)
subprocess.run(["docker", "system", "prune", "-f"])
subprocess.run(["docker-compose", "down"])
shutil.copytree("./stacks", f"{backup_dir}/stacks")
shutil.copy2("./docker-compose.yml", backup_dir)
shutil.copy2("./rollback.py", backup_dir)
# Specifies the previous version of the image that you want to use for rollback
print('The versions are written only the numbers example: 1.9.4')
current_version = "v" + input('Write the current version of asppmith: ')
previous_version = "v" + input('Enter the version number you want to return to: ')
with open("docker-compose.yml", "r") as file:
compose_file = file.read()
# Replaces the current version of the image with the previous version in the file
compose_file = compose_file.replace(current_version, previous_version)
with open("docker-compose.yml", "w") as file:
file.write(compose_file)
subprocess.run(["docker-compose", "up", "-d"])