Skip to content

Implementation of "sam build" CLI command#766

Merged
sanathkr merged 19 commits intoaws:developfrom
sanathkr:sambuild
Nov 19, 2018
Merged

Implementation of "sam build" CLI command#766
sanathkr merged 19 commits intoaws:developfrom
sanathkr:sambuild

Conversation

@sanathkr
Copy link
Copy Markdown
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
Copy Markdown
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!!!!!! 🎉🎉🎉🎉🎉

Comment thread samcli/commands/build/command.py Outdated
Comment thread 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
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread samcli/commands/build/command.py Outdated
Comment thread samcli/commands/build/build_context.py Outdated
Comment thread samcli/commands/build/build_context.py Outdated
Comment thread samcli/lib/build/app_builder.py Outdated
Comment thread samcli/lib/build/app_builder.py Outdated
Comment thread samcli/lib/build/app_builder.py
Comment thread samcli/lib/build/app_builder.py
Comment thread samcli/lib/build/app_builder.py Outdated
Copy link
Copy Markdown
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.

Comment thread samcli/commands/_utils/options.py Outdated
import click

_TEMPLATE_OPTION_DEFAULT_VALUE = "template.[yaml|yml]"
_TEMPLATE_SEARCH_PATHS = [
Copy link
Copy Markdown
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.

Comment thread samcli/commands/_utils/options.py Outdated

_TEMPLATE_OPTION_DEFAULT_VALUE = "template.[yaml|yml]"
_TEMPLATE_SEARCH_PATHS = [
os.path.join(".sam", "build", "template.yaml"),
Copy link
Copy Markdown
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 :)

Comment thread samcli/commands/build/build_context.py Outdated
Comment thread samcli/commands/build/build_context.py Outdated
: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
Copy Markdown
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.

Comment thread samcli/lib/build/app_builder.py Outdated
Comment thread samcli/lib/build/app_builder.py
Comment thread samcli/local/docker/lambda_build_container.py
@sanathkr sanathkr changed the title WIP: Implementation of "sam build" CLI command Implementation of "sam build" CLI command Nov 19, 2018
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread samcli/commands/build/command.py
Comment thread samcli/commands/build/command.py
Comment thread samcli/commands/build/command.py
"manifest_dir": "{}/manifest".format(base)
}

if pathlib.PurePath(source_dir) == pathlib.PurePath(manifest_dir):
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread tests/integration/testdata/buildcmd/Python/requirements.txt
"optimizations",
"options")

self.maxDiff = None # Print whole json diff
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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