Skip to content

chore: tag all releases with semver - #7858

Merged
jedevc merged 5 commits into
dagger:mainfrom
jedevc:semver-tags-for-everyone
Aug 1, 2024
Merged

jedevc merged 5 commits into
dagger:mainfrom
jedevc:semver-tags-for-everyone

Conversation

@jedevc

@jedevc jedevc commented Jul 9, 2024

Copy link
Copy Markdown
Contributor

Fixes #7760

Instead of just using commit hashes and directory IDs, which produces nearly incomprehensible versions (which is more of a pain, now that engineVersion is actually important). This makes it a bit clearer when and where a non-tagged build came from by using changie to get the last release we built.

Frustratingly, it seems non-trivial to do version comparison on these, so we keep skipping these. In the future, we should work out on compromise. For an example of why this is hard: suppose that we add a MinVersion of v0.12.0 - the next pre-release will end up being something like "v0.11.10-dev-240709191414-1ccb8772510a". So this version will fail these checks.

We could add a little piece of code to note what the next release will be - which would make these comparison a lot simpler (essentially, we'd treat pre-releases of vX as equivalent to X). But this would require too much extra maintainance for now - but maybe we could dupe this with MinVersion numbers in version.go today.

image

You get a semver tag!

@jedevc
jedevc force-pushed the semver-tags-for-everyone branch from b809ba6 to 066b90f Compare July 9, 2024 19:34
@jedevc

jedevc commented Jul 9, 2024

Copy link
Copy Markdown
Contributor Author

@jedevc jedevc added this to the v0.12.0 milestone Jul 9, 2024
@jedevc
jedevc requested review from gerhard and sipsma July 9, 2024 19:43
@jedevc jedevc mentioned this pull request Jul 10, 2024
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch from 066b90f to faddb41 Compare July 10, 2024 16:10
@jedevc
jedevc marked this pull request as draft July 10, 2024 16:10
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch 2 times, most recently from 5c765f1 to 1b7bccd Compare July 10, 2024 17:07
@sipsma

sipsma commented Jul 10, 2024

Copy link
Copy Markdown
Contributor

One thing I just noticed, we construct the default runner host to connect to based on Version: https://github.com/sipsma/dagger/blob/b06d45a7e0e026bbe557994314afb1f09282cf8e/engine/consts.go#L26-L26

This will continue working for tagged releases, but I think the change here would create a disconnect for CLIs published off main in that now we publish the engine image using just the git commit SHA and Version is more involved.

Getting CLIs built off main to automatically provision the correct engine image built off main by default was a pretty nice property to have, so it would be nice to maintain. It's not an utterly crucial requirement though

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

Makes sense on a high level! I do greatly prefer the explicit file with the next version that you added in the last commit over inferring from changie (since whether the next version is a patch or minor bump is a human decision)

Comment thread dev/version.go Resolved
Comment thread dev/version.go Resolved
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch 2 times, most recently from 379625a to 3497538 Compare July 11, 2024 15:58
@jedevc
jedevc marked this pull request as ready for review July 11, 2024 16:00
@jedevc

jedevc commented Jul 11, 2024

Copy link
Copy Markdown
Contributor Author

Getting CLIs built off main to automatically provision the correct engine image built off main by default was a pretty nice property to have, so it would be nice to maintain. It's not an utterly crucial requirement though

Oof, just missed this till now - I've split this behavior out to populate Tag separately, so we can preserve this.

@jedevc
jedevc force-pushed the semver-tags-for-everyone branch from 40e2fee to 0bca261 Compare July 11, 2024 16:41
Comment thread dev/test.go
Comment on lines +96 to +101
// Add ldflags
ldflags := []string{
"-X", "github.com/dagger/dagger/engine.Version=" + t.Dagger.Version.String(),
"-X", "github.com/dagger/dagger/engine.Tag=" + t.Dagger.Version.TagString(),
}
args = append(args, "-ldflags", strings.Join(ldflags, " "))

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.

So I ended up trying to use engine.Version somewhere in our tests. Previously I was making up v1000 as a version number, but we can't do that anymore: #7692

I also really really didn't want to have to update this test every single release, that was not something I wanted to do.

Comment thread .goreleaser.common.yml Outdated
ldflags:
- -s -w
- -X github.com/dagger/dagger/engine.Version={{.Env.ENGINE_VERSION}}
- -X github.com/dagger/dagger/engine.Tag={{.Env.ENGINE_VERSION}}

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 we want to set this to a different value, i.e. WithEnvVariable("ENGINE_TAG", cli.Dagger.Version.TagString() here https://github.com/sipsma/dagger/blob/2a9bb343e013194b9153739fe17a06c55282a841/dev/cli.go#L85

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.

Eek, yes.

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.

Hm, actually, the timestamps are an issue here 🤔 Because we publish the cli and engine in separate steps, the timestamps will be different, which is weird.

I guess we can get the timestamp in github actions, and pass it everywhere, but that's really annoying 😢

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.

Fixed this in the last commit, by adding a new ENGINE_TAG env that's populated from the new --tag parameter. dev builds won't have this set, so we should error out - which makes sense, the current behavior is to try and pull a non-existent image.

Additionally, the timestamps in version numbers are an issue for the github multi-step release - this is resolved by just having a version pre-calculation step, which is messy, but eventually we'll shift all of this logic into dagger, so it'll hopefully all go away...

@jedevc jedevc modified the milestones: v0.12.0, v0.12.1, v0.12.2 Jul 11, 2024
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch from 65e5e48 to 508c89b Compare July 18, 2024 12:46
@jedevc
jedevc marked this pull request as draft July 18, 2024 12:46
@jedevc

jedevc commented Jul 18, 2024

Copy link
Copy Markdown
Contributor Author

Marking as draft while I rework this a bit.

@jedevc
jedevc force-pushed the semver-tags-for-everyone branch 3 times, most recently from f855540 to 2a3a63a Compare July 18, 2024 14:29
@vito vito added this to the v0.12.3 milestone Jul 22, 2024
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch 3 times, most recently from 447114a to d6e7540 Compare July 24, 2024 11:29
@jedevc

jedevc commented Jul 24, 2024 •

Copy link
Copy Markdown
Contributor Author

So I think this is getting much closer to ready - this changes some release things, so I'll keep an eye on main once it's merged. However, the major changes are:

  • Every build gets semver tags
  • All builds cut directly off of main pretty much keep working as they do today
  • All dev builds will happily work with each other (as long as they share the same major/minor/patch) part of their build - we all roughly know what we're doing.
  • The compat mode for a module with engineVersion vX.Y.Z-<anything> is always vX.Y.Z
    • Note: we should still strongly advise against doing this - imagine the following scenario:
    • We add breaking change 1 to dagger
    • You generate a module with a version with this engineVersion
    • We add breaking change 2 to dagger
    • Your module is still requesting the same api version - and so your module breaks.
    • This is expected! There's really no way to avoid this without having every single breaking change in dagger introduced with a timestamp (I thought about this for a good while, I don't really like it, but we could always return to it if it's a sticking point)
    • The only other option that I thought of is that vX.Y.Z-dev could serve the schema vX.Y.(Z - 1) - but then this means that builds cut off of main won't work with new features (making it harder to pick up), you'd need to manually specify --compat=vX.Y.Z - that feels fiddly - and would probably some weird test hackery.
      • Some very tricky logic would be required to get minor releases working - what release came before "v0.12.0"?
      • And of course, if a user publishes this module, then it breaks anyways - and now without the prerelease in the engineVersion to indicate it.
    • @sipsma any thoughts? I think the current behavior in this PR is the best compromise we can make right now (we could change this in the future, and say something like "all pre-releases after v0.13.0 are considered to be serving the previous releases API").

Future work:

@jedevc
jedevc marked this pull request as ready for review July 24, 2024 11:29
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch 3 times, most recently from bb684ad to 69bfa83 Compare July 24, 2024 13:32

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

LGTM so far, couple significant comments and some nits.

I'd generally say that we really need to lean on the tests here. There are just so many dimensions ((version, min version) x (engine, client) x (dev, not dev)) that it gets really hard to think about all of them purely by reading the code. That's just inherent though, so whatever we can do to make sure we have as much test coverage as feasible in a readable way will pay dividends I think.

Comment thread engine/consts.go Outdated
Comment on lines +39 to +40
// can happen during dev builds
return "", fmt.Errorf("no builtin image tag available")

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: I wonder if we should just default to docker-container://dagger-engine.dev 🤔 That's what you want most of the time and the other times you are explicitly setting the env var anyways. Not a blocker either way though, just if you agree

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.

Yeaaaa, this is already weird uncharted territory, so this makes sense to me.

Comment thread engine/version.go Outdated
// MinimumEngineVersion is used by the client to determine the minimum
// allowed engine version that can be used by that client.
MinimumEngineVersion = "v0.12.0"
MinimumEngineVersion = "v0.12.1"

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.

Sorry if I missed this somewhere else, but why is this bumped to v0.12.1?

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.

Hmmm, I did this for a reason - and I now cannot remember it. We can always re-bump it later if it turns out to have been for a good reason.

Comment thread engine/client/client.go Resolved
Comment thread engine/version.go Resolved

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.

Just saw in the tests that we only have cases where the engine sets Version and MinVersion to the same values. Would it be valuable to have additional tests where Version>MinVersion? That's the situation we'd find ourselves in most often so IIUC it seems like good to have too. Might be misunderstanding something though.

Also as a nit: these tests are extremely valuable for understanding what the intended behavior is in the first place (almost documentation of it), which makes me wonder if it would be worth the effort to refactor them as table-driven tests.

Then we can just easily look through every permutation of (engine version, engine min version, client version, client min version) in a centralized place (as opposed to a bunch of separate tests with boilerplate overhead) and know what the expected behavior is. It would also probably make it easier to see if we are missing some particular permutation.

  • I realize this might be a tedious change from the current state, so not a blocker for me at all, just a suggestion if you agree

@jedevc jedevc Jul 26, 2024 •

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.

Mm, agreed - I started doing some of this in version_test.go with pretty much exactly this kind of test (a lot more lightweight as well, though they aren't integration tests).

Does that kind of work? I can add more inline doc comments to explain those if they're currently unclear. I think we could keep the heavier integration tests with the current scenarios, and then use version_test.go to cover all the more detailed cases.

The reason I didn't go for table tests in the first place was that spinning up a bunch of engines with different versions is relatively heavy. We could definitely do it. The other problem is that the _EXPERIMENTAL_DAGGER_VERSION isn't perfect - it's the best way to test it right now, but really we'd want to have dagger dev-module tests I think to make sure they're properly propagated from the build process.

Still worth doing? I'm kind of in the balance and could be persuaded either way.

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.

Yeah we should definitely have the unit tests too, but the thing is when I look through them it's hard to connect them back to the actual version of the Engine/CLI/Module/etc. that is being compared in various places (you need to go look at the code where those comparisons are happening, see which value is which arg, what processing has been done on the arg already, etc.)

I think the table driven integ tests could be made to work with the right set of parameters to the test (i.e. provide engine service as arg so we don't need a new one for each test, etc.).

But maybe another approach would be to change the code such that we keep the current CheckVersionCompatibility/CheckMaxVersionCompatibility/etc. functions but wrap them with very specific functions like CheckEngineModuleVersionCompatibility/CheckClientEngineCompatibility/etc. and use those in our code instead.

So rather than calling

engine.CheckMaxVersionCompatibility(modCfg.EngineVersion, engine.BaseVersion(engine.Version))

in core/schema/module.go, we instead call something like

func CheckEngineModuleVersionCompatibility(modCfgEngineVersion, engineVersion string) error {
   return engine.CheckMaxVersionCompatibility(modCfgEngineVersion, engine.BaseVersion(engineVersion)
}

Same idea for calling CheckClientEngineCompatibility instead of engine.CheckVersionCompatibility(engine.NormalizeVersion(c.bkVersion), engine.MinimumEngineVersion) in engine/client/client.go, etc.

Then we can unit test those higher-level wrappers and make it super clear what the intended behavior is for each specific case of all the different comparisons we need to make. That might make the code overall easier to keep track of too. WDYT?

  • Like I said, all this isn't a blocker, not even 100% sure it would look as nice as I'm theorizing

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.

That might make the code overall easier to keep track of too. WDYT?

Yeah, this is honestly the most important thing for this change, so I've just sucked it up and converted it - it's an absolute pain, but it's now done 🎉

Now it should be super easy to add new tests there, I don't think there's anything major that's not covered?

@jedevc jedevc modified the milestones: v0.12.3, v0.12.4 Jul 26, 2024
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch 3 times, most recently from 2210f80 to 7c81e3d Compare July 30, 2024 15:38
@jedevc
jedevc requested a review from sipsma July 30, 2024 15:39
jedevc added 3 commits July 31, 2024 13:04
Instead of just using commit hashes and directory IDs, which produces
nearly incomprehensible versions (which is more of a pain, now that
`engineVersion` is actually important). This makes it a *bit* clearer
when and where a non-tagged build came from by using changie to get the
last release we built.

Frustratingly, it seems non-trivial to do version comparison on these,
so we keep skipping these. In the future, we should work out on
compromise. For an example of why this is hard: suppose that we add a
MinVersion of v0.12.0 - the next pre-release will end up being
something like "v0.11.10-dev-240709191414-1ccb8772510a". So this version
will fail these checks.

We could add a little piece of code to note what the *next* release will
be - which would make these comparison a lot simpler (essentially, we'd
treat pre-releases of vX as equivalent to X). But this would require
too much extra maintainance for now - but maybe we could dupe this with
MinVersion numbers in `version.go` today.

Signed-off-by: Justin Chadwell <[email protected]>
Otherwise, it could potentially build two different timestamps - which
would cause an amount of chaos.

Signed-off-by: Justin Chadwell <[email protected]>
Without this, we hit some *pretty* big issues when comparing against dev
versions (which we now have some more tests for).

Essentially, we do two main things:
- When comparing client/server/module versions to each other, we make
  sure that the versions are both, 1. normalized (handling empty
  version strings, old-style version strings, etc), and 2. stripped to
  their base version when we're using dev engines (so that
  vX.Y.Z-dev-123 is compatible with vX.Y.Z-dev-456).
- Keep all schemaVersions as stripped versions without prereleases. This
  ensures that we're always serving the most up-to-date API view.

Signed-off-by: Justin Chadwell <[email protected]>
@jedevc
jedevc force-pushed the semver-tags-for-everyone branch 2 times, most recently from de269f7 to deedf99 Compare July 31, 2024 12:41
@jedevc
jedevc merged commit b31fa64 into dagger:main Aug 1, 2024
jedevc added a commit to jedevc/homebrew-core that referenced this pull request Aug 1, 2024
Since dagger/dagger#7858, `engine.Tag` must now be populated.

From that PR, quoting myself:
> Because we add a new link-time variable, we need to update everywhere we do builds of dagger

Without this, the dagger client will not be able to resolve external resources it needs to be able to operate.
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.

Introduce go-style pseudoversions for cli + engine releases

3 participants