2013-07-09 20:40:51 +02:00
|
|
|
#!/usr/bin/python -u
|
2012-08-31 20:16:50 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2013-04-09 21:18:54 +02:00
|
|
|
import logging
|
2013-04-09 21:51:16 +02:00
|
|
|
import datetime
|
2013-05-13 21:46:01 +02:00
|
|
|
import shutil
|
2013-07-02 17:24:16 +02:00
|
|
|
import time
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2013-10-25 23:46:02 +02:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
2013-11-13 20:57:31 +01:00
|
|
|
from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC, make_deploy_path
|
2013-10-25 23:20:40 +02:00
|
|
|
|
2013-04-09 21:18:54 +02:00
|
|
|
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
|
|
|
level=logging.INFO)
|
|
|
|
|
2013-07-02 17:17:16 +02:00
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print FAIL + "Usage: update-deployment refname" + ENDC
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
refname = sys.argv[1]
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2013-05-13 21:47:09 +02:00
|
|
|
subprocess.check_call(["mkdir", '-p',
|
2013-05-15 23:11:37 +02:00
|
|
|
DEPLOYMENTS_DIR,
|
2013-10-04 19:19:57 +02:00
|
|
|
'/home/zulip/logs'])
|
2013-05-13 21:46:01 +02:00
|
|
|
|
2013-07-02 17:24:16 +02:00
|
|
|
start_time = time.time()
|
|
|
|
got_lock = False
|
|
|
|
while time.time() - start_time < 300:
|
|
|
|
try:
|
|
|
|
os.mkdir(LOCK_DIR)
|
|
|
|
got_lock = True
|
|
|
|
break
|
|
|
|
except OSError:
|
|
|
|
print WARNING + "Another deployment in progress; waiting for lock..." + ENDC
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
if not got_lock:
|
2013-05-13 21:46:01 +02:00
|
|
|
print FAIL + "Deployment already in progress. Please run\n" \
|
2013-10-31 18:44:49 +01:00
|
|
|
+ " %s/current/tools/update-deployment %s\n" % (DEPLOYMENTS_DIR, refname) \
|
2013-05-13 21:46:01 +02:00
|
|
|
+ "manually when the current deployment finishes." + ENDC
|
|
|
|
sys.exit(1)
|
|
|
|
|
2013-11-13 20:57:31 +01:00
|
|
|
deploy_path = make_deploy_path()
|
2013-05-28 23:59:50 +02:00
|
|
|
|
2013-05-29 20:35:02 +02:00
|
|
|
logging.info("Cloning the repository")
|
2013-05-28 23:59:50 +02:00
|
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname,
|
2013-10-07 18:32:26 +02:00
|
|
|
"git@git.zulip.net:eng/zulip.git",
|
2013-05-28 23:59:50 +02:00
|
|
|
deploy_path], stdout=open('/dev/null', 'w'))
|
|
|
|
os.chdir(deploy_path)
|
2012-10-18 05:41:28 +02:00
|
|
|
|
2013-04-09 21:18:54 +02:00
|
|
|
# Update static files
|
|
|
|
logging.info("Updating static files")
|
2013-10-31 18:44:49 +01:00
|
|
|
subprocess.check_call(["./tools/update-prod-static", "--prev-deploy",
|
Reuse minified JS from previous deploys
This is a big change affecting lots of areas:
* Pipeline no longer deals with JS (though it still minifies CSS)
* A new script, tools/minify-js (called from update-prod-static),
minifies JavaScripts
* A command-line argument --prev-deploy, if passed to minify-js or
update-prod-static, is used to copy minified JS from a previous
deploy (i.e., a previous git checkout), if the source files have
not changed
* update-deployment passes --prev-deploy
* Scripts are now included with the minified_js template tag, rather
than Pipeline's compressed_js
Also, as a side benefit of this commit, our Handlebars templates will
no longer be copied into prod-static/ and accessible in production.
Unminification is probably broken, but, per Zev and Trac ticket #1377,
it wasn't working perfectly before this change either.
(Based on code review, this commit has been revised to:
* Warn if git returns an error in minify-js
* Add missing output redirects in update-prod-static
* Use DEPLOY_ROOT instead of manually constructing that directory
* Use old style formatting)
(imported from commit e67722ea252756db8519d5c0bd6a421d59374185)
2013-07-03 22:42:25 +02:00
|
|
|
os.path.join(DEPLOYMENTS_DIR, 'current')])
|
2013-04-09 21:18:54 +02:00
|
|
|
|
|
|
|
logging.info("Restarting server...")
|
2013-10-25 23:20:40 +02:00
|
|
|
subprocess.check_call(["./scripts/restart-server"])
|
2013-04-09 21:51:16 +02:00
|
|
|
|
2013-05-15 23:58:05 +02:00
|
|
|
logging.info("Deployment complete")
|
|
|
|
shutil.rmtree(LOCK_DIR)
|
2012-08-31 20:16:50 +02:00
|
|
|
|
2013-10-31 18:20:07 +01:00
|
|
|
subprocess.check_call(["./scripts/purge-old-deployments"])
|