58
58
parser.add_argument('--branch', required=True)
59
59
parser.add_argument('--stage', required=True)
60
parser.add_argument('--use-project-pool',
61
action='store_true', default=False)
63
61
# Parse known arguments, collect (and augment) the rest as 'mojo_args'.
64
62
args, mojo_args = parser.parse_known_args()
65
if args.use_project_pool and '--project' in mojo_args:
66
print("Error: Cannot specify both --use-project-pool and --project")
70
65
'--branch', args.branch,
76
71
logger = logging.getLogger()
77
72
logger.setLevel(logging.INFO)
79
# Optional remote logging via logstash.
80
logstash_host = os.environ.get('CI_LOGSTASH_HOST')
81
if logstash_host is not None:
85
print('Follow the README instructions for installing '
90
logstash.LogstashHandler(logstash_host, 5959, 1))
92
74
# Deploy new environment if the stage identifier isn't recorded.
93
75
idenfifier_dir = os.path.expanduser('~/ci-cd-identifiers/')
94
76
if not os.path.exists(idenfifier_dir):
101
83
identifier_path = os.path.join(idenfifier_dir, identifier)
102
84
if os.path.exists(identifier_path):
105
# Thomi - 2015-05-28: Transitional code to use the mojo project pool code.
106
# Once this is in production we can make this the default. Until then,
107
# this giant if statement determines if we use the pool or a dedicated
108
# project from the command line:
109
if args.use_project_pool:
110
# use the project pool:
111
pool = MojoProjectPool(
112
MOJO_PROJECT_POOL_DIR,
113
MOJO_PROJECT_POOL_LOCK_DIR
116
with pool.acquire_mojo_project() as project_name:
117
# Register deployment identifier regardless its deployment
118
# status. We don't want to deploy it again.
119
with open(identifier_path, 'w') as fd:
120
fd.write(info + '\n')
122
mojo_args += ['--project', project_name]
123
status = 'SUCCEEDED' if deploy(mojo_args) == 0 else 'FAILED'
124
except NoProjectError:
125
print("No available mojo projects, not deploying.")
126
print("Deployment will be retried next run.")
129
# Don't use the project pool - use whatever was supplied on the CLI:
130
# Register deployment identifier regardless its deployment status.
131
# We don't want to deploy it again.
132
with open(identifier_path, 'w') as fd:
133
fd.write(info + '\n')
134
# `mojo.py` prints additional information to stdout, which is only
135
# recorded locally, for now ...
136
status = 'SUCCEEDED' if deploy(mojo_args) == 0 else 'FAILED'
85
print("Not deploying as this combination of branches has already been")
86
print("deployed. Remove '%s' and retry to override this." % identifier_path)
89
# use the project pool:
90
pool = MojoProjectPool(
91
MOJO_PROJECT_POOL_DIR,
92
MOJO_PROJECT_POOL_LOCK_DIR
95
with pool.acquire_mojo_project() as project_name:
96
# Register deployment identifier regardless its deployment
97
# status. We don't want to deploy it again.
98
with open(identifier_path, 'w') as fd:
101
mojo_args += ['--project', project_name]
102
status = 'SUCCEEDED' if deploy(mojo_args) == 0 else 'FAILED'
103
except NoProjectError:
104
print("No available mojo projects, not deploying.")
105
print("Deployment will be retried next run.")
138
108
# We only log a sucint but descriptive message about the deployment
139
109
# status. This content will be shipped to logstash and be handled