Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 122 #128

Merged
merged 2 commits into from Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions cob/cli/docker_cli.py
Expand Up @@ -411,19 +411,27 @@ def _generate_compose_file_from_image(image_name, *, http_port=None):

@docker.command(name='deploy', help='Deploys an dockerized cob app image to the local systemd-based machine')
@click.option('--force', is_flag=True, default=False)
@click.option('--compose-override', 'compose_overrides', multiple=True)
@click.argument('image_name')
def deploy_image(image_name, force):
def deploy_image(image_name, force, compose_overrides):
click.echo(f'Obtaining project information for {image_name}...')
project_name = _get_project_name_from_image(image_name)
unit_template = load_template('systemd_unit')
filename = Path('/etc/systemd/system') / f'{project_name}-docker.service'

for override_file in compose_overrides:
docker_compose_override_file = Path(override_file)
_logger.debug(f'Checking the existance of a docker compose override file under project root {docker_compose_override_file}')
if not docker_compose_override_file.exists():
raise click.ClickException(f'File {docker_compose_override_file} does not exist')

click.echo(f'Writing systemd unit file under {filename}...')
if filename.exists() and not force:
click.confirm(f'{filename} already exists. Overwrite?', abort=True)

tmp_filename = Path(mkdtemp()) / 'systemd-unit'
with tmp_filename.open('w') as f: # pylint: disable=no-member
f.write(unit_template.render(project_name=project_name, image_name=image_name, cob=f'{sys.executable} -m cob.cli.main'))
f.write(unit_template.render(project_name=project_name, image_name=image_name, compose_overrides=compose_overrides, cob=f'{sys.executable} -m cob.cli.main'))

subprocess.check_call(f'sudo -p "Enter password to deploy service" mv {tmp_filename} {filename}', shell=True)
click.echo(f'Starting systemd service {filename.stem}...')
Expand Down
2 changes: 1 addition & 1 deletion cob/templates/systemd_unit.j2
Expand Up @@ -7,7 +7,7 @@ After=docker.service
Type=oneshot
RemainAfterExit=yes
ExecStartPre=-{{cob}} docker stop-image {{image_name}}
ExecStart={{cob}} docker run-image {{image_name}} -d
ExecStart={{cob}} docker run-image {{image_name}} {% for cfile in compose_overrides %} -o {{cfile}} {% endfor %} -d
ExecStop={{cob}} docker stop-image {{image_name}}

[Install]
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.rst
@@ -1,6 +1,7 @@
Changelog
=========

* :feature:`122` Adding docker compose override files to ``cob docker deploy --compose-override``. The new flag can be used multiple times.
* :release:`0.22.0 <04-09-2019>`
* :feautre:`121` Improve environment/config customization
* :feature:`116` Update PyAML version
Expand Down
7 changes: 7 additions & 0 deletions doc/deployment.rst
Expand Up @@ -87,3 +87,10 @@ If your target machine is based on *systemd* (e.g. recent Ubuntu Server releases
$ cob docker deploy your.server.com:4567/myproject:latest

This will pull off the needed information from the Docker image and create appropriate unit files to run your project.



.. note:: cob uses docker-compose for deployment. a docker-compose-override yml file can be provided which is then used as described in `docker-compose overview <https://docs.docker.com/compose/reference/overview/>`_.

To use the above capability, add ``--compose-override <full path to override file>`` to the above ``cob docker deploy`` command.
You can use more than one compose-override files by repeating the flag for each file.