|
23 | 23 | import tempfile |
24 | 24 | import time |
25 | 25 |
|
| 26 | +import pytz |
| 27 | + |
26 | 28 | from local.butler import appengine |
27 | 29 | from local.butler import common |
28 | 30 | from local.butler import constants |
|
47 | 49 | Version = namedtuple('Version', ['id', 'deploy_time', 'traffic_split']) |
48 | 50 |
|
49 | 51 |
|
50 | | -def now(): |
| 52 | +def now(tz=None): |
51 | 53 | """Used for mocks.""" |
52 | | - return datetime.datetime.now() |
| 54 | + return datetime.datetime.now(tz) |
53 | 55 |
|
54 | 56 |
|
55 | 57 | def _get_services(paths): |
@@ -449,6 +451,27 @@ def _deploy_terraform(config_dir): |
449 | 451 | common.execute(f'rm -rf {terraform_dir}/.terraform*') |
450 | 452 |
|
451 | 453 |
|
| 454 | +def _is_safe_deploy_day(): |
| 455 | + time_now_in_ny = now(pytz.timezone('America/New_York')) |
| 456 | + day_now_in_ny = time_now_in_ny.weekday() |
| 457 | + return day_now_in_ny not in {4, 5, 6} # The days of the week are 0-indexed. |
| 458 | + |
| 459 | + |
| 460 | +def _enforce_safe_day_to_deploy(): |
| 461 | + """Checks that is not an unsafe day (Friday, Saturday, or Sunday) to |
| 462 | + deploy for chrome ClusterFuzz.""" |
| 463 | + |
| 464 | + config = local_config.Config() |
| 465 | + if config.get('weekend_deploy_allowed', True): |
| 466 | + return |
| 467 | + |
| 468 | + if not _is_safe_deploy_day(): |
| 469 | + raise RuntimeError('Cannot deploy Fri-Sun to this CF instance except for ' |
| 470 | + 'urgent fixes. See b/384493595. If needed, temporarily ' |
| 471 | + 'delete+commit this. You are not too l33t for this ' |
| 472 | + 'rule. Do not break it!') |
| 473 | + |
| 474 | + |
452 | 475 | def _deploy_k8s(config_dir): |
453 | 476 | """Deploys all k8s workloads.""" |
454 | 477 | k8s_dir = os.path.join('infra', 'k8s') |
@@ -498,6 +521,8 @@ def execute(args): |
498 | 521 | print('gsutil not found in PATH.') |
499 | 522 | sys.exit(1) |
500 | 523 |
|
| 524 | + _enforce_safe_day_to_deploy() |
| 525 | + |
501 | 526 | # Build templates before deployment. |
502 | 527 | appengine.build_templates() |
503 | 528 |
|
|
0 commit comments