Skip to content

check vendored package versions and prompt users to upgrade - #2321

Merged
aluzzardi merged 1 commit into
dagger:mainfrom
aluzzardi:stdlib-universe-nagging
Apr 29, 2022
Merged

aluzzardi merged 1 commit into
dagger:mainfrom
aluzzardi:stdlib-universe-nagging

Conversation

@aluzzardi

@aluzzardi aluzzardi commented Apr 27, 2022 •

Copy link
Copy Markdown
Contributor

This is a workaround to prompt users to run project update when a version mismatch of stdlib/universe is detected.

The workaround should go entirely away once we have proper package management.

For now, this writes dagger's binary version inside cue.mod/pkg/<module>/version.txt whenever we dagger project update, and checks if the version matches upon dagger do.

Example:

$ dagger do test
5:06PM WRN system | A new version of package "dagger.io" is available, please run `dagger project update` to upgrade
...

/cc @helderco @marcosnils

@aluzzardi
aluzzardi requested review from a team, samalba and shykes as code owners April 27, 2022 00:11
@marcosnils

marcosnils commented Apr 27, 2022 •

Copy link
Copy Markdown
Contributor

If I understood the code correctly If we release a new version of Dagger where we don't change any package we're still going to be warning all users to upgrade unnecessarily. Shouldn't we ideally warn the users to update when it's necessary?

We could do this by making the check a bit more smarter and specify up to which dagger version stdlib/universe is API compatible / requires an upgrade. Ideally we should also dogfood this approach and make our CI follow the same approach instead of relying on the source packages so we can get tests to fail when someone changes the packages and doesn't does the proper modifications so Dagger warns upon initialization.

Current solution LGTM if we decide that adding a last_update per package and doing all this work is not worth at this stage and until the package manger is finally ready.

@aluzzardi
aluzzardi force-pushed the stdlib-universe-nagging branch 2 times, most recently from 632c6df to 668cd0b Compare April 27, 2022 02:42
@aluzzardi

Copy link
Copy Markdown
Contributor Author

Updated following your feedback @marcosnils with a couple of other changes

  • Add a list of module version requirements in the runtime
	ModuleRequirements = map[string]string{
		DaggerModule:   ">= 0.2.8",
		UniverseModule: ">= 0.2.8",
	}
  • It's not a warning anymore, it's an error. Supposedly we'll update the requirements when we KNOW it's going to break.

Example:

$ dagger do list
failed to load plan: package "universe.dagger.io" (version 0.2.7) is incompatible with this version of dagger (requires >= 0.2.8). Run `dagger project update` to resolve this

Usage: 
  dagger do [flags]
  • TENTATIVE Fail when the vendored module is NEWER than the runtime (e.g. project update was run by someone else with a newer version of dagger)

Ideally, we should have a way to encode runtime requirements in the module itself. However it's trickier to do (anyone's got suggestions?) and I think in the meantime this will cause more good than annoyance.

Worst case scenario, we force people upgrade dagger when not necessary. Versus getting weird runtime errors.

Example:

$ dagger do list
failed to load plan: this plan requires dagger 0.2.8 or newer. Run `dagger version --check` to check for latest version

Usage: 
  dagger do [flags]
  • Tests

I haven't figured out a way yet to test this properly. @marcosnils you suggested having CI follow the same approach but it's a bit tricky since there are interdependencies between the runtime, stdlib and universe.

@marcosnils

marcosnils commented Apr 27, 2022 •

Copy link
Copy Markdown
Contributor

@aluzzardi PR LGTM as is. Leaving a few reflections after thinking about this for some time.

Ideally, we should have a way to encode runtime requirements in the module itself. However it's trickier to do (anyone's got suggestions?) and I think in the meantime this will cause more good than annoyance.

Well. nodejs's package.json has the engines spec for such purpose https://docs.npmjs.com/cli/v7/configuring-npm/package-json#engines. I guess that ideally each package eventually could have a dagger.cue (or whatever) in their root folder to specify such constraints? I do agree that we should think this more in depth before going ahead and implement it.

I haven't figured out a way yet to test this properly. @marcosnils you suggested having CI follow the same approach but it's a bit tricky since there are interdependencies between the runtime, stdlib and universe.

What I had in mind is that we should have an automated (non manual review) way to know if someone changes a package in a non-backwards compatible way and forgets to update the requirements which would cause confusing runtime errors. So, for that to happen we should have independent version streams between the packages and dagger. That way it's easy to create a CI step that checks if a package has been modified but it's version hasn't been updated.

So, to make my ideas more concrete what I'm thinking is:

Having a dagger.cue (name TBD) at the root of each package with something like:

version: "0.0.1"
engine: ">=0.2.7"

Embed this file with the module inside dagger and do both an engine and module version check with the following constraints:

  • If engine constraint is not met, fail with an error as we do in this PR
  • If MINOR or PATCH module version changes, suggest the user to perform a dagger project update
  • if MAJOR module changes, fail and force the user to upgrade.

The thing that I like about this approach is that it gives us a bit more flexibility to keep the modules and dagger versions separately while providing a workflow to minimize potential errors when reviewing code and upgrading modules until the PM is fully ready.

Thoughts?

@aluzzardi

Copy link
Copy Markdown
Contributor Author

Ok I really like this:

So, to make my ideas more concrete what I'm thinking is:

Having a dagger.cue (name TBD) at the root of each package with something like:

version: "0.0.1"
engine: ">=0.2.7"

To make a parallel with go and go.mod, this could a statement in the file that contains the dependencies (e.g. similar to go 1.16 in go.mod):

$ cat cue.mod/module.cue
# module already exists in `module.cue`
module: "universe.dagger.io"

# this is from package management
require: {
	"github.com/dagger/dagger": "v0.2.7"
}

# FIXME: need to find a better keyword
# `dagger do` will fail if attempting to run a module for a newer runtime. Also, fetching modules that are meant for a newer runtime will fail as well
runtime: "0.2.8"

The thing that I like about this approach is that it gives us a bit more flexibility to keep the modules and dagger versions separately while providing a workflow to minimize potential errors when reviewing code and upgrading modules until the PM is fully ready.

Yeah, that's very interesting. I think this warrants a longer conversation as it's a complex topic, we should start a separate issue. I like where it's going.

Embed this file with the module inside dagger and do both an engine and module version check with the following constraints:

re "engine and module version check": I don't know if that applies once we switch to proper package management, e.g. stdlib / universe etc will NOT be embedded in the binary anymore and will be external.

Specifically, regarding the module version check:

If MINOR or PATCH module version changes, suggest the user to perform a dagger project update
if MAJOR module changes, fail and force the user to upgrade.

There won't be anymore the notion of "changes", right? For example, the module "universe" in cue.mod is version 0.1.2. But that's it, there's no vendored version, we can't compare that against another version.

I think having the runtime target version in the module should be enough. For instance:

  • Each module states which version of dagger they target (e.g. at dagger project init, in module.cue or similar, just like go does)
  • The engine binary contains a minimum version it is compatible with

The constraint we'd then apply is: module.engine >= ${minimum version} && module.engine <= ${current version}:

  • Fail if a module targets an OLDER runtime no longer supported by the current one
    • In which case, the user should dagger project update the module
  • Fail if a module targets a NEWER runtime than the current one (we can't know if it works or not)
    • In which case, the user should upgrade dagger

@aluzzardi aluzzardi mentioned this pull request Apr 27, 2022
17 tasks done
@aluzzardi

Copy link
Copy Markdown
Contributor Author

In the meantime, is this approach ok @marcosnils @helderco ?

The hackish part is we're writing a version.txt file when project update'ing. Ideally this information would be elsewhere (TBD), but that's the quickest I have.

@marcosnils

Copy link
Copy Markdown
Contributor

In the meantime, is this approach ok @marcosnils @helderco ?

Yep, this works until we brainstorm a more robust solution. Let's make sure to ping all @dagger/maintainers in Discord and let then know to have special care when changing modules so they check if version requirements should be changed 🙏

@aluzzardi
aluzzardi force-pushed the stdlib-universe-nagging branch 2 times, most recently from bc3c7f9 to cb3b58f Compare April 28, 2022 20:31
@aluzzardi

Copy link
Copy Markdown
Contributor Author

I just revamped the logic to make it simpler.

Here's the outline:

  • When running dagger project update, we store the runtime version in pkg/<MODULE>/version.txt
  • The runtime keeps a map of MINIMUM module version it requires to run properly
  • The runtime refuses to run with modules depending on a NEWER version of the runtime (compared to itself)

The logic is pretty straightforward:

if vendoredVersion.LessThan(minimumVersion) {
	return fmt.Errorf("package %q (version %s) is incompatible with this version of dagger (requires %s or newer). Run `dagger project update` to resolve this", module, vendoredVersion.String(), minimumVersion.String())
}

if vendoredVersion.GreaterThan(daggerVersion) {
	return fmt.Errorf("this plan requires dagger %s or newer. Run `dagger version --check` to check for latest version", vendoredVersion.String())
}

@marcosnils

Copy link
Copy Markdown
Contributor

We could do this by making the check a bit more smarter and specify up to which dagger version stdlib/universe is API compatible / requires an upgrade.

That's what I had in mind initially :D. Since it's simpler to reason the logic that way :). SGTM! it'd be great if someone else can also ✔️

@helderco helderco 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.

In the meantime, is this approach ok @marcosnils @helderco ?

Yes, as a workaround it LGTM. We'll make it better with #2163 🙂

@aluzzardi

Copy link
Copy Markdown
Contributor Author

@sipsma I'm getting the ListWorkers timeout every single time, weirdly enough (like 3+ times in a row already)

@sipsma

sipsma commented Apr 29, 2022

Copy link
Copy Markdown
Contributor

@aluzzardi looking at your branch I think you didn't pick up this commit yet 5bd9077

@aluzzardi

Copy link
Copy Markdown
Contributor Author

@sipsma Oh thank you! Indeed I forgot to rebase, done

@aluzzardi

Copy link
Copy Markdown
Contributor Author

Still a failed to execute plan: maximum timeout reached after rebasing, I'll check tomorrow, maybe it has actually something to do with this PR

@sipsma

sipsma commented Apr 29, 2022

Copy link
Copy Markdown
Contributor

Still a failed to execute plan: maximum timeout reached after rebasing, I'll check tomorrow, maybe it has actually something to do with this PR

@aluzzardi That's a different issue from the ListWorkers error (I have no idea why these both decided to show up out of nowhere on the same day).

That issue with failed to execute plan: maximum timeout reached is just GHA being slow, most likely due to throttling. It can be fixed with a retry. I created an issue to track it here: #2365

@aluzzardi
aluzzardi force-pushed the stdlib-universe-nagging branch from 24f314b to 5153158 Compare April 29, 2022 22:59
@aluzzardi

Copy link
Copy Markdown
Contributor Author

@marcosnils @helderco Made a couple of minor tweaks, I'll merge them but let me know if you want me to change anything:

  • Store version.txt in <module>/cue.mod/version.txt rather than <module>/version.txt (e.g. cue.mod/pkg/dagger.io/cue.mod/version.txt) so we don't pollute the package's namespace
  • Skip version checks if the module is a symlink (like in our own repo)
  • Also: dagger project update won't update a module if it's a symlink (if you mistakenly run dagger project update in dagger/dagger)

@aluzzardi
aluzzardi merged commit 478c481 into dagger:main Apr 29, 2022
@aluzzardi
aluzzardi deleted the stdlib-universe-nagging branch April 29, 2022 23:22
@helderco helderco mentioned this pull request May 2, 2022
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.

4 participants