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
Compose services #45231
Compose services #45231
Conversation
re-run lint |
Now that #45190 has been merged, we should wait for @rallytime to merge that forward into develop, and then this should be rebased so that we use salt.utils.yaml.dump()
to do the yaml dumping.
@obeleh The merge forward should be completed now. Can you address the comments above? |
Ok switched yaml implementation. I hoped however that I could change this: services[service_name]['image'] = str('{0}:{1}'.format(image, tag)) into this: services[service_name]['image'] ='{0}:{1}'.format(image, tag) But I still get this error:
|
I'll work on the yaml dumper, we shouldn't be adding that YAML tag in our custom dumper.
None, None) | ||
try: | ||
with salt.utils.files.fopen(file_path, 'r') as fl: | ||
loaded = yaml.load(fl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using safe_load here.
None, None) | ||
else: | ||
try: | ||
loaded_definition = yaml.load(definition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using safe_load here.
def __write_docker_compose(path, docker_compose): | ||
def __load_docker_compose(path): | ||
''' | ||
Read the compose file and load its' contents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no apostrophe necessary after its
Oh sorry, I marked this PR as approved but I had a few changes I wanted to see made before merging. |
Accidentally marked as approved. See my earlier comments for a few changes that should be made.
It turns out that using a regular dump here uses PyYAML's default dumper. Using our custom safe dumper, that YAML tag should not be present in the dumped output.
salt/modules/dockercompose.py
Outdated
:return: | ||
''' | ||
try: | ||
dumped = yaml.dump(content, indent=2, default_flow_style=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this to safe_dump
.
salt/modules/dockercompose.py
Outdated
'Service {0} did not contain the variable "image"'.format(service_name), | ||
None, None) | ||
image = services[service_name]['image'].split(':')[0] | ||
services[service_name]['image'] = str('{0}:{1}'.format(image, tag)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use safe_dump
above, you can replace this with '{0}:{1}'.format(image, tag)
.
@obeleh Can you come back to this PR and address the comments above? |
Sorry for the delay. At the time you asked for the change I was busy with other things. I've tested the change you suggested and it works. Hope everything is fine now :) |
re-run lint |
@obeleh There's a very small lint error here: https://jenkins.saltstack.com/job/PR/job/salt-pr-lint-n/19740/violations/file/salt/modules/dockercompose.py/ Can you fix that? |
What does this PR do?
Ads functionality to manage docker-compose service definitions as proposed in #44911
What issues does this PR fix or reference?
#44911
New Behavior
the following salt calls:
Different in the behaviour with all other salt calls in this module is that this has to do a yaml.dumps because we're modifying content and not modifying strings. I've explicitly stated in the docstrings that this is the case:
This wil re-write your yaml file. Comments will be lost. Indentation is set to 2 spaces
Tests written?
No
Commits signed with GPG?
Yes