Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remaster: a reckoning of weird ideas (+ add gRPC runtime service) #186

Merged
merged 37 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c34a19e
forward.go -> runner.go
vito Jun 6, 2022
544f426
order-dependent scope JSON encoding/decoding
vito Jun 8, 2022
fc88ea0
Bass runtime is no longer a runtime
vito Jun 5, 2022
1895518
Value.String -> Value.Repr
vito Apr 15, 2022
6da2615
add protobufs
vito Apr 15, 2022
6a38d40
checkpoint: runtimes take protos
vito Jun 5, 2022
cd1676d
wip
vito Jun 5, 2022
375c8d4
wip
vito Jun 5, 2022
9f2a074
checkpoint
vito Jun 6, 2022
f7984fc
go back to bass types for runtimes and memos
vito Jun 6, 2022
7b488d0
grpc runtime client/server
vito Jun 6, 2022
999373e
memos.json -> bass.lock
vito Jun 8, 2022
907359d
memos.lock -> bass.lock
vito Jun 9, 2022
b1a1050
Repr() -> back to String()
vito Jun 9, 2022
7d87dea
ensure Bindings.Scope/NewScope deterministic order
vito Jun 9, 2022
8595e71
fix a ton of protobuf marshal/unmarshal issues
vito Jun 9, 2022
069553c
use protobuf encoding for thunk equality
vito Jun 9, 2022
1159ef1
implement Export/ExportPath runtime grpc
vito Jun 9, 2022
f9d8281
get rid of automatic (un)hyphenation
vito Jun 9, 2022
3e16ef2
undocument hyphens
vito Jun 9, 2022
be6a181
fix bass --bump
vito Jun 9, 2022
b4efae0
support decoding *Scope into maps
vito Jun 9, 2022
3faeff8
fix data race with scope recursion detection
vito Jun 9, 2022
cb884ac
remove oneof proto stutter
vito Jun 10, 2022
5f35cbf
avoid unneccessary JSON conversion for inputs
vito Jun 10, 2022
6074fbe
better proto naming
vito Jun 11, 2022
f058ce2
use protobuf for memos
vito Jun 11, 2022
9435200
eliminate duck-typed JSON pattern (Descope)
vito Jun 11, 2022
0c7f3c2
update/restore .lock files
vito Jun 11, 2022
37b5ede
replace protobuf fspath with logical paths
vito Jun 11, 2022
0d4bdd1
eliminate fs IDs
vito Jun 11, 2022
a63ca80
stop implicitly adding .bass when (load)ing thunks
vito Jun 11, 2022
2b9de41
bump tabs
vito Jun 11, 2022
2037d30
bump nix vendorsha
vito Jun 12, 2022
5070fcf
remove unneeded FromValue impls
vito Jun 12, 2022
286bd14
keep sensitive secrets out of protobuf
vito Jun 12, 2022
95e7c26
replace (str-thunk) with just using a list
vito Jun 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pkg/runtimes/bin/exe.%: pkg/runtimes/shim/main.go
cmd/bass/bass: shims
env GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=$(VERSION)" -o ./cmd/bass/bass ./cmd/bass

pkg/proto/%.pb.go: proto/%.proto
protoc -I=./proto --go_out=. --go-grpc_out=. proto/$*.proto

nix/vendorSha256.txt: go.mod go.sum
./hack/get-nix-vendorsha > $@

Expand All @@ -26,6 +29,9 @@ install: cmd/bass/bass
mkdir -p $(DESTDIR)
cp $< $(DESTDIR)

.PHONY: proto
proto: pkg/proto/bass.pb.go pkg/proto/runtime.pb.go pkg/proto/progress.pb.go pkg/proto/memo.pb.go

.PHONY: clean
clean:
rm -f cmd/bass/bass $(shims)
4 changes: 2 additions & 2 deletions bass/bass.bass
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

; load dependencies
(use (.git (linux/alpine/git))
(git:github/vito/tabs/ref/main/nix))
(git:github/vito/tabs/ref/main/nix.bass))

; clones the repo and checks out the given sha
(defn checkout [sha]
Expand Down Expand Up @@ -152,7 +152,7 @@
(undo-wordwrap src (src/notes/ notes)))))

(provide [release]
(use (git:github/vito/tabs/ref/main/gh))
(use (git:github/vito/tabs/ref/main/gh.bass))

; returns the github release module
(defn release [token]
Expand Down
2 changes: 1 addition & 1 deletion bass/bass.lock
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ memos: {
}
output: {
string: {
value: "66938767c1fa545039225b4a06d7edc4a67a46cf"
value: "d2b84a954119fa7506192aa5c0a9be7fa291500a"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions bass/checks
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bass

(use (.git (linux/alpine/git))
(*dir*/bass)
(*dir*/github))
(*dir*/bass.bass)
(*dir*/github.bass))

; a github client that uses commit statuses for checks
(defn status-client [repo]
Expand Down
2 changes: 1 addition & 1 deletion bass/github.bass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bass

(provide [start-status]
(def *memos* *dir*/memos.json)
(def *memos* *dir*/bass.lock)

; starts the thunk and reflects its status as a Commit Status
(defn start-status [thunk name sha repo auth]
Expand Down
2 changes: 1 addition & 1 deletion bass/shipit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

; load libraries
(use (.strings)
(*dir*/bass))
(*dir*/bass.bass))

; builds and publishes a GitHub release
;
Expand Down
5 changes: 3 additions & 2 deletions bass/test
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env bass

(use (*dir*/bass.bass))

; runs tests against src passed on *stdin*
;
; Emits code coverage to *stdout*.
(defn main testflags
(for [{:src src} *stdin*]
(use (src/project))
(let [tests (project:tests src ["./..." & testflags])]
(let [tests (bass:tests src ["./..." & testflags])]
(log "running tests")
(run tests)
(emit {:coverage tests/cover.html} *stdout*))))
68 changes: 32 additions & 36 deletions cmd/bass/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"context"
"fmt"
"os"
"strings"

"github.com/vito/bass/pkg/bass"
"github.com/vito/bass/pkg/proto"
"github.com/vito/progrock"
"google.golang.org/protobuf/encoding/prototext"
)

func bump(ctx context.Context) error {
Expand All @@ -17,63 +17,59 @@ func bump(ctx context.Context) error {
return err
}

var lf bass.LockfileContent
err = bass.UnmarshalJSON(lockContent, &lf)
content := &proto.Memosphere{}
err = prototext.Unmarshal(lockContent, content)
if err != nil {
return err
}

for thunkFn, pairs := range lf.Data {
segs := strings.SplitN(thunkFn, ":", 2)
if len(segs) != 2 {
return fmt.Errorf("malformed bass.lock key: %q", thunkFn)
}

thunkID := segs[0]
fn := bass.Symbol(segs[1])
thunk := lf.Thunks[thunkID]

runtime, err := bass.RuntimeFromContext(ctx, nil)
for _, memo := range content.Memos {
thunk := bass.Thunk{}
err := thunk.UnmarshalProto(memo.Module)
if err != nil {
return err
}

scope, err := runtime.Load(ctx, thunk)
scope, err := bass.Bass.Load(ctx, thunk)
if err != nil {
return err
}

var comb bass.Combiner
err = scope.GetDecode(fn, &comb)
if err != nil {
return err
}
for _, call := range memo.Calls {
binding := bass.Symbol(call.Binding)

for i, pair := range pairs {
res, err := bass.Trampoline(ctx, comb.Call(ctx, pair.Input.Value, bass.NewEmptyScope(), bass.Identity))
var comb bass.Combiner
err = scope.GetDecode(binding, &comb)
if err != nil {
return err
}

// update reference inline
pairs[i].Output.Value = res
}
}
for _, res := range call.Results {
input, err := bass.FromProto(res.Input)
if err != nil {
return err
}

lockFile, err := os.Create(bumpLock)
if err != nil {
return err
}
out, err := bass.Trampoline(ctx, comb.Call(ctx, input, bass.NewEmptyScope(), bass.Identity))
if err != nil {
return err
}

output, err := bass.MarshalProto(out)
if err != nil {
return err
}

defer lockFile.Close()
res.Output = output
}
}
}

enc := bass.NewEncoder(lockFile)
enc.SetIndent("", " ")
err = enc.Encode(lf)
payload, err := prototext.MarshalOptions{Multiline: true}.Marshal(content)
if err != nil {
return err
}

return nil
return os.WriteFile(bumpLock, payload, 0644)
})
}
25 changes: 18 additions & 7 deletions cmd/bass/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"archive/tar"
"context"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -17,20 +18,25 @@ import (

func export(ctx context.Context) error {
return withProgress(ctx, "export", func(ctx context.Context, vertex *progrock.VertexRecorder) error {
dec := bass.NewDecoder(os.Stdin)
dec := bass.NewRawDecoder(os.Stdin)

var val bass.Value
err := dec.Decode(&val)
var msg json.RawMessage
err := dec.Decode(&msg)
if err != nil {
return err
}

var errs error

var path bass.ThunkPath
err = val.Decode(&path)
err = json.Unmarshal([]byte(msg), &path)
if err == nil {
runtime, err := bass.RuntimeFromContext(ctx, path.Thunk.Platform())
platform := path.Thunk.Platform()
if platform == nil {
return fmt.Errorf("cannot export bass thunk path: %s", path)
}

runtime, err := bass.RuntimeFromContext(ctx, *platform)
if err != nil {
return err
}
Expand All @@ -43,9 +49,14 @@ func export(ctx context.Context) error {
}

var thunk bass.Thunk
err = val.Decode(&thunk)
err = json.Unmarshal([]byte(msg), &path)
if err == nil {
runtime, err := bass.RuntimeFromContext(ctx, thunk.Platform())
platform := path.Thunk.Platform()
if platform == nil {
return fmt.Errorf("cannot export bass thunk: %s", thunk)
}

runtime, err := bass.RuntimeFromContext(ctx, *platform)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bass/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func root(ctx context.Context) error {
ctx = bass.WithRuntimePool(ctx, pool)

if runnerAddr != "" {
return runnerLoop(ctx, runnerAddr, config.Runtimes)
return runnerLoop(ctx, runnerAddr, pool.Runtimes)
}

if runExport {
Expand Down
7 changes: 1 addition & 6 deletions cmd/bass/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -51,11 +50,7 @@ func run(ctx context.Context, filePath string, argv ...string) error {

stdin := bass.Stdin
if len(inputs) > 0 {
stdin, err = cli.InputsSource(inputs)
if err != nil {
err = fmt.Errorf("inputs: %w", err)
return
}
stdin = cli.InputsSource(inputs)
}

scope := bass.NewRunScope(bass.Ground, bass.RunState{
Expand Down
9 changes: 4 additions & 5 deletions cmd/bass/forward.go → cmd/bass/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/cenkalti/backoff/v4"
"github.com/vito/bass/pkg/bass"
"github.com/vito/bass/pkg/runtimes"
"github.com/vito/bass/pkg/zapctx"
"github.com/vito/progrock"
Expand All @@ -31,20 +30,20 @@ var defaultKeys = []string{
"id_rsa",
}

func runnerLoop(ctx context.Context, sshAddr string, configs []bass.RuntimeConfig) error {
func runnerLoop(ctx context.Context, sshAddr string, assoc []runtimes.Assoc) error {
ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
defer stop()

return withProgress(ctx, "runner", func(ctx context.Context, bassVertex *progrock.VertexRecorder) (err error) {
exp := backoff.NewExponentialBackOff()
exp.MaxElapsedTime = 0 // https://www.youtube.com/watch?v=6BtuqUX934U
return backoff.Retry(func() error {
return runner(ctx, sshAddr, configs)
return runner(ctx, sshAddr, assoc)
}, exp)
})
}

func runner(ctx context.Context, sshAddr string, configs []bass.RuntimeConfig) error {
func runner(ctx context.Context, sshAddr string, assoc []runtimes.Assoc) error {
ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
defer stop()

Expand Down Expand Up @@ -137,7 +136,7 @@ func runner(ctx context.Context, sshAddr string, configs []bass.RuntimeConfig) e
}

forwards := new(errgroup.Group)
for _, runtime := range configs {
for _, runtime := range assoc {
runtime := runtime
forwards.Go(func() error {
return client.Forward(ctx, runtime)
Expand Down
Loading