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

feat(core): pre-fetch provider tools and make tools a native feature #1858

Merged
merged 2 commits into from
Jun 9, 2020

Conversation

edvald
Copy link
Collaborator

@edvald edvald commented Jun 4, 2020

What this PR does / why we need it:

This adds the notion of tools to the plugin framework, and a command to
allow using and pre-fetching these tools.

The primary motivation was to allow pre-fetching the tools as part of
our container builds, as well as to make it easy for users to do the
same in their custom CI setups with Garden.

The garden tools command is also handy since it allows users to easily
use the exact same tools as Garden's providers fetch and use.

To pre-fetch the tools, we add a garden util fetch-tools command,
which fetches all tools for the configured providers in the current
project, or for all registered providers if the --all flag is set.

Notes:

  • We now always fetch the docker binary on use, instead of checking for
    its existence locally. This avoids some code complexity and makes sure
    we always use the expected version. The downside should be mitigated
    by the pre-fetching in built containers, and the fetch-tools command.
  • We really need to reduce the number of tools and versions we bundle
    before we release 0.12. The container image sizes are too large atm.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Any feedback on the design/usability here would be good, and maybe give it a spin, see if it all works as expected.

@edvald edvald added this to the 0.12.0 milestone Jun 4, 2020
Copy link
Collaborator

@eysi09 eysi09 left a comment

Choose a reason for hiding this comment

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

Had a few comments/questions, but otherwise looks great!

Some additional questions:

Are we verifying anywhere, either explicitly or implicitly, that the tool remote URLs are correct across all platforms?

Is there any concern that the tools will conflict with previous installations? For example, if you have two Docker installations or install a tool via Chocolate and again via Garden.

You mentioned the images where too bloated, how do we plan on addressing that?

docs/reference/commands.md Show resolved Hide resolved
conflicts.

When there are name conflicts and a plugin name is not specified, the preference is
for defined by configured providers in the current project (if applicable), and then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be: the preference is defined by the dependency order of configured providers, right?

In any case the for shouldn't be there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually it's supposed to be "the preference is for tools defined by configured providers". I'll fix and likely rephrase for better clarity.

@@ -126,15 +125,12 @@ export class AnalyticsHandler {
private ciName = ci.name
private systemConfig: SystemInfo
private isCI = ci.isCI
private sessionId: string
private sessionId: string | null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we changing the behaviour? Shouldn't the class throw if the session id is missing instead of just failing silently?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kept getting errors in unit tests. As far as I can tell this case (null sessionId) only comes up there. I'm open to a separate fix for that, but I couldn't quite grok why this was how it was so I'd ask you or @thsig to investigate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah the sessionId appears to be created in the CLI class and passed to BufferedEventStream and the Garden class. It doesn't look its really used by the Garden class though, so perhaps we could just pass it directly to the AnalyticsHandler class.

In any case, I don't think we should change the behaviour of the AnalyticsHandler class to accommodate the unit tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If the AnalyticsHandler is never supposed to receive a null sessionId, it should imo be caught at compile time. I'm unclear on why there's a runtime guard there then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be clear, I wasn't trying to get my tests to pass, other unrelated tests kept failing. I can revert this, but then we'd need a separate PR to fix the failing tests.

@@ -247,7 +243,7 @@ export class AnalyticsHandler {
* Used internally to check if a users has opted-in or not.
*/
private analyticsEnabled(): boolean {
if (process.env.GARDEN_DISABLE_ANALYTICS === "true") {
if (!this.sessionId || process.env.GARDEN_DISABLE_ANALYTICS === "true") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

See my comment above. A missing session ID shouldn't signify a disabled analytics imo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a valid scenario where the session ID is null but we want events to be sent?

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO the issue is that the sessionId shouldn't be null to begin with. That's why before this commit, the AnalyticsHandler would just throw if it was missing.

help = "Access tools included by providers."
cliOnly = true

// FIXME: We need this while we're still resolving providers in the AnalyticsHandler
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where are we doing that? When generating the metadata we call getRawModuleConfigs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do now, not when this was written originally. You fixed that quite recently. Comment is out of date, but the flag remains necessary, so I'll remove the comment.

garden-service/src/commands/tools.ts Show resolved Hide resolved
garden-service/src/commands/util.ts Show resolved Hide resolved
cwd?: string
env?: { [key: string]: string }
log: LogEntry
timeout?: number
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is seconds, right? Should we perhaps make it explicit my naming it timeoutSec? Or stay consistent with execa and use milliseconds as well, and name the variable timeoutMs?

Or do have we consistently use seconds in throughout the codebase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is unchanged from previous code, but yeah I wouldn't mind making the unit explicit everywhere.

garden-service/src/util/ext-tools.ts Show resolved Hide resolved
garden-service/src/util/ext-tools.ts Show resolved Hide resolved
@edvald
Copy link
Collaborator Author

edvald commented Jun 9, 2020

Are we verifying anywhere, either explicitly or implicitly, that the tool remote URLs are correct across all platforms?

That would be good. We haven't done that so far, but it would be feasible to create an integ test suite that does that, or something in CI.

Is there any concern that the tools will conflict with previous installations? For example, if you have two Docker installations or install a tool via Chocolate and again via Garden.

Not really, those won't conflict. But we will indeed fetch Docker even if it's already installed.

You mentioned the images where too bloated, how do we plan on addressing that?

I added a couple of to-do items in our 0.12 checklist, for dropping old tools that we don't aim to support anymore. That's a big chunk. Then there are smaller improvements we could make, e.g. make it possible to drop files that we don't use in archives we extract.

@eysi09
Copy link
Collaborator

eysi09 commented Jun 9, 2020

Thanks for the answers, make sense. Do you want to look into the tests now, or just the next time we actually tamper with the tool URLs?

@edvald
Copy link
Collaborator Author

edvald commented Jun 9, 2020

We already test most of them implicitly in container builds, integ/e2e tests and Windows tests, so I'm not sure I'd want to get into more explicit tool tests. Until a new reason comes up, that is.

edvald added 2 commits June 9, 2020 20:01
This adds the notion of tools to the plugin framework, and a command to
allow using and pre-fetching these tools.

The primary motivation was to allow pre-fetching the tools as part of
our container builds, as well as to make it easy for users to do the
same in their custom CI setups with Garden.

The `garden tools` command is also handy since it allows users to easily
use the exact same tools as Garden's providers fetch and use.

To pre-fetch the tools, we add a `garden util fetch-tools` command,
which fetches all tools for the configured providers in the current
project, or for all registered providers if the `--all` flag is set.

Notes:
- We now always fetch the docker binary on use, instead of checking for
  its existence locally. This avoids some code complexity and makes sure
  we always use the expected version. The downside should be mitigated
  by the pre-fetching in built containers, and the fetch-tools command.
- We really need to reduce the number of tools and versions we bundle
  before we release 0.12. The container image sizes are too large atm.
@edvald edvald merged commit 65e3251 into 0.12 Jun 9, 2020
@edvald edvald deleted the tools-command branch June 9, 2020 18:30
edvald added a commit that referenced this pull request Jun 21, 2020
…1858)

* feat(core): pre-fetch provider tools and make tools a native feature

This adds the notion of tools to the plugin framework, and a command to
allow using and pre-fetching these tools.

The primary motivation was to allow pre-fetching the tools as part of
our container builds, as well as to make it easy for users to do the
same in their custom CI setups with Garden.

The `garden tools` command is also handy since it allows users to easily
use the exact same tools as Garden's providers fetch and use.

To pre-fetch the tools, we add a `garden util fetch-tools` command,
which fetches all tools for the configured providers in the current
project, or for all registered providers if the `--all` flag is set.

Notes:
- We now always fetch the docker binary on use, instead of checking for
  its existence locally. This avoids some code complexity and makes sure
  we always use the expected version. The downside should be mitigated
  by the pre-fetching in built containers, and the fetch-tools command.
- We really need to reduce the number of tools and versions we bundle
  before we release 0.12. The container image sizes are too large atm.
eysi09 pushed a commit that referenced this pull request Jun 24, 2020
…1858)

* feat(core): pre-fetch provider tools and make tools a native feature

This adds the notion of tools to the plugin framework, and a command to
allow using and pre-fetching these tools.

The primary motivation was to allow pre-fetching the tools as part of
our container builds, as well as to make it easy for users to do the
same in their custom CI setups with Garden.

The `garden tools` command is also handy since it allows users to easily
use the exact same tools as Garden's providers fetch and use.

To pre-fetch the tools, we add a `garden util fetch-tools` command,
which fetches all tools for the configured providers in the current
project, or for all registered providers if the `--all` flag is set.

Notes:
- We now always fetch the docker binary on use, instead of checking for
  its existence locally. This avoids some code complexity and makes sure
  we always use the expected version. The downside should be mitigated
  by the pre-fetching in built containers, and the fetch-tools command.
- We really need to reduce the number of tools and versions we bundle
  before we release 0.12. The container image sizes are too large atm.
edvald added a commit that referenced this pull request Jun 24, 2020
…1858)

* feat(core): pre-fetch provider tools and make tools a native feature

This adds the notion of tools to the plugin framework, and a command to
allow using and pre-fetching these tools.

The primary motivation was to allow pre-fetching the tools as part of
our container builds, as well as to make it easy for users to do the
same in their custom CI setups with Garden.

The `garden tools` command is also handy since it allows users to easily
use the exact same tools as Garden's providers fetch and use.

To pre-fetch the tools, we add a `garden util fetch-tools` command,
which fetches all tools for the configured providers in the current
project, or for all registered providers if the `--all` flag is set.

Notes:
- We now always fetch the docker binary on use, instead of checking for
  its existence locally. This avoids some code complexity and makes sure
  we always use the expected version. The downside should be mitigated
  by the pre-fetching in built containers, and the fetch-tools command.
- We really need to reduce the number of tools and versions we bundle
  before we release 0.12. The container image sizes are too large atm.
edvald added a commit that referenced this pull request Jun 24, 2020
…1858)

* feat(core): pre-fetch provider tools and make tools a native feature

This adds the notion of tools to the plugin framework, and a command to
allow using and pre-fetching these tools.

The primary motivation was to allow pre-fetching the tools as part of
our container builds, as well as to make it easy for users to do the
same in their custom CI setups with Garden.

The `garden tools` command is also handy since it allows users to easily
use the exact same tools as Garden's providers fetch and use.

To pre-fetch the tools, we add a `garden util fetch-tools` command,
which fetches all tools for the configured providers in the current
project, or for all registered providers if the `--all` flag is set.

Notes:
- We now always fetch the docker binary on use, instead of checking for
  its existence locally. This avoids some code complexity and makes sure
  we always use the expected version. The downside should be mitigated
  by the pre-fetching in built containers, and the fetch-tools command.
- We really need to reduce the number of tools and versions we bundle
  before we release 0.12. The container image sizes are too large atm.
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.

2 participants