Skip to content

Commit

Permalink
Merge pull request #21 from SohuTech/add-deploy-hooks
Browse files Browse the repository at this point in the history
Add deploy hooks
  • Loading branch information
the5fire authored May 14, 2018
2 parents 090bc44 + 319408e commit 7b68f39
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
9 changes: 6 additions & 3 deletions essay/log.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# coding: utf-8
from os import path
from __future__ import unicode_literals

import sys
import logging.config
from os import path


def init_log(log_dir=None):
if log_dir and not path.exists(log_dir):
msg = u'指定路径不存在:%s' % log_dir
print msg.encode('utf-8')
msg = '指定路径不存在:%s' % log_dir
sys.stdout(msg)
log_dir = None

config = {
Expand Down
9 changes: 5 additions & 4 deletions essay/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding:utf-8
from __future__ import unicode_literals

import re
import sys
Expand Down Expand Up @@ -36,17 +37,17 @@ def main():
if re.match('^[a-zA-Z0-9_]+$', project_name):
create_project(project_name, options.template)
else:
print u'无效工程名: ' + project_name
sys.stdout.write('无效工程名: ' + project_name)
elif len(sys.argv) >= 2 and sys.argv[1] == 'init':
options, args = init_options()
project_name = sys.argv[2]
if re.match('^[a-zA-Z0-9_]+$', project_name):
init_project(project_name, options.template)
else:
print u'无效工程名: ' + project_name
sys.stdout.write('无效工程名: ' + project_name)
elif len(sys.argv) >= 2 and sys.argv[1] == 'pinstall':
if len(sys.argv) == 2 or sys.argv[2] == '-h':
print "es pinstall <package>"
sys.stdout.write("es pinstall <package>")
return

args = sys.argv[1:]
Expand All @@ -55,7 +56,7 @@ def main():
pip.main(args)
else:
if len(sys.argv) == 2 and '-h' in sys.argv:
print help_text
sys.stdout.write(help_text)
pip.main()


Expand Down
14 changes: 11 additions & 3 deletions essay/tasks/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@
@task(default=True)
@parallel(30)
def deploy(version, venv_dir, profile):
"""
发布指定的版本
""" 发布指定的版本,会自动安装项目运行所需要的包
会自动安装项目运行所需要的包
version:build之后的版本
venv_dir:虚拟环境名称
profile:profile参数会传递到supervisord.conf中
"""

if not version:
version = build.get_latest_version()

virtualenv.ensure(venv_dir)

pre_hook = env.DEPLOY_PRE_HOOK
post_hook = env.DEPLOY_POST_HOOK

with virtualenv.activate(venv_dir):
if callable(pre_hook):
pre_hook(version, venv_dir, profile)
supervisor.ensure(project=env.PROJECT, profile=profile)
package.install(env.PROJECT, version)
supervisor.shutdown()
supervisor.start()
if callable(post_hook):
post_hook(version, venv_dir, profile)


@task(default=True)
Expand Down
6 changes: 4 additions & 2 deletions essay/templates/default/__project__/log.py.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# coding: utf-8
from __future__ import unicode_literals

from os import path
import logging.config

def init_log(log_dir=None):
# if log_dir and not path.exists(log_dir):
# msg = u'指定路径不存在:%s' % log_dir
# print msg.encode('utf-8')
# print(msg.encode('utf-8'))
# return

config = {
Expand Down Expand Up @@ -43,4 +45,4 @@ def init_log(log_dir=None):
}
}

logging.config.dictConfig(config)
logging.config.dictConfig(config)
6 changes: 3 additions & 3 deletions essay/templates/default/__project__/main.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class index:
return "Hello, world!"

def main():
print 'version:', settings.__version__
print 'git version:', settings.__git_version__
print 'release time', settings.__release_time__
print('version:', settings.__version__)
print('git version:', settings.__git_version__)
print('release time', settings.__release_time__)

app = web.application(urls, globals())
app.run()
Expand Down

0 comments on commit 7b68f39

Please sign in to comment.