Skip to content

Use Bespoke Tool Path for dotnet-lambda Commands - #127

Closed
chrisoverzero wants to merge 1 commit into
aws:developfrom
chrisoverzero:feature/tool-path
Closed

Use Bespoke Tool Path for dotnet-lambda Commands#127
chrisoverzero wants to merge 1 commit into
aws:developfrom
chrisoverzero:feature/tool-path

Conversation

@chrisoverzero

Copy link
Copy Markdown

There are situations in which the user's installation of
"Amazon.Lambda.Tools" can be as good as read-only. This installs the
builder's copy of the tool to a known location which is separate from
the user's default global installation.

Resolves: #126

Issue #, if available:

#126

Description of changes:

Adds the concept of a "tool directory" to the settings for dotnetcli. It's currently set to the value of the scratch directory. By doing this, the user's installation of "Amazon.Lambda.Tools" can be treated as read-only, whether it actually is or not.

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

There are situations in which the user's installation of
"Amazon.Lambda.Tools" can be as good as read-only. This installs the
builder's copy of the tool to a known location which is separate from
the user's default global installation.

Resolves: #126
if tool_dir is None:
env = None
else:
env = SubprocessDotnetCLI._merge(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm far from a Python expert, so if I've made a hash of this, please do let me know.

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 have dropped support for running Lambda builder in Python 2.
Let's directly use env.copy().update(...) instead.

Comment thread aws_lambda_builders/workflows/dotnet_clipackage/workflow.py
@sriram-mv

Copy link
Copy Markdown
Contributor

you can use your own custom makefile builder for dotnet runtimes to add additional arguments to the binaries that are being used for building.

Here is an example for using makefile for custom runtimes, but a makefile builder can still be used for officially supported lambda runtimes.

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-custom-runtimes.html

@chrisoverzero

Copy link
Copy Markdown
Author

you can use your own custom makefile builder […]

@sriram-mv I’m sure I can, but that doesn’t change how the builder outright fails on Docker images in which dotnet-lambda is already installed. The sam build process assumes that it owns the installation of dotnet-lambda – even upgrading it if it’s out of date – when that’s commonly not so.

Even if this approach isn’t the best one (and it felt like a kludge as I wrote it), that assumption of ownership is too fragile.

@CoshUS CoshUS left a comment

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.

Thanks for the PR! Added a few comments.
Using local tools should also fully resolve #205

if tool_dir is None:
env = None
else:
env = SubprocessDotnetCLI._merge(

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 have dropped support for running Lambda builder in Python 2.
Let's directly use env.copy().update(...) instead.

LOG.debug("Installing Amazon.Lambda.Tools Global Tool")
self.subprocess_dotnet.run(
['tool', 'install', '-g', 'Amazon.Lambda.Tools'],
['tool', 'install', '--tool-path', self.tool_dir, 'Amazon.Lambda.Tools'],

@CoshUS CoshUS Mar 17, 2022

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.

This would still be a global tool but with a custom path.
https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools

As a global tool in a custom location (also known as a tool-path tool).

The tool binaries are installed in a location that you specify. You can invoke the tool from the installation directory or by providing the directory with the command name or by adding the directory to the PATH environment variable. One version of a tool is used for all directories on the machine.

Maybe we can use local tools instead and check whether a global Amazon.Lambda.Tools is already installed.

As a local tool (applies to .NET Core SDK 3.0 and later).

The tool binaries are installed in a default directory. You invoke the tool from the installation directory or any of its subdirectories. Different directories can use different versions of the same tool.

We should also check whether a global version of the Amazon.Lambda.Tools is already installed and skip over if needed.

@hawflau

hawflau commented Jun 13, 2022

Copy link
Copy Markdown
Contributor

Closing due to inactivity. Feel free to reopen the PR if there's any update

@hawflau hawflau closed this Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build via sam build Fails When "Amazon.Lambda.Tools" Is Installed in Built Docker Container

5 participants