Skip to content

feat: add support _EXPERIMENTAL_DAGGER_CLI_BIN to rust - #5534

Merged
sipsma merged 6 commits into
dagger:mainfrom
wingyplus:rust-experimental-cli-bin
Aug 2, 2023
Merged

sipsma merged 6 commits into
dagger:mainfrom
wingyplus:rust-experimental-cli-bin

Conversation

@wingyplus

@wingyplus wingyplus commented Aug 1, 2023 •

Copy link
Copy Markdown
Contributor

From the root of the rust sdk, run:

$ env _EXPERIMENTAL_DAGGER_CLI_BIN=../../bin/dagger cargo run --example first-pipeline

The sdk will use dagger binary defined in _EXPERIMENTAL_DAGGER_CLI_BIN to run the pipeline. And modify the engine to try running on local cli when session port & token doesn't set, if this configuration is not set, it will fallback to download cli method.

And also fix tests that failure because of using deleted apis. And re-generate code to make lint happy.

From the root of the rust sdk, run:

    $ env _EXPERIMENTAL_DAGGER_CLI_BIN=../../bin/dagger cargo run --example first-pipeline

The sdk will use dagger binary defined in `_EXPERIMENTAL_DAGGER_CLI_BIN`
to run the pipeline. And modify the engine to try running on local cli
when session port & token doesn't set, if this configuration is not set,
it will fallback to download cli method.

Signed-off-by: Thanabodee Charoenpiriyakij <[email protected]>
Since add support for local cli, the tests failure because of the use of
deleted apis, introduced in PR
dagger#5512. Fixes by switch to the api
that still available, such as `fs().file(..,..)` to just `file(..,..)`,
`exit_code()` to `sync()`.

Signed-off-by: Thanabodee Charoenpiriyakij <[email protected]>
Signed-off-by: Thanabodee Charoenpiriyakij <[email protected]>
Re-run codegen to generate up-to-date sdk to make lint happy.

Signed-off-by: Thanabodee Charoenpiriyakij <[email protected]>
@wingyplus
wingyplus force-pushed the rust-experimental-cli-bin branch from a639614 to f420a9d Compare August 1, 2023 14:46

@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, thanks!

@sipsma

sipsma commented Aug 1, 2023

Copy link
Copy Markdown
Contributor

I'm a rust noob so would prefer to get @kjuulh signoff before merge

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

Some small comments. Feel free to ping me if you want to discuss the changes =D

We may have to duplicate the ENGINE version so that we've got both a

  • Fetched engine version
  • Running engine version

This may be useful because if we're not using the fetcher, and instead the one provided by dagger run, or just a binary, then we don't control what engine we're running on.

Otherwise, we could also just add a flag set in the user agent, such that we can see that we're running under another engine. Or use an external binary.

Comment on lines +34 to +36
if let Ok((conn, child)) = self.from_local_cli(cfg).await {
return Ok((conn, Some(child)));
}

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.

It is good practice to defer to Option for cases like this, if we don't care about the error at all, we'll just continue

Suggested change
if let Ok((conn, child)) = self.from_local_cli(cfg).await {
return Ok((conn, Some(child)));
}
if let Some((conn, child)) = self.from_local_cli(cfg).await? {
return Ok((conn, Some(child)));
}

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.

If we put ? after await then it would raise with error:

Error: failed to connect to dagger engine

Caused by:
    environment variable not found

Location:
    crates/dagger-sdk/examples/first-pipeline/main.rs:3:18

The error above come from running cargo run --example first-pipeline. It probably because of I used await? during fetch env variable. What should I suppose to fix in this case?

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.

You can just return a None instead then.

We don't care about the error, so we just return an Option,

If you don't need the error at all.

It can also be done like so.

if let Some((conn, child)) = self.from_local_cli(cfg).await.ok() { //-> this will transform an Err into an Option. 

Comment thread sdk/rust/crates/dagger-sdk/src/gen.rs Resolved
@wingyplus

Copy link
Copy Markdown
Contributor Author

Some small comments. Feel free to ping me if you want to discuss the changes =D

We may have to duplicate the ENGINE version so that we've got both a

* Fetched engine version

* Running engine version

This may be useful because if we're not using the fetcher, and instead the one provided by dagger run, or just a binary, then we don't control what engine we're running on.

Otherwise, we could also just add a flag set in the user agent, such that we can see that we're running under another engine. Or use an external binary.

I'm not sure if this related to #5315? So we could ensure that the rust SDK still compat with the current engine that running on.

@kjuulh

kjuulh commented Aug 1, 2023 •

Copy link
Copy Markdown
Contributor

Some small comments. Feel free to ping me if you want to discuss the changes =D
We may have to duplicate the ENGINE version so that we've got both a

* Fetched engine version

* Running engine version

This may be useful because if we're not using the fetcher, and instead the one provided by dagger run, or just a binary, then we don't control what engine we're running on.
Otherwise, we could also just add a flag set in the user agent, such that we can see that we're running under another engine. Or use an external binary.

I'm not sure if this related to #5315? So we could ensure that the rust SDK still compat with the current engine that running on.

@wingyplus

There is a bit of overlap for sure.

But I think it is fine with going what we've got now, as long as just get the bump fixed, so that the generated code matches the version it is running under.

Lets keep in mind that we may need the compatibility checks at some point =D


All in all, to get the issues fixed, we just need to trigger bump, so that we run under the right version, and get the function fixed, so that it either return an Error, which we transform with .ok or returning an Option inside the function. Up to you, I don't mind either way

Hopefully the direction to resolution isn't too unclear =D

Signed-off-by: Thanabodee Charoenpiriyakij <[email protected]>
Signed-off-by: Thanabodee Charoenpiriyakij <[email protected]>
@wingyplus

Copy link
Copy Markdown
Contributor Author

@kjuulh All issues are addressed. Please kindly review it again. 🙇

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

Looks good

@sipsma
sipsma merged commit 1bbc0c7 into dagger:main Aug 2, 2023
@wingyplus
wingyplus deleted the rust-experimental-cli-bin branch August 2, 2023 14:29
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.

3 participants