Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: catapult_build/appengine_deploy.py

Issue 2701113002: Migrate to the Google Cloud SDK. (Closed)
Patch Set: Work for both old and new SDKs. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | dashboard/bin/deploy » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # TODO(qyearsley): Add a step to vulcanize each template HTML file. 5 # TODO(qyearsley): Add a step to vulcanize each template HTML file.
6 # TODO(qyearsley): Add a step to put static files in a versioned 6 # TODO(qyearsley): Add a step to put static files in a versioned
7 # directory and modify app.yaml and request_handler as needed. 7 # directory and modify app.yaml and request_handler as needed.
8 8
9 import os 9 import os
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 12
13 from catapult_build import temp_deployment_dir 13 from catapult_build import temp_deployment_dir
14 14
15 15
16 def AppcfgUpdate(paths, app_id, service_name=None): 16 def Deploy(paths, args):
17 """Deploys a new version of an App Engine app from a temporary directory. 17 """Deploys a new version of an App Engine app from a temporary directory.
18 18
19 Args: 19 Args:
20 paths: List of paths to files and directories that should be linked 20 paths: List of paths to files and directories that should be linked
21 (or copied) in the deployment directory. 21 (or copied) in the deployment directory.
22 app_id: The application ID to use. 22 args: Arguments passed to "gcloud app deploy".
23 """ 23 """
24 with temp_deployment_dir.TempDeploymentDir( 24 with temp_deployment_dir.TempDeploymentDir(
25 paths, use_symlinks=False) as temp_dir: 25 paths, use_symlinks=False) as temp_dir:
26 print 'Deploying from "%s".' % temp_dir 26 print 'Deploying from "%s".' % temp_dir
27 27
28 script_path = _FindScriptInPath('appcfg.py') 28 # google-cloud-sdk/bin/gcloud is a shell script, which we can't subprocess
29 # on Windows with shell=False. So, execute the Python script directly.
30 if os.name == 'nt':
31 script_path = _FindScriptInPath('gcloud.cmd')
32 else:
33 script_path = _FindScriptInPath('gcloud')
29 if not script_path: 34 if not script_path:
30 print 'This script requires the App Engine SDK to be in PATH.' 35 print 'This script requires the Google Cloud SDK to be in PATH.'
36 print 'https://cloud.google.com/sdk/'
31 sys.exit(1) 37 sys.exit(1)
32 38
33 subprocess.call([ 39 subprocess.call([script_path, 'app', 'deploy', '--no-promote',
34 sys.executable, 40 '--version', _VersionName()] + args,
35 script_path, 41 cwd=temp_dir)
36 '--application=%s' % app_id,
37 '--version=%s' % _VersionName(),
38 'update',
39 os.path.join(temp_dir, service_name) if service_name else temp_dir,
40 ])
41 42
42 43
43 def _FindScriptInPath(script_name): 44 def _FindScriptInPath(script_name):
44 for path in os.environ['PATH'].split(os.pathsep): 45 for path in os.environ['PATH'].split(os.pathsep):
45 script_path = os.path.join(path, script_name) 46 script_path = os.path.join(path, script_name)
46 if os.path.exists(script_path): 47 if os.path.exists(script_path):
47 return script_path 48 return script_path
48 49
49 return None 50 return None
50 51
51 52
52 def _VersionName(): 53 def _VersionName():
53 is_synced = not _Run(['git', 'diff', 'master', '--no-ext-diff']).strip() 54 is_synced = not _Run(['git', 'diff', 'master', '--no-ext-diff']).strip()
54 deployment_type = 'clean' if is_synced else 'dev' 55 deployment_type = 'clean' if is_synced else 'dev'
55 email = _Run(['git', 'config', '--get', 'user.email']) 56 email = _Run(['git', 'config', '--get', 'user.email'])
56 username = email[0:email.find('@')] 57 username = email[0:email.find('@')]
57 commit_hash = _Run(['git', 'rev-parse', '--short=8', 'HEAD']).strip() 58 commit_hash = _Run(['git', 'rev-parse', '--short=8', 'HEAD']).strip()
58 return '%s-%s-%s' % (deployment_type, username, commit_hash) 59 return '%s-%s-%s' % (deployment_type, username, commit_hash)
59 60
60 61
61 def _Run(command): 62 def _Run(command):
62 proc = subprocess.Popen(command, stdout=subprocess.PIPE) 63 proc = subprocess.Popen(command, stdout=subprocess.PIPE)
63 output, _ = proc.communicate() 64 output, _ = proc.communicate()
64 return output 65 return output
OLDNEW
« no previous file with comments | « no previous file | dashboard/bin/deploy » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698