Skip to content

Add support for .NET Core build #80

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

Closed
wants to merge 19 commits into from
Closed

Conversation

normj
Copy link
Member

@normj normj commented Feb 11, 2019

Description of changes:
Add support for building .NET Core Lambda function as part of SAM build.

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

-dvc | --disable-version-check Disable the .NET Core version check. Only for advanced usage.
```

Currently **--framework** is the only required parameter which tells the underlying build process what version of .NET Core to build for.
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this infomation passed in? is it decided by the builder based on the runtime?

Copy link
Member Author

Choose a reason for hiding this comment

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

For most users --framework will be already set in the aws-lambda-tools-defaults.json file so they won't have to do anything. If it is not set then the user would need to specify it on the sam build command line which would get passed into the builder. I tried to follow the examples I saw in the other builders for grabbing options that were passed on the commandline.

Copy link
Contributor

Choose a reason for hiding this comment

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

So this is currently not supported in SAM CLI, although the correct plumbing exists thru options property. See #4

How big of a requirement is this? Do you know the fraction of users that use parameters vs .json file to pass this value?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not big requirement since the framework will most likely be set through the *.json file. It is a good thing to have for the future. As long as the code is doing it in the way SAM envisions this being handled in the future is all that I require now. We should make sure SAM init version of a .NET Core project includes the json file like all of the rest of our .NET tooling does.

I also might update the Amazon.Lambda.Tools to auto detect the framework based on the project file. If/when I do this work SAM build would pull that change in automatically due to the nature of this PR always updating the version of Amazon.Lambda.Tools.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, in the future when we add add sam build --debug mode, we would want to pass this over to lambda-builders, and the dotnet workflow to pick it up as the configuration.

This would also yield a conversation on which is higher priority, the flag or the information in the json config file.

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing Amazon.Lambda.Tools .NET Core Global tool that this wraps around already has the rule that if a value is specified in the command line it overrides any setting in the json file. I would expect that rule to apply from sam build as well.

The tool is installed by executing the command `dotnet tool install -g Amazon.Lambda.Tools` This will install the
tool from [NuGet](https://www.nuget.org/packages/Amazon.Lambda.Tools/) the .NET package management system.

To keep the tool updated the command `dotnet tool update -g Amazon.Lambda.Tools` will be executed if the install
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!


#### Output

The output of `dotnet lambda package` command is a zip archive that consumers can then deploy to Lambda. For SAM build
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this is a requirement mainly stemming from the ability to customize the zip file later during package. See this discussion - #69 (comment)

-dvc | --disable-version-check Disable the .NET Core version check. Only for advanced usage.
```

Currently **--framework** is the only required parameter which tells the underlying build process what version of .NET Core to build for.
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is currently not supported in SAM CLI, although the correct plumbing exists thru options property. See #4

How big of a requirement is this? Do you know the fraction of users that use parameters vs .json file to pass this value?

class GlobalToolInstallAction(BaseAction):

"""
A Lambda Builder Action which runs bundle install in order to build a full Gemfile.lock
Copy link
Contributor

Choose a reason for hiding this comment

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

docstring update

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated


class RunPackageAction(BaseAction):
"""
A Lambda Builder Action which vendors dependencies to the vendor/bundle directory.
Copy link
Contributor

Choose a reason for hiding this comment

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

docstring update

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated


def execute(self):
try:
LOG.debug("Running bundle install --deployment in %s", self.source_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

log statement needs update

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir,
source_dir,
runtime=self.runtime,
options={"--framework": "netcoreapp2.1", "--configuration": "Debug"})
Copy link
Contributor

Choose a reason for hiding this comment

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

we currently need a way to support args support in aws-sam-cli, i.e flags passed to sam build

Copy link
Member Author

@normj normj Feb 15, 2019

Choose a reason for hiding this comment

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

Is it fine to leave this hear till sam build adds support for passing args?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah think thats fine.

"""
NAME = "DotnetCliPackageBuilder"

CAPABILITY = Capability(language="dotnet",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add resolver and validator for the executables used by the workflow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have an example of what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a resolver to make sure the dotnet CLI is installed.

A validator is not needed because the dotnet CLI has its own built in versioning system to match the available installed .NET SDK with the selected project. A validator would just duplicate that work and possibly get in the way.

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.

changes to travis might be required to get the tests to pass on linux, to install dotnet executable beforehand.

I see windows is passing! woohoo 💯 , we may still need some more test coverage to get the overall gate to pass though after installing dotnet on the travis boxes.

-dvc | --disable-version-check Disable the .NET Core version check. Only for advanced usage.
```

Currently **--framework** is the only required parameter which tells the underlying build process what version of .NET Core to build for.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, in the future when we add add sam build --debug mode, we would want to pass this over to lambda-builders, and the dotnet workflow to pick it up as the configuration.

This would also yield a conversation on which is higher priority, the flag or the information in the json config file.

@sriram-mv
Copy link
Contributor

This looks good to me! All gates pass. Just a follow up question, do we need a test with any tough to build dependencies in the builder?

# The package command contains lots of useful information on how the package was created and
# information when the package command was not successful. For that reason the output is
# always written to the output to help developers diagnose issues.
sys.stdout.write(out.decode('utf8').strip())
Copy link
Contributor

Choose a reason for hiding this comment

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

Also can we write this to Logs instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are logs written to stdout by default during SAM build? I want users to see that information.

@normj
Copy link
Member Author

normj commented Feb 26, 2019

Closing in favor of a new clean branch

@normj normj closed this Feb 26, 2019
hawflau added a commit to hawflau/aws-lambda-builders that referenced this pull request Nov 14, 2023
* Add support for java21

* fix black formatting

* update gha to use java 21

* add missing java 21 testing projects

* use gradle-8.4 for java21

---------

Co-authored-by: Mohamed ElAsmar <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Nov 15, 2023
* Add support for java21

* fix black formatting

* update gha to use java 21

* add missing java 21 testing projects

* use gradle-8.4 for java21

---------

Co-authored-by: Mohamed ElAsmar <[email protected]>
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.

3 participants