#I need some help creating and testing

1 messages ยท Page 1 of 1 (latest)

keen lotus
#

Quick ping on this for @digital solar, @vernal ember and @rustic aspen if they can help

keen lotus
#

FYI @sleek magnet @keen silo I'm waiting on these pending code snippets to close the services guide

vernal ember
#

I'll have a look tomorrow on that one

keen lotus
#

Hi guys, can I do anything to help move this forward? I'm trying to complete the doc today as I'd like to perhaps reuse the code samples in a blog post I'm writing to announce the release

rustic aspen
keen lotus
#

Yup, I saw those errors

#

I saw a message from Alex to wrap in hack/dev. Did that work?

keen lotus
#

Ok let's ping @keen silo to see if he can help with the other errors?

#

@digital solar i know you're super busy with zenith and I'm sorry to ping you on this, but do you think you could add the python examples for services v2 in the above PR?

digital solar
keen lotus
#

I'm not sure how to write the async/await calls

#

for starting services and also how to write the portforward

digital solar
#

From those go samples it seems straightforward, you just put an await whenever you use ctx and err in Go. Or in the same places you have await in TS.

keen lotus
#

OK i see.

#

and how can I test it?

digital solar
#

Same way as you do with other examples, with virtual env activated: ./hack/dev ./bin/dagger run python <path to script>.

keen lotus
#

thanks, will try and ping you in case of difficulties

keen lotus
#

@rustic aspen how did you get the services typescript snippets to run? @daring hare was trying one of them and saw this error:

./hack/dev ./bin/dagger run node --loader ts-node/esm docs/current/guides/snippets/use-services/expose-host-services-to-container/index.ts
...
docs/current/guides/snippets/use-services/expose-host-services-to-container/index.ts(1,33): error TS2307: Cannot find module '@dagger.io/dagger' or its corresponding type declarations.
rustic aspen
#

You cannot run it in the docs directory since you do not have the npm package @dagger.io/dagger installed

#

You need to create a little project with a package.json and @dagger.io/dagger node modules

#

If you need any help @daring hare Iโ€™m here

daring hare
#

I think my problem is installing the version of the sdk from that branch. Same with python. Do we have docs on that?

#

@rustic aspen got me sorted out, thanks ๐Ÿ™

#

basically needed to go to sdk/nodejs and run npm run build, and then reference the local path in my package.json

keen silo
#

would be great to have that in a README somewhere, I went through that yesterday and ultimately gave up

daring hare
#

trying to figure it out for python and then i'm happy to document it all

#

cc @digital solar

digital solar
daring hare
#

Perfect, thanks!

digital solar
#

Of course up until hack/dev that's a one time setup. If you already have the venv with the sdk installed, just need to activate the venv.

daring hare
#

Works! I think I was expecting the pip install sdk/python to require extra steps ๐Ÿ˜…

#

and @keen silo I think this is a thing TypeError: Host.service() got an unexpected keyword argument 'frontend'

daring hare
digital solar
#

That's only if you have changes in the API that haven't been re-generated yet.

daring hare
#

I'm confused what's expected for the start/stop snippets (in snippets/start-stop-services). It runs go test ./... but we don't put any go files in the container to test

keen lotus
keen silo
#

the latter - it would be great to adjust it to a runnable example, but for now it's just a code sample

#

could help to add a dummy with[Mounted]Directory("/src") or comment to make that clear

keen lotus
#

So long as it runs without erroring out, even if there are no tests, it's ok for me to show it in the guide with an explanatory note

keen silo
#

@keen lotus any idea what's going on with netlify? https://app.netlify.com/sites/devel-docs-dagger-io/deploys/65303c6fd63826000811ea76

4:14:18 PM: $ spectaql ./docs-graphql/config.yml -t ./static/api/reference
4:14:19 PM: Found example to be rendered for cacheVolume
4:14:19 PM: Rendering successful.
4:14:19 PM: Found example to be rendered for loadCacheVolumeFromID
4:14:19 PM: Error processing the example for loadCacheVolumeFromID. Error: ENOENT: no such file or directory, open "/opt/build/repo/website/docs-graphql/data/examples/queries/loadCacheVolumeFromID/gql.md"
4:14:19 PM: Found example to be rendered for container
[...]
keen silo
daring hare
daring hare
#

for testing TS from the snippets you need a TS config too but that's kind of a problem specific to this PR where we have SDK changes and new doc snippets on the same branch

daring hare
#

working on figuring out the correct syntax

#

but my python brain is very smooth

keen lotus
#

however the build failure is due to this Error: Docs markdown link couldn"t be resolved: (./757394-use-service-containers.md) in "/opt/build/repo/docs/current/guides/128409-build-test-publish-php.md" for version current

keen silo
#

a ha - I think can fix that quickly, good eye

keen lotus
#

Maybe when you resolved the conflicts @keen silo this change didn't make it through? It's an easy fix though, just modify the link to be ...use-services.md

keen silo
#

yeah, that's probably what happened

daring hare
#

ok the python thing i'm struggling with in docs/current/guides/snippets/use-services/expose-host-services-to-container/main.py is
client.host().service(frontend=3306, backend=3306)
the args to service should be ports=[PortForward]
so like in JS it's client.host().service([{ frontend: 3306, backend: 3306 }])

#

I tried client.host().service(ports=[dagger.PortForward(frontend=3306, backend=3306)]) but that's no good

#

or rather it works but then complains about protocol being null

keen lotus
#

i failed on finding the correct syntax for this as well... maybe client.host().service([frontend=3306, backend=3306])?

daring hare
#

Tried that too along with a lot of variations ๐Ÿ˜ญ I think my last one is right but graphql isn't omitting the protocol field

#

stepping away for dinner now!

keen lotus
#

@daring hare I saw that the PR was merged, checked the commit log and I think your code snippet changes weren't included? Will you please open a new PR for those?

daring hare
daring hare
# digital solar What's that with the `protocol`?

the PortForward class has 3 fields: frontend, backend, and protocol. Trying to define it like this: client.host().service(ports=[dagger.PortForward(frontend=3306, backend=3306)]) gave me

gql.transport.exceptions.TransportQueryError: {'message': 'Syntax Error GraphQL request (3:41) Unexpected Name "null"\n\n2:   host {\n3:     service: service(ports: [{protocol: null, frontend: 3306, backe
โ”ƒ nd: 3306}]) {\n                                           ^\n4:       id: id\n', 'locations': [{'line': 3, 'column': 41}]}
...
2:   host {                                                                                                                                                                                                       
โ”ƒ 3:     service: service(ports: [{protocol: null, frontend: 3306, backend: 3306}]) 

context: https://github.com/dagger/dagger/blob/main/docs/current/guides/snippets/use-services/expose-host-services-to-container/main.py#L12

digital solar
#

In the API it's protocol: NetworkProtocol = TCP so it should accept a null. Probably should be protocol: NetworkProtocol! = TCP.

digital solar
digital solar
daring hare
#

yeah, just tried this and it works: client.host().service(ports=[dagger.PortForward(frontend=3306, backend=3306, protocol='TCP')])

digital solar
#

By the way, Python could be more lenient on types but early on in the SDK's life people were complaining with errors blowing up very late when serializing for the query, i.e., AST, so I put a strict typecheck in place because of the much more useful error messages.

daring hare
#

Definitely helpful for me, and it looks more like Go

digital solar
#

Otherwise you could have used a dict: {"frontend": 3306, "backend": 3306}.

daring hare
#

Tried that too ๐Ÿ˜‚ That's how it looks in TS

#

Hm it's failing if I don't set frontend too, which is supposed to be optional and defaulted to the value of backend

digital solar
#

Is the query being sent with frontend: null?

daring hare
#

yeah

digital solar
#

It's what's on the API, so it's a bug in the API?

#

Oh, I guess not specified != null.

daring hare
#

I'm not actually sure where the defaulting is supposed to happen, it's just what the docs say ๐Ÿคท

digital solar
#

Hmm... will need to look into it.

#

I'm wondering if it's because it's in a list instead of a direct argument.

#

Because the check that doesn't send values that match their defaults is in Arg, which is used on the params directly, not fields of inputs.

#

You can see the one bellow has a default of "localhost", that's how it compares.

daring hare
#

Yeah I did notice that, I was wondering how that worked

keen lotus
daring hare
keen lotus
#

@daring hare will you be making any changes to the go code snippets in the guide?

daring hare
daring hare
keen lotus
digital solar
daring hare
#

Yup those were the only changes I found. After talking with @keen silo this just makes the snippets work with what's on main so we can publish the guide, it doesn't fix the issues with the sdk

digital solar
#

Vikram said it was 6 scripts listed at the top of the PR that's why I asked.

daring hare
keen lotus
#

Let me know if you want direct links to view them in the repo, if that's easier

digital solar