-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implementation of "sam build" CLI command #766
Conversation
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.
This looks really good! Super excited for this capability to be added!!!!!! 🎉🎉🎉🎉🎉
samcli/commands/build/command.py
Outdated
template): | ||
# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing | ||
|
||
do_cli(template, source_root, build_dir, clean, native) # pragma: no cover |
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.
nit: can we match param order between cli
and do_cli
methods
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.
Done
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.
Shaping up!
Don't forget about docstrings and you should really use Pathlib over os.path. I find it much easier to read and understand when doing Path manipulations.
PS: We really need that class to encapsulate all the Path madness.
samcli/commands/_utils/options.py
Outdated
import click | ||
|
||
_TEMPLATE_OPTION_DEFAULT_VALUE = "template.[yaml|yml]" | ||
_TEMPLATE_SEARCH_PATHS = [ |
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.
Instead. What if you keep the default and have commands pass in the extra resolving that should take priority?
This will simplify resolving and will allow the commands to control the resolve order. For example, package should only care about build and deploy should only care about package (templates). If they don't exist then some other flow would be triggered anyways.
samcli/commands/_utils/options.py
Outdated
|
||
_TEMPLATE_OPTION_DEFAULT_VALUE = "template.[yaml|yml]" | ||
_TEMPLATE_SEARCH_PATHS = [ | ||
os.path.join(".sam", "build", "template.yaml"), |
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.
Consider making this directory bound instead of template.
Also pathlib :)
:return dict: Template data as a dictionary | ||
:raises InvokeContextException: If template file was not found or the data was not a JSON/YAML | ||
""" | ||
# TODO: This method was copied from InvokeContext. Move it into a common folder |
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.
Don't forget about this.
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.
Have some minor comments, but nothing blocking.
Excited for this! 💃
|
||
|
||
def docker_common_options(f): | ||
for option in reversed(docker_click_options()): |
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.
Q: What does reversed really give us?
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.
It allows us to list options in the code in the order it will appear in help text. Just for our convenience.
|
||
class BuildContext(object): | ||
|
||
_BUILD_DIR_PERMISSIONS = 0o755 |
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.
Maybe a comment on why these permissions?
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.
Done
"manifest_dir": "{}/manifest".format(base) | ||
} | ||
|
||
if pathlib.PurePath(source_dir) == pathlib.PurePath(manifest_dir): |
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.
Nice check!
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.
I spent 3 hours debugging an issue that stemmed from not having this check ;)
...init/templates/cookiecutter-aws-sam-hello-python/{{cookiecutter.project_name}}/template.yaml
Show resolved
Hide resolved
process.wait() | ||
|
||
process_stdout = b"".join(process.stdout.readlines()).strip().decode('utf-8') | ||
print(process_stdout) |
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 can probably remove the prints?
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.
I do want to have prints for debugging. pytest prints them only if your test fails
"optimizations", | ||
"options") | ||
|
||
self.maxDiff = None # Print whole json diff |
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.
prolly dont need this?
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, its helpful in debugging when the diff doesn't match up
THANK YOU THANK YOU THANK YOU! As we just started to explore SAM, we quickly bumped into the python packaging crap. |
help="Specify whether CLI should skip pulling down the latest Docker image for Lambda runtime.", | ||
envvar="SAM_SKIP_PULL_IMAGE"), | ||
|
||
click.option('--docker-network', |
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.
Is there a way to pass environment variables to the container ?
Description of changes:
Implementation of #743 -
sam build
command.Implementation is complete. It includes unit and integration tests.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.