Skip to content

Update SDKs to pull CLI from S3 URL. - #4194

Merged
sipsma merged 3 commits into
dagger:mainfrom
sipsma:cli-s3
Dec 15, 2022
Merged

sipsma merged 3 commits into
dagger:mainfrom
sipsma:cli-s3

Conversation

@sipsma

@sipsma sipsma commented Dec 14, 2022 •

Copy link
Copy Markdown
Contributor

Signed-off-by: Erik Sipsma [email protected]

Brings the SDKs fully in line with the description of the new session behavior here: #3830 (comment)

Basically:

  1. Prefer DAGGER_SESSION_URL if set, connect to it over http directly, no binary
  2. Fallback to _EXPERIMENTAL_DAGGER_CLI_BIN, if set, as a pointer to the CLI, call the session subcommand on that
  3. Finally, fallback to pulling a CLI binary from an URL encoded in the binary.
    • This is the same idea as when we used to pull the binary from the engine image w/ docker, except just an http request (with some extra complication due to tarball unpacking)

This PR is probably on the border of too large, but a lot of the changes are just re-arrangements of existing code, equivalent code in 3 SDKs and/or tests. If other prefer I can start by just merging the Go stuff and then send out separate PRs for python+nodejs.


Overall current state:

  1. Go - solid afaict
  2. Python - I did not put any effort into a large scale refactorization yet as I don't know the best way to approach it. I don't think we need the whole @register_engine thing anymore (I removed the equivalent of that in go+nodejs) but want to wait for your opinion first @helderco
  3. NodeJS - Ran into tons of headaches trying to get tar-related code working well (just fell back to making everything a file on the filesystem more or less, no in memory operations) and some other stuff related to test mocking. So it's ugly but works. Leaving comments on some questions I have.

Each of the SDKs have tests that setup an http server and use that to test the "pull from s3 url" code path. That's a good start but this code is still not tested against the real CLI deployed to S3 because we haven't done a release of the CLI yet that includes the new session subcommand that SDKs need.

So the last follow up (besides more cleanup of python+node) will be to either:

  1. Setup the automation for pushing the CLI to s3 on every push to main
  2. Do a release of the engine+cli, then test the SDKs against that, update as needed.

I'd greatly prefer 1 and talked to Gerhard about it a bit last week. It seems relatively straightforward, but I'll see how it goes when I try tomorrow.

Comment thread sdk/nodejs/provisioning/bin.ts Outdated
Comment on lines 325 to 340

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.

This is the ugliest thing remaining: basically, we want the ability to override the host we pull the CLI from in order to test it, but I really want to avoid using an env var for that (since that makes it much easier for SDK users to intentionally or even be tricked into overriding those env vars at actual runtime).

I went down a nightmare rabbit hole of trying to use rewire and a few similar things but had to give up because everything either wasn't compatible (w/ es6 + typescript) or was way over my head in terms of actually understanding. @slumbering let me know if there's any good ways of approaching this that work on our codebase or if this ugly workaround works. Main thing is I just don't want this to end up in our generated docs.

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.

Looking at it now 👀

Comment thread sdk/python/src/dagger/config.py Resolved
@helderco

Copy link
Copy Markdown
Contributor

Thanks for the head start! I can update the python bits here soon, hopefully I won't block you.

I haven't looked closely yet, but you say @register_engine won't be needed, so that means pulling CLI from URL will be the only provisioning method now? Will users be able to use a CLI that's already installed in their system?

I mean, I'm sure that'll be obvious when I look at the code, just quick context catch up in the meantime if I don't say anything. If you can update the PR description with the issue where this plan is laid out, that'd be great.

@sipsma

sipsma commented Dec 14, 2022

Copy link
Copy Markdown
Contributor Author

@helderco Updated the PR description with the backlink to the other issue and a summary, let me know what other questions come up!

@helderco

Copy link
Copy Markdown
Contributor

@sipsma Thanks! 🙏

@helderco

helderco commented Dec 14, 2022 •

Copy link
Copy Markdown
Contributor

@sipsma Weren't we going to use DAGGER_SESSION_PORT instead? I need to catch up 🙂

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

Glad to see this! Definitely simplifies things a lot.

Overall LGTM, I'll let @helderco @slumbering @dolanor @TomChv dive deeper in the Node/Python parts.

I guess we could use this to "untangle" a little bit the dev environment at some point.

@helderco

Copy link
Copy Markdown
Contributor

@sipsma Weren't we going to use DAGGER_SESSION_PORT instead? I need to catch up 🙂

Ok, I see in #3830 (Implementation steps) that there's a task for it:

Switch DAGGER_SESSION_URL -> DAGGER_SESSION_PORT

Comment thread sdk/nodejs/test/connect.spec.ts Outdated

@slumbering slumbering Dec 14, 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.

Not sure about the utility of those old* variables (from line 60-62). Same in the after(()...
cc @sipsma

@slumbering slumbering Dec 14, 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.

Oh I guess it's because we're playing with process env and you want to reset everything in the after((...
I'm playing with Sinon.js that could stubs process.env values

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.

I'm still confused with oldCLIHost and oldCLIScheme

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.

@sipsma : I've just pushed a commit to remove them

@sipsma sipsma Dec 15, 2022 •

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.

Hey sorry I didn't get back to this PR yesterday, but the reason for this is that CLI_HOST and CLI_SCHEME are set in the top level of the module, so changing them will affect any other tests. I think it technically doesn't hurt to leave them changed right now since no other test cases will hit the code paths that use them, but I'd rather leave the reset of them in since it could be very confusing in the future if someone is writing another test case and those vars have a different unexpected value. I went back to the original approach for now, but let me know what you think.

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 should find another way in a near futur, like stubbing with sinon.js for instance.

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.

Agreed, I tried a bunch of stuff like rewire but couldn't get it to work; I didn't think sinon would work because it would require we change our Connect method to accept a way of configuring all this, which means its configurable outside of tests too, which is what I was trying to avoid. Maybe it's just unavoidable though? Or I'm probably missing something obvious.

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

As you say, can't really test default download logic but everything else seems to be working, just make sure to fix the typo.

I'm working on refactoring but I want to take the opportunity to fix a few more things so no need to wait for me if you need to move on, I can send a follow up PR.

Comment thread sdk/python/src/dagger/engine/bin.py Resolved
Comment thread sdk/python/src/dagger/_version.py Resolved
@sipsma

sipsma commented Dec 15, 2022

Copy link
Copy Markdown
Contributor Author

For some reason the engine tests are stuck on:

Requested labels: ubuntu-22.04-16c-64g-600gb
Job defined at: dagger/dagger/.github/workflows/test.yml@refs/pull/4194/merge
Waiting for a runner to pick up this job...

Even after I tried restarting once. I'm gonna re-run those tests locally from a clean branch as a double check and will merge if they pass so we don't get blocked on that.

@sipsma

sipsma commented Dec 15, 2022

Copy link
Copy Markdown
Contributor Author

As you say, can't really test default download logic but everything else seems to be working, just make sure to fix the typo.
I'm working on refactoring but I want to take the opportunity to fix a few more things so no need to wait for me if you need to move on, I can send a follow up PR.

Thanks @helderco, that sounds great. The PR coming after this one will add publishes of the CLI on every push to main alongside a few updates to primarily the test case code in each SDK to support running against those CLI builds. As of right now the changes to the actual non-test code in SDKs is extremely small (just support for pulling from a different url path, similar to the way they can change host/scheme already), so shouldn't need to worry about conflicts.

@sipsma

sipsma commented Dec 15, 2022

Copy link
Copy Markdown
Contributor Author

Engine tests passed locally, merging

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