mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 05:53:43 +00:00
Add a deployment lock to prevent concurrent deployments
The lock file is a directory in case we want to add future metadata information. (imported from commit 505a684870baff94f28bf689b0c5ca2e8265a3c0)
This commit is contained in:
@@ -7,6 +7,7 @@ import traceback
|
|||||||
import logging
|
import logging
|
||||||
from humbug_tools import check_output
|
from humbug_tools import check_output
|
||||||
import datetime
|
import datetime
|
||||||
|
import shutil
|
||||||
|
|
||||||
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
||||||
level=logging.INFO)
|
level=logging.INFO)
|
||||||
@@ -18,12 +19,24 @@ WARNING = '\033[93m'
|
|||||||
FAIL = '\033[91m'
|
FAIL = '\033[91m'
|
||||||
ENDC = '\033[0m'
|
ENDC = '\033[0m'
|
||||||
|
|
||||||
|
LOCK_DIR = "/home/humbug/humbug-deployments/lock"
|
||||||
|
|
||||||
os.chdir("/home/humbug/humbug")
|
os.chdir("/home/humbug/humbug")
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
oldrev = sys.argv[1]
|
oldrev = sys.argv[1]
|
||||||
newrev = sys.argv[2]
|
newrev = sys.argv[2]
|
||||||
refname = sys.argv[3]
|
refname = sys.argv[3]
|
||||||
|
|
||||||
|
subprocess.check_call(["mkdir", '-p', '/home/humbug/humbug-deployments'])
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir(LOCK_DIR)
|
||||||
|
except OSError:
|
||||||
|
print FAIL + "Deployment already in progress. Please run\n" \
|
||||||
|
+ " update-deployment %s %s %s\n" % (oldrev, newrev, refname) \
|
||||||
|
+ "manually when the current deployment finishes." + ENDC
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
subprocess.check_call(["git", "fetch"], stdout=open('/dev/null', 'w'))
|
subprocess.check_call(["git", "fetch"], stdout=open('/dev/null', 'w'))
|
||||||
subprocess.check_call(["git", "reset", "--hard", refname], stdout=open('/dev/null', 'w'))
|
subprocess.check_call(["git", "reset", "--hard", refname], stdout=open('/dev/null', 'w'))
|
||||||
|
|
||||||
@@ -34,7 +47,6 @@ subprocess.check_call(["find", ".", "-name", "*.pyc", "-delete"], stdout=open('/
|
|||||||
logging.info("Updating static files")
|
logging.info("Updating static files")
|
||||||
subprocess.check_call(["./tools/update-prod-static"])
|
subprocess.check_call(["./tools/update-prod-static"])
|
||||||
|
|
||||||
subprocess.check_call(["mkdir", '-p', '/home/humbug/humbug-deployments'])
|
|
||||||
timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
|
timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
|
||||||
deploy_path = "/home/humbug/humbug-deployments/%s" % (timestamp,)
|
deploy_path = "/home/humbug/humbug-deployments/%s" % (timestamp,)
|
||||||
subprocess.check_call(["cp", '-a', '/home/humbug/humbug', deploy_path])
|
subprocess.check_call(["cp", '-a', '/home/humbug/humbug', deploy_path])
|
||||||
@@ -54,3 +66,5 @@ if '[schema]' in commits:
|
|||||||
print
|
print
|
||||||
print FAIL + "Schema change detected! Please make the appropriate changes manually." + ENDC
|
print FAIL + "Schema change detected! Please make the appropriate changes manually." + ENDC
|
||||||
print
|
print
|
||||||
|
|
||||||
|
shutil.rmtree(LOCK_DIR)
|
||||||
|
|||||||
Reference in New Issue
Block a user