Skip to content

Commit

Permalink
Minor fix & attempt to fix zcat error on macox
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mab committed Jul 9, 2020
1 parent 81631f1 commit ee4930d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 74 deletions.
1 change: 1 addition & 0 deletions pydiploy/require/circus.py
Expand Up @@ -122,6 +122,7 @@ def upstart():
use_jinja=True,
)
fabric.api.sudo('systemctl daemon-reload')
fabtools.systemd.start_and_enable('circus')
# Upstart
else:
#  init files to declare circus as an upstart daemon
Expand Down
2 changes: 2 additions & 0 deletions pydiploy/require/python/utils.py
Expand Up @@ -7,6 +7,7 @@
import fabric
import fabtools
from fabric.api import env

from pydiploy.decorators import do_verbose
from pydiploy.require.system import shell

Expand All @@ -29,6 +30,7 @@ def python_pkg(update=False):
else 'python%s-dev' % env.remote_python_version,
'python2' if env.remote_python_version < 3 else '',
'build-essential',
'python3-dev',
],
update=update,
)
Expand Down
94 changes: 27 additions & 67 deletions pydiploy/require/releases_manager.py
Expand Up @@ -6,9 +6,8 @@

import fabric
import fabtools
from fabric.api import env, hide, warn_only

import pydiploy
from fabric.api import env, hide, warn_only
from pydiploy.decorators import do_verbose


Expand All @@ -19,10 +18,7 @@ def set_current():
"""
fabric.api.sudo(
"ln -nfs %(current_release)s %(current_path)s"
% {
'current_release': env.remote_current_release,
'current_path': env.remote_current_path,
}
% {'current_release': env.remote_current_release, 'current_path': env.remote_current_path,}
)


Expand All @@ -32,22 +28,15 @@ def setup():
Configs stuff for deployement
"""
fabric.api.sudo(
"mkdir -p %(remote_domain_path)s/{releases,shared}"
% {'remote_domain_path': env.remote_project_dir}
)
fabric.api.sudo(
"mkdir -p %(remote_shared_path)s/{config,log}"
% {'remote_shared_path': env.remote_shared_path}
"mkdir -p %(remote_domain_path)s/{releases,shared}" % {'remote_domain_path': env.remote_project_dir}
)
fabric.api.sudo("mkdir -p %(remote_shared_path)s/{config,log}" % {'remote_shared_path': env.remote_shared_path})
# extra symlinks if present in settings
if env.has_key('extra_symlink_dirs'):
for extra_symlink_dir in env.extra_symlink_dirs:
fabric.api.sudo(
"mkdir -p %(remote_shared_path)s/%(shared_dir)s"
% {
'remote_shared_path': env.remote_shared_path,
'shared_dir': os.path.basename(extra_symlink_dir),
}
% {'remote_shared_path': env.remote_shared_path, 'shared_dir': os.path.basename(extra_symlink_dir),}
)

fabric.api.execute(pydiploy.require.system.permissions)
Expand All @@ -65,8 +54,7 @@ def cleanup():
del directories[: env.keep_releases]
env.directories = ' '.join(
[
"%(releases_path)s/%(release)s"
% {'releases_path': env.remote_releases_path, 'release': release}
"%(releases_path)s/%(release)s" % {'releases_path': env.remote_releases_path, 'release': release}
for release in directories
]
)
Expand All @@ -85,18 +73,13 @@ def deploy_code():
tag_requested = fabric.api.prompt('Please specify target tag used: ')
while not pydiploy.require.git.check_tag_exist(tag_requested):
tag_requested = fabric.api.prompt(
'tag %s unknown please specify valid target tag used: '
% fabric.colors.red(tag_requested)
'tag %s unknown please specify valid target tag used: ' % fabric.colors.red(tag_requested)
)

env.tag = tag_requested

env.local_tmp_root_app = os.path.join(
env.local_tmp_dir, '%(application_name)s-%(tag)s' % env
)
env.local_tmp_root_app_package = os.path.join(
env.local_tmp_root_app, env.root_package_name
)
env.local_tmp_root_app = os.path.join(env.local_tmp_dir, '%(application_name)s-%(tag)s' % env)
env.local_tmp_root_app_package = os.path.join(env.local_tmp_root_app, env.root_package_name)

fabric.api.require('tag', provided_by=['tag', 'head'])
fabric.api.require('remote_project_dir', provided_by=env.goals)
Expand All @@ -106,9 +89,7 @@ def deploy_code():
tarball = pydiploy.require.git.archive(
env.application_name,
prefix='%s/' % archive_prefix,
specific_folder=env.remote_repo_specific_folder
if "remote_repo_specific_folder" in env
else "",
specific_folder=env.remote_repo_specific_folder if "remote_repo_specific_folder" in env else "",
tag=env.tag,
remote=env.remote_repo_url,
)
Expand All @@ -120,26 +101,26 @@ def deploy_code():
# use tarball to get commit id
with warn_only():
env.commit_id = fabric.api.local(
'zcat %s | git get-tar-commit-id' % os.path.basename(tarball),
capture=True,
'gunzip -c %s | git get-tar-commit-id' % os.path.basename(tarball), capture=True,
)
fabric.api.local('tar xvf %s' % os.path.basename(tarball))
# add deployed.json file
with open(
'%s/%s_info.json' % (env.local_tmp_root_app, env.application_name), 'w'
) as f:
with open('%s/%s_info.json' % (env.local_tmp_root_app, env.application_name), 'w') as f:
data = {}
data['info'] = [
{
'app_host': env.host_string,
'repo_url': env.remote_repo_url,
'python_version': env.remote_python_version,
'local_user': env.local_user,
'socket_port': env.socket_port,
'tag': env.tag,
'commit_id': env.commit_id,
}
]
if 'python_version' in env:
data['info'][0].update({'python_version': env.python_version})

if 'socket_port' in env:
data['info'][0].update({'socket_port': env.socket_port})

json.dump(data, f)

Expand All @@ -162,18 +143,14 @@ def deploy_code():
'.gitignore',
'.gitattributes',
]
exclude_files += [
'%s/settings/%s.py' % (env.root_package_name, goal) for goal in env.goals
]
exclude_files += ['%s/settings/%s.py' % (env.root_package_name, goal) for goal in env.goals]

if env.has_key('excluded_files'):
exclude_files += env.excluded_files
if env.has_key('cfg_shared_files'):
for cfg_shared_file in env.cfg_shared_files:
cfg_present = fabtools.files.is_file(
path='%s/config/%s'
% (env.remote_shared_path, os.path.basename(cfg_shared_file)),
use_sudo=True,
path='%s/config/%s' % (env.remote_shared_path, os.path.basename(cfg_shared_file)), use_sudo=True,
)
if cfg_present is None:
fabtools.files.upload_template(
Expand Down Expand Up @@ -204,17 +181,11 @@ def deploy_code():

# Wrong repository url (git archive is empty)
if result.return_code == 23:
fabric.api.abort(
fabric.colors.red("Unable to use repository, please check repository url !")
)
fabric.api.abort(fabric.colors.red("Unable to use repository, please check repository url !"))

fabric.api.sudo(
'chown -R %(user)s:%(group)s %(project_dir)s'
% {
'user': env.remote_owner,
'group': env.remote_group,
'project_dir': env.remote_current_release,
}
% {'user': env.remote_owner, 'group': env.remote_group, 'project_dir': env.remote_current_release,}
)
# symlink with new release
fabric.api.execute(symlink)
Expand Down Expand Up @@ -247,16 +218,11 @@ def rollback_code():
# elif nb_releases == 1:
elif nb_releases == 1:

fabric.api.puts(
fabric.colors.red('No rollback only one release found on remote !')
)
fabric.api.puts(fabric.colors.red('No rollback only one release found on remote !'))
else:
fabric.api.sudo(
"rm %(current_path)s && rm -rf %(previous_release)s"
% {
'current_path': env.remote_current_path,
'previous_release': env.remote_current_release,
}
% {'current_path': env.remote_current_path, 'previous_release': env.remote_current_release,}
)


Expand All @@ -269,10 +235,7 @@ def symlink():
# TODO : really usefull ? (eg : for php apps ...)
fabric.api.sudo(
"ln -nfs %(shared_path)s/log %(current_release)s/log"
% {
'shared_path': env.remote_shared_path,
'current_release': env.remote_current_release,
}
% {'shared_path': env.remote_shared_path, 'current_release': env.remote_current_release,}
)

if env.has_key('cfg_shared_files'):
Expand Down Expand Up @@ -304,11 +267,8 @@ def run_tests():
# Runs local unit test
authorized_commands = ['tox']
if env.run_tests_command in authorized_commands:
with fabric.api.lcd(
'%s/%s-%s/' % (env.local_tmp_dir, env.application_name, env.tag.lower())
):
with fabric.api.lcd('%s/%s-%s/' % (env.local_tmp_dir, env.application_name, env.tag.lower())):
fabric.api.local(env.run_tests_command)
else:
fabric.api.abort(
fabric.colors.red("wrong test command. Currently, only tox is supported")
)
fabric.api.abort(fabric.colors.red("wrong test command. Currently, only tox is supported"))

1 change: 0 additions & 1 deletion pydiploy/require/system.py
Expand Up @@ -10,7 +10,6 @@
import fabric
import fabtools
from fabric.api import env

from pydiploy.decorators import do_verbose


Expand Down
2 changes: 1 addition & 1 deletion pydiploy/version.py
@@ -1,3 +1,3 @@
# pydiploy version
__version__ = '1.2.0'
__version__ = '1.2.0.2'
__version_info__ = tuple([int(num) for num in __version__.split('.')])
8 changes: 6 additions & 2 deletions tests/test_require_circus.py
Expand Up @@ -255,7 +255,8 @@ def test_app_circus_conf(self, upload_template):

@patch('fabtools.files.is_dir', return_value=False)
@patch('fabtools.files.upload_template', return_value=Mock())
def test_upstart(self, upload_template, is_systemd):
@patch('fabtools.systemd.start_and_enable', return_value=Mock())
def test_upstart(self, start_and_enable, upload_template, is_systemd):
upstart()

self.assertTrue(upload_template.called)
Expand All @@ -271,7 +272,10 @@ def test_upstart(self, upload_template, is_systemd):
@patch('fabric.api.sudo', return_value=Mock())
@patch('fabtools.files.is_dir', return_value=True)
@patch('fabtools.files.upload_template', return_value=Mock())
def test_upstart_systemd(self, upload_template, is_systemd, mock_reload_daemon):
@patch('fabtools.systemd.start_and_enable', return_value=Mock())
def test_upstart_systemd(
self, start_and_enable, upload_template, is_systemd, mock_reload_daemon
):
upstart()

self.assertTrue(upload_template.called)
Expand Down
2 changes: 1 addition & 1 deletion tools/pydiployfabfile.sublime-snippet
Expand Up @@ -308,7 +308,7 @@ def custom_manage_cmd(cmd):
execute(pydiploy_custom_command, cmd)
]]></content>
<description>Pydiploy fabfile 1.2.0</description>
<description>Pydiploy fabfile 1.2.0.2</description>
<tabTrigger>pydiployfab</tabTrigger>
<scope>source.python</scope>
</snippet>
2 changes: 1 addition & 1 deletion tools/pydiployfabfilebottle.sublime-snippet
Expand Up @@ -296,7 +296,7 @@ def set_up():
execute(pydiploy_set_up)
]]></content>
<description>Pydiploy fabfile bottle 1.2.0</description>
<description>Pydiploy fabfile bottle 1.2.0.2</description>
<tabTrigger>pydiployfabbottle</tabTrigger>
<scope>source.python</scope>
</snippet>
2 changes: 1 addition & 1 deletion tools/pydiployfabfilesimple.sublime-snippet
Expand Up @@ -161,7 +161,7 @@ def post_install_backend():
execute(pydiploy_postinstall_backend)
]]></content>
<description>Pydiploy fabfile simple 1.2.0</description>
<description>Pydiploy fabfile simple 1.2.0.2</description>
<tabTrigger>pydiployfabsimple</tabTrigger>
<scope>source.python</scope>
</snippet>

0 comments on commit ee4930d

Please sign in to comment.