Skip to content

Commit c1424e3

Browse files
authored
Merge pull request #35 from typecode/develop
Version 0.4.2
2 parents 0d5c74a + c3a9611 commit c1424e3

File tree

3 files changed

+53
-19
lines changed

3 files changed

+53
-19
lines changed

sykle/__init__.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# __init__.py
22

3-
__version__ = '0.4.1'
3+
__version__ = '0.4.2'
44

55

66
class Sykle():
@@ -12,7 +12,7 @@ class Sykle():
1212
def __init__(
1313
self, project_name='sykle-project',
1414
unittest_config=[], e2e_config=[],
15-
predeploy_config=[], debug=False,
15+
predeploy_config=[], preup_config=[], debug=False,
1616
aliases={}
1717
):
1818
"""
@@ -22,6 +22,7 @@ def __init__(
2222
unittest_config (array[dict]): Array of unittest configs
2323
e2e_config (array[dict]): Array of end to end test configs
2424
predeploy_config (array[dict]): Array with predeploy steps
25+
preup_config (array[dict]): Array with preup steps
2526
aliases (dict): Dictionary defining custom commands
2627
"""
2728
from .call_subprocess import call_subprocess
@@ -31,6 +32,7 @@ def __init__(
3132
self.project_name = project_name
3233
self.e2e_config = e2e_config
3334
self.predeploy_config = predeploy_config
35+
self.preup_config = preup_config
3436
self.unittest_config = unittest_config
3537

3638
def _read_env_file(self, env_file):
@@ -138,6 +140,7 @@ def build(self, docker_type='dev', docker_vars={}):
138140

139141
def up(self, docker_type='dev'):
140142
"""Starts up relevant docker compose services"""
143+
self.preup(docker_type=docker_type)
141144
self.dc(
142145
input=['up', '--build', '--force-recreate'],
143146
docker_type=docker_type
@@ -192,31 +195,47 @@ def deployment_ssh(self, target):
192195
"""Opens an ssh connection to the deployment"""
193196
return self.call_subprocess(['ssh', target], debug=self.debug)
194197

198+
def preup(self, docker_type):
199+
for config in self.preup_config:
200+
if config.get('service'):
201+
self.dc_run(
202+
input=config['command'].split(' '),
203+
service=config['service'],
204+
docker_type=docker_type,
205+
)
206+
else:
207+
self.call_subprocess(config['command'].split(' '))
208+
195209
def predeploy(self, env_file=None, docker_vars={}):
196210
for config in self.predeploy_config:
197-
self.dc_run(
198-
input=config['command'].split(' '),
199-
service=config['service'],
200-
docker_type='prod-build',
201-
env_file=env_file,
202-
docker_vars=docker_vars
203-
)
211+
if config.get('service'):
212+
self.dc_run(
213+
input=config['command'].split(' '),
214+
service=config['service'],
215+
docker_type='prod-build',
216+
env_file=env_file,
217+
docker_vars=docker_vars
218+
)
219+
else:
220+
self.call_subprocess(config['command'].split(' '))
204221

205222
def deploy(self, target, env_file=None, docker_vars={}):
206223
"""Deploys docker images/static assets and starts services"""
207224
self.predeploy(env_file=env_file, docker_vars=docker_vars)
208225
self.push(docker_vars=docker_vars)
209226
self.deployment_cp([env_file], target=target, dest='~/.env')
210227
self.deployment_cp(['docker-compose.prod.yml'], target=target)
211-
# TODO: might want to make this optional
212-
self.deployment_exec(
213-
['docker', 'system', 'prune', '-a', '--force'], target=target
214-
)
215228

216229
command = self._remote_docker_compose_command(docker_vars)
217230
self.deployment_exec(command + ['pull'], target=target)
218231
self.deployment_exec(command + ['up', '-d'], target=target)
219232

233+
# cleans up docker system
234+
# TODO: might want to make this optional
235+
self.deployment_exec(
236+
['docker', 'system', 'prune', '-a', '--force'], target=target
237+
)
238+
220239
def run_alias(self, alias, input=[], docker_type=None, docker_vars={}, target=None):
221240
alias_config = self.aliases.get(alias)
222241
is_exec = alias_config.get('exec', False)

sykle/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def main():
160160
unittest_config=config.unittest,
161161
e2e_config=config.e2e,
162162
predeploy_config=config.predeploy,
163+
preup_config=config.preup,
163164
aliases=config.aliases,
164165
debug=args['--debug']
165166
)

sykle/config.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,22 @@ class Config():
3636
"command": "behave"
3737
}
3838
],
39-
// list of commands to invoke before deploying (run sequentially)
39+
// list of commands to invoke before deploy (run sequentially)
4040
"predeploy": [
4141
{
4242
"service": "django",
4343
"command": "django-admin collectstatic --no-input"
44+
},
45+
{
46+
// if no service is specified, will run as normal bash command
47+
"command": "aws ecr get-login --region us-east-1"
48+
}
49+
],
50+
// list of commands to invoke before up (run sequentially)
51+
"preup": [
52+
{
53+
// if no service is specified, will run as normal bash command
54+
"command": "syk down"
4455
}
4556
],
4657
// deployment to use by default (must be listed in deployments section)
@@ -152,6 +163,7 @@ def init(enable_print=False):
152163
("unittest", [{"service": None, "command": None}]),
153164
("e2e", [{"service": None, "command": None}]),
154165
("predeploy", []),
166+
("preup", []),
155167
("default_deployment", "staging"),
156168
("deployments", {
157169
"staging": {
@@ -207,10 +219,11 @@ def interpolate_env_values(dict, env):
207219
with their associated env vars
208220
"""
209221
new_dict = {}
210-
for (k, v) in dict.items():
211-
if v is None or len(v) == 0:
222+
for (k, _v) in dict.items():
223+
v = '' if _v is None else str(_v)
224+
if len(v) == 0:
212225
new_dict[k] = ''
213-
elif not isinstance(v, str) or v[0] != '$':
226+
elif v[0] != '$':
214227
new_dict[k] = v
215228
else:
216229
new_dict[k] = env.get(v[1:], '')
@@ -225,8 +238,8 @@ def interpolate_env_values_from_file(dict, env_file):
225238

226239
def __init__(
227240
self, project_name, default_service, default_deployment, plugins={},
228-
aliases={}, unittest=[], e2e=[], predeploy=[], deployments={},
229-
version=None,
241+
aliases={}, unittest=[], e2e=[], predeploy=[], preup=[],
242+
deployments={}, version=None,
230243
):
231244
self.version = version
232245
self.project_name = project_name
@@ -236,6 +249,7 @@ def __init__(
236249
self.unittest = unittest
237250
self.e2e = e2e
238251
self.predeploy = predeploy
252+
self.preup = preup
239253
self.deployments = deployments
240254
self.plugins = plugins
241255

0 commit comments

Comments
 (0)