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

Introduce command to stop local containers #157

Closed
wants to merge 1 commit into from
Closed

Introduce command to stop local containers #157

wants to merge 1 commit into from

Conversation

cenouralm
Copy link
Contributor

No description provided.

@cenouralm cenouralm self-assigned this Sep 16, 2020
@cenouralm cenouralm linked an issue Sep 16, 2020 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Sep 16, 2020

Coverage Status

Coverage decreased (-0.1%) to 86.056% when pulling 69e7251 on cenouralm:stop_local into be04439 on inveniosoftware:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 85.907% when pulling e988e9e on cenouralm:stop_local into d03def3 on inveniosoftware:master.

@cenouralm cenouralm marked this pull request as ready for review September 16, 2020 15:55
Comment on lines 125 to 127
@click.option('--stop', default=False, is_flag=True,
help='Stop containers')
def run(stop):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing IRL, the stop should be a separate command, not a flag on the run. (We we called option b when we talked)

Suggested change
@click.option('--stop', default=False, is_flag=True,
help='Stop containers')
def run(stop):
def run():

"""Run development server and celery queue."""
if stop:
command = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a stop_containers function in the docker_helper file. It might be good using that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

@cenouralm cenouralm marked this pull request as draft September 17, 2020 09:49
invenio_cli/cli.py Outdated Show resolved Hide resolved
invenio_cli/cli.py Outdated Show resolved Hide resolved
@@ -295,7 +295,7 @@ def test_localcommands_run(
fake_cli_config):
commands = LocalCommands(fake_cli_config)

commands.run()
commands.run(stop=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not re-reviewing tests. Not updated as mentioned IRL.

invenio_cli/helpers/commands.py Outdated Show resolved Hide resolved
@@ -228,6 +228,15 @@ def demo(self):
command = ['pipenv', 'run', 'invenio', 'rdm-records', 'demo']
subprocess.run(command, check=True)

def stop(self):
"""Stops containers."""
docker_helper = DockerHelper(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This is more a comment for future work:

We should try to find a common way of using docker_helper. The containerize command has an instance as attribute and the local commands instantiate it each time is needed. It might be able to be refactored into something common.

local=True)

docker_helper.stop_containers()
click.secho('Stopped containers...', fg='green')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Full OCD]: IMO the ... are sort of an indication of something going on - in progress -. Therefore, I would use if for the messages before the action. e.g. "creating indexes...".

For messages of things that are already finished I would not put the ... For example

click.secho('Virtual environment destroyed', fg='green')

If you decide to change this (totally up to yo, as in, this is my OCD). Could you change the Destroyed ... messages too and remove the ...

Suggested change
click.secho('Stopped containers...', fg='green')
click.secho('Containers stopped', fg='green')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll do that :)

patched_docker_helper, patched_subprocess, fake_cli_config):
commands = LocalCommands(fake_cli_config)

# Needed to fake call to docker-compose --version but not call
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doubt: What does this comment applies to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was made when developing the test_localcommands_destroy and I can't really remember the reason why was done.

@@ -312,6 +312,28 @@ def test_localcommands_run(
assert patched_subprocess.Popen.mock_calls == expected_calls


@patch('invenio_cli.helpers.commands.subprocess')
@patch('invenio_cli.helpers.docker_helper.subprocess')
def test_localcommands_stop(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moderate: There is no assertion in this test, in case something does not work at desired what kind of feedback do we get when running tests? How is it notified? stacktrace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit addressed the missing assertion 6380144

@cenouralm cenouralm marked this pull request as ready for review September 18, 2020 13:27
@lnielsen lnielsen added this to In Review in InvenioRDM October Board Oct 13, 2020
@ppanero ppanero removed this from In Review in InvenioRDM October Board Oct 13, 2020
Copy link
Contributor

@fenekku fenekku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying Lars's trick is the way to go - will cause some refactoring of this PR but it's for the best.

Comment on lines 58 to 67
def stop_containers(self):
"""Stop currently running containers."""
command = ['docker-compose',
'--file', 'docker-compose.full.yml', 'stop']

if self.local:
command[2] = 'docker-compose.yml'
command = [
'docker-compose',
'--file',
'docker-compose.yml' if self.local else 'docker-compose.full.yml',
'stop'
]

subprocess.call(command)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the same trick @lnielsen mentioned can be used for the stop command too (It works. I learned something!):

def stop_containers(self):
    """Stop currently running containers."""
    command = [
        'docker-compose',
        '--file',
        'docker-compose.full.yml',
        'stop'
    ]
    subprocess.call(command)

Testing becomes much easier and uniform too.

- REQUIREMENTS=devel

python:
- "3.6"
# Lower than 3.6.9 distutils imports `imp` and throws a deprecation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the case for this library?

@cenouralm
Copy link
Contributor Author

cenouralm commented Oct 19, 2020

The successor of this PR is #167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants