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

Implementation of "sam build" CLI command #766

Merged
merged 19 commits into from
Nov 19, 2018
Merged

Conversation

sanathkr
Copy link
Contributor

@sanathkr sanathkr commented Nov 14, 2018

Description of changes:
Implementation of #743 - sam build command.

Implementation is complete. It includes unit and integration tests.

sambuild

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@jfuss jfuss left a 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!!!!!! 🎉🎉🎉🎉🎉

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@jfuss jfuss left a 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.

import click

_TEMPLATE_OPTION_DEFAULT_VALUE = "template.[yaml|yml]"
_TEMPLATE_SEARCH_PATHS = [
Copy link
Contributor

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.


_TEMPLATE_OPTION_DEFAULT_VALUE = "template.[yaml|yml]"
_TEMPLATE_SEARCH_PATHS = [
os.path.join(".sam", "build", "template.yaml"),
Copy link
Contributor

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
Copy link
Contributor

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.

@sanathkr sanathkr changed the title WIP: Implementation of "sam build" CLI command Implementation of "sam build" CLI command Nov 19, 2018
Copy link
Contributor

@sriram-mv sriram-mv left a 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()):
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice check!

Copy link
Contributor Author

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 ;)

process.wait()

process_stdout = b"".join(process.stdout.readlines()).strip().decode('utf-8')
print(process_stdout)
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

prolly dont need this?

Copy link
Contributor Author

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

@sanathkr sanathkr merged commit 1b92321 into aws:develop Nov 19, 2018
@mvanbaak
Copy link
Contributor

THANK YOU THANK YOU THANK YOU!

As we just started to explore SAM, we quickly bumped into the python packaging crap.
You saved my day with this PR!

help="Specify whether CLI should skip pulling down the latest Docker image for Lambda runtime.",
envvar="SAM_SKIP_PULL_IMAGE"),

click.option('--docker-network',
Copy link
Contributor

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 ?

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.

5 participants