From 90492b111b4b9698909f3e8bd57cca8a37ba6396 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 08:29:45 -0500 Subject: [PATCH 01/10] Add RunnerService examples --- examples/PROJECTS.md | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/examples/PROJECTS.md b/examples/PROJECTS.md index 21958aa0a..a87e9eab5 100644 --- a/examples/PROJECTS.md +++ b/examples/PROJECTS.md @@ -4,9 +4,9 @@ runme: version: v2.2 --- -## gRPC runme.project.v1.ProjectService +## ProjectService -Flags matche the launcher arguments in .vscode/launch.json. +Flags match the launcher arguments in .vscode/launch.json. List available operations: @@ -39,3 +39,27 @@ $ grpcurl \ -d "{\"directory\":{\"path\":\".\"}}" \ 127.0.0.1:9999 runme.project.v1.ProjectService/Load ``` + +## RunnerService + +List all runner services. + +```sh {"id":"01HNGQNYYWKP635FT8GHE67476","promptEnv":"false"} +export VERSION="v1" # there's also v2alpha1 +$ grpcurl \ + -cacert /tmp/runme/tls/cert.pem \ + -cert /tmp/runme/tls/cert.pem \ + -key /tmp/runme/tls/key.pem \ + 127.0.0.1:9999 list runme.runner.$VERSION.RunnerService +``` + +Resolve variable inside cells: + +```sh {"id":"01HNGQS6TV8YKQAKE0ZD7TZREH","promptEnv":"false"} +$ grpcurl \ + -cacert /tmp/runme/tls/cert.pem \ + -cert /tmp/runme/tls/cert.pem \ + -key /tmp/runme/tls/key.pem \ + -d "{\"script\":\"export NAME=Noname\", \"env\":[\"NAME=Sebastian\"]}" \ + 127.0.0.1:9999 runme.runner.v1.RunnerService/ResolveEnv +``` From b99fef2130c4c888757cde89896ccdc4a3c7caab Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 08:30:39 -0500 Subject: [PATCH 02/10] Rename --- examples/{PROJECTS.md => services.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{PROJECTS.md => services.md} (100%) diff --git a/examples/PROJECTS.md b/examples/services.md similarity index 100% rename from examples/PROJECTS.md rename to examples/services.md From 74ce28f5e96115dddba399248dad6693d1ec5b51 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 14:50:57 -0500 Subject: [PATCH 03/10] Setup instructions --- examples/server/grpc.md | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/examples/server/grpc.md b/examples/server/grpc.md index 4350ed799..3dc615879 100644 --- a/examples/server/grpc.md +++ b/examples/server/grpc.md @@ -4,7 +4,7 @@ runme: version: v2.2 --- -# Daemon/kernel functionality +# GRPC Kernel Install system dependencies: @@ -12,37 +12,23 @@ Install system dependencies: $ brew bundle --no-lock ``` -Let's build the project first and include working directory into `$PATH`: - -```sh {"id":"01HF7BT3HBDTRGQAQMGVG57QBE"} -$ cd ../.. -$ make -$ export CWD=$(cd ../.. && pwd | tr -d '\n') -$ export PATH="$CWD:$PATH" -``` - ## Exercise GRPC interface -Bring up the server. It's gRPC based: - -```sh {"background":"true","id":"01HF7BT3HBDTRGQAQMGXCKJCAB"} -$ ../../runme server --address /tmp/runme.sock -``` - Issue a simple call to the deserialize API, first set markdown input data: ```sh {"id":"01HF7BT3HBDTRGQAQMH0ZYTWA9"} -export mddata="# Ohai this is my cool headline" +export MD="# Ohai this is my cool headline" ``` Then issue RPC call and display the result: -```sh {"closeTerminalOnSuccess":"false","id":"01HF7BT3HBDTRGQAQMH2K85BHG"} -$ data="$(echo $mddata | openssl base64 | tr -d '\n')" +```sh {"closeTerminalOnSuccess":"false","id":"01HF7BT3HBDTRGQAQMH2K85BHG","terminalRows":"15"} +$ data="$(echo $MD | openssl base64 | tr -d '\n')" $ cd ../.. && grpcurl \ + -cacert /tmp/runme/tls/cert.pem \ + -cert /tmp/runme/tls/cert.pem \ + -key /tmp/runme/tls/key.pem \ -protoset <(buf build -o -) \ -d "{\"source\": \"$data\"}" \ - -plaintext \ - -unix /tmp/runme.sock \ - runme.parser.v1.ParserService/Deserialize + 127.0.0.1:9999 runme.parser.v1.ParserService/Deserialize ``` From 20fb77965b67f0eb180cdb8d042bc64b33dc7694 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 14:52:39 -0500 Subject: [PATCH 04/10] Consolidate --- examples/{server => grpc-samples}/Brewfile | 0 examples/{server => grpc-samples}/grpc.md | 0 examples/{ => grpc-samples}/services.md | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename examples/{server => grpc-samples}/Brewfile (100%) rename examples/{server => grpc-samples}/grpc.md (100%) rename examples/{ => grpc-samples}/services.md (100%) diff --git a/examples/server/Brewfile b/examples/grpc-samples/Brewfile similarity index 100% rename from examples/server/Brewfile rename to examples/grpc-samples/Brewfile diff --git a/examples/server/grpc.md b/examples/grpc-samples/grpc.md similarity index 100% rename from examples/server/grpc.md rename to examples/grpc-samples/grpc.md diff --git a/examples/services.md b/examples/grpc-samples/services.md similarity index 100% rename from examples/services.md rename to examples/grpc-samples/services.md From 88473b2b9a7b0e5bb718304c5faf3de51f83fc46 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 14:54:22 -0500 Subject: [PATCH 05/10] Break out setup --- examples/grpc-samples/services.md | 2 +- examples/grpc-samples/{grpc.md => setup.md} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename examples/grpc-samples/{grpc.md => setup.md} (100%) diff --git a/examples/grpc-samples/services.md b/examples/grpc-samples/services.md index a87e9eab5..4d3cf4b06 100644 --- a/examples/grpc-samples/services.md +++ b/examples/grpc-samples/services.md @@ -6,7 +6,7 @@ runme: ## ProjectService -Flags match the launcher arguments in .vscode/launch.json. +Flags match the launcher arguments in `.vscode/launch.json` for `Debug Server`. Be sure to complete [setup.md](setup.md). List available operations: diff --git a/examples/grpc-samples/grpc.md b/examples/grpc-samples/setup.md similarity index 100% rename from examples/grpc-samples/grpc.md rename to examples/grpc-samples/setup.md From b8be143b8301c71ea9903c9ee8d30ce5154eb6f1 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 14:55:16 -0500 Subject: [PATCH 06/10] Fix headline --- examples/grpc-samples/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/grpc-samples/setup.md b/examples/grpc-samples/setup.md index 3dc615879..55fd35e78 100644 --- a/examples/grpc-samples/setup.md +++ b/examples/grpc-samples/setup.md @@ -4,7 +4,7 @@ runme: version: v2.2 --- -# GRPC Kernel +# GRPC Setup Install system dependencies: From 9f4eaf36445d33a7f7c215d71af03124e1a43b79 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 15:04:08 -0500 Subject: [PATCH 07/10] Return default lifecycle identity if options are nil --- internal/document/editor/editorservice/service.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/document/editor/editorservice/service.go b/internal/document/editor/editorservice/service.go index 6f45d2ac6..fe2a647fa 100644 --- a/internal/document/editor/editorservice/service.go +++ b/internal/document/editor/editorservice/service.go @@ -26,7 +26,7 @@ func NewParserServiceServer(logger *zap.Logger) parserv1.ParserServiceServer { func (s *parserServiceServer) Deserialize(_ context.Context, req *parserv1.DeserializeRequest) (*parserv1.DeserializeResponse, error) { s.logger.Info("Deserialize", zap.ByteString("source", req.Source[:min(len(req.Source), 64)])) - identityResolver := identity.NewResolver(fromProtoRunmeIdentityToLifecycleIdentity(req.Options.Identity)) + identityResolver := identity.NewResolver(fromProtoDeserializeReqOptionsToLifecycleIdentity(req.Options)) notebook, err := editor.Deserialize(req.Source, identityResolver) if err != nil { s.logger.Info("failed to call Deserialize", zap.Error(err)) @@ -237,7 +237,13 @@ func (*parserServiceServer) serializeCellOutputs(cell *parserv1.Cell, options *p return outputs } -func fromProtoRunmeIdentityToLifecycleIdentity(idt parserv1.RunmeIdentity) identity.LifecycleIdentity { +func fromProtoDeserializeReqOptionsToLifecycleIdentity(opt *parserv1.DeserializeRequestOptions) identity.LifecycleIdentity { + var idt parserv1.RunmeIdentity + + if opt != nil { + idt = opt.Identity + } + switch idt { case parserv1.RunmeIdentity_RUNME_IDENTITY_ALL: return identity.AllLifecycleIdentity @@ -246,6 +252,6 @@ func fromProtoRunmeIdentityToLifecycleIdentity(idt parserv1.RunmeIdentity) ident case parserv1.RunmeIdentity_RUNME_IDENTITY_CELL: return identity.CellLifecycleIdentity default: - return identity.UnspecifiedLifecycleIdentity + return identity.DefaultLifecycleIdentity } } From f291147e8a45385f8a867e59146faead6bf18613 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 15:08:15 -0500 Subject: [PATCH 08/10] Use json file --- examples/grpc-samples/resolve-vars.json | 6 ++++++ examples/grpc-samples/services.md | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 examples/grpc-samples/resolve-vars.json diff --git a/examples/grpc-samples/resolve-vars.json b/examples/grpc-samples/resolve-vars.json new file mode 100644 index 000000000..552d5b9d3 --- /dev/null +++ b/examples/grpc-samples/resolve-vars.json @@ -0,0 +1,6 @@ +{ + "script": "export NAME=\"Noname\"\nexport LICENSE=$(cat ../LICENSE)\necho \"LICENSE: $LICENSE\"", + "env": [ + "LICENSE=" + ] +} diff --git a/examples/grpc-samples/services.md b/examples/grpc-samples/services.md index 4d3cf4b06..708419583 100644 --- a/examples/grpc-samples/services.md +++ b/examples/grpc-samples/services.md @@ -55,11 +55,11 @@ $ grpcurl \ Resolve variable inside cells: -```sh {"id":"01HNGQS6TV8YKQAKE0ZD7TZREH","promptEnv":"false"} +```sh {"id":"01HNGQS6TV8YKQAKE0ZD7TZREH","promptEnv":"false","terminalRows":"15"} $ grpcurl \ -cacert /tmp/runme/tls/cert.pem \ -cert /tmp/runme/tls/cert.pem \ -key /tmp/runme/tls/key.pem \ - -d "{\"script\":\"export NAME=Noname\", \"env\":[\"NAME=Sebastian\"]}" \ - 127.0.0.1:9999 runme.runner.v1.RunnerService/ResolveEnv + -d @ \ + 127.0.0.1:9999 runme.runner.v1.RunnerService/ResolveVars < resolve-vars.json ``` From d4ca82e0cd06094845d82c34ab507ed7c3634a78 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 15:23:44 -0500 Subject: [PATCH 09/10] Return default only if unset --- internal/document/editor/editorservice/service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/document/editor/editorservice/service.go b/internal/document/editor/editorservice/service.go index fe2a647fa..d8299f9f7 100644 --- a/internal/document/editor/editorservice/service.go +++ b/internal/document/editor/editorservice/service.go @@ -251,6 +251,8 @@ func fromProtoDeserializeReqOptionsToLifecycleIdentity(opt *parserv1.Deserialize return identity.DocumentLifecycleIdentity case parserv1.RunmeIdentity_RUNME_IDENTITY_CELL: return identity.CellLifecycleIdentity + case parserv1.RunmeIdentity_RUNME_IDENTITY_UNSPECIFIED: + return identity.UnspecifiedLifecycleIdentity default: return identity.DefaultLifecycleIdentity } From de50d53efd1bf3da05c3ff828d3f8b11adf2df57 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Fri, 2 Feb 2024 15:33:26 -0500 Subject: [PATCH 10/10] Fix plural --- examples/grpc-samples/services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/grpc-samples/services.md b/examples/grpc-samples/services.md index 708419583..181c6fc14 100644 --- a/examples/grpc-samples/services.md +++ b/examples/grpc-samples/services.md @@ -53,7 +53,7 @@ $ grpcurl \ 127.0.0.1:9999 list runme.runner.$VERSION.RunnerService ``` -Resolve variable inside cells: +Resolve variables inside cell: ```sh {"id":"01HNGQS6TV8YKQAKE0ZD7TZREH","promptEnv":"false","terminalRows":"15"} $ grpcurl \