From f7065e0b4de97cbafcb732c459f8744d2f5c55e5 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 28 Mar 2025 21:40:05 -0600 Subject: chore: extract magefiles directory --- magefile.go | 116 ---------------------------------------- magefiles/magefile.go | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 116 deletions(-) delete mode 100644 magefile.go create mode 100644 magefiles/magefile.go diff --git a/magefile.go b/magefile.go deleted file mode 100644 index 4ce8e00..0000000 --- a/magefile.go +++ /dev/null @@ -1,116 +0,0 @@ -//go:build mage -// +build mage - -package main - -import ( - "context" - "path/filepath" - - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" - "github.com/xlgmokha/x/pkg/x" -) - -// Default target to run when none is specified -// If not set, running mage will list available targets -var Default = Servers - -// Run the Identity Provider -func Idp() error { - env := map[string]string{ - "SCHEME": "http", - "PORT": "8282", - "HOST": "idp.example.com:8080", - } - return sh.RunWithV(env, "ruby", "./bin/idp") -} - -// Run the UI (a.k.a Service Provider) -func UI() error { - env := map[string]string{ - "SCHEME": "http", - "PORT": "8283", - "HOST": "ui.example.com:8080", - "IDP_HOST": "idp.example.com:8080", - } - return sh.RunWithV(env, "ruby", "./bin/ui") -} - -// Run the API Gateway -func Gateway() error { - env := map[string]string{ - "BIND_ADDR": ":8080", - } - return sh.RunWithV(env, "go", "run", "./cmd/gtwy/main.go") -} - -// Run the REST API -func Api() error { - env := map[string]string{ - "SCHEME": "http", - "PORT": "8284", - "HOST": "localhost:8284", - } - return sh.RunWithV(env, "ruby", "./bin/api") -} - -// Run the Authzd Service -func Authzd() error { - env := map[string]string{ - "BIND_ADDR": ":50051", - } - return sh.RunWithV(env, "go", "run", "./cmd/authzd/main.go") -} - -// Generate gRPC from protocal buffers -func Protos() error { - for _, file := range x.Must(filepath.Glob("./protos/*.proto")) { - if err := sh.RunV( - "protoc", - "--proto_path=./protos", - "--go_out=pkg/rpc", - "--go_opt=paths=source_relative", - "--go-grpc_out=pkg/rpc", - "--go-grpc_opt=paths=source_relative", - "--ruby_out=lib/authx/rpc", - "--twirp_ruby_out=lib/authx/rpc", - file, - ); err != nil { - return err - } - } - - return nil -} - -// Run All the servers -func Servers(ctx context.Context) { - mg.CtxDeps(ctx, Idp, UI, Api, Authzd, Gateway) -} - -// Run the end to end tests -func Test(ctx context.Context) error { - mg.CtxDeps(ctx, func() error { - return sh.RunV("go", "clean", "-testcache") - }) - return sh.RunV("go", "test", "-shuffle=on", "-v", "./...") -} - -func Graphviz() error { - files := []string{ - "doc/share/authz/sns.dot", - } - for _, file := range files { - if err := sh.RunV("dot", "-Tpng", "-O", file); err != nil { - return err - } - } - - return nil -} - -// Generate documentation -func Docs(ctx context.Context) { - mg.CtxDeps(ctx, Graphviz) -} diff --git a/magefiles/magefile.go b/magefiles/magefile.go new file mode 100644 index 0000000..5f5c0ff --- /dev/null +++ b/magefiles/magefile.go @@ -0,0 +1,143 @@ +//go:build mage +// +build mage + +package main + +import ( + "context" + "os" + "path/filepath" + + "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" + "github.com/xlgmokha/x/pkg/x" +) + +// Default target to run when none is specified +// If not set, running mage will list available targets +var Default = Servers + +// Run the Identity Provider +func Idp() error { + env := map[string]string{ + "SCHEME": "http", + "PORT": "8282", + "HOST": "idp.example.com:8080", + } + return sh.RunWithV(env, "ruby", "./bin/idp") +} + +// Run the UI (a.k.a Service Provider) +func UI() error { + env := map[string]string{ + "SCHEME": "http", + "PORT": "8283", + "HOST": "ui.example.com:8080", + "IDP_HOST": "idp.example.com:8080", + } + return sh.RunWithV(env, "ruby", "./bin/ui") +} + +// Run the API Gateway +func Gateway() error { + env := map[string]string{ + "BIND_ADDR": ":8080", + } + return sh.RunWithV(env, "go", "run", "./cmd/gtwy/main.go") +} + +// Run the REST API +func Api() error { + env := map[string]string{ + "SCHEME": "http", + "PORT": "8284", + "HOST": "localhost:8284", + } + return sh.RunWithV(env, "ruby", "./bin/api") +} + +// Run the Authzd Service +func Authzd() error { + env := map[string]string{ + "BIND_ADDR": ":50051", + } + return sh.RunWithV(env, "go", "run", "./cmd/authzd/main.go") +} + +// Start NATS server +func Nats() error { + return sh.RunV( + "nats-server", + "--addr=127.0.0.1", + "--port=4222", + "--http_port=8222", + "--pid=tmp/pids/nats.pid", + "--jetstream", + "--store_dir=tmp/nats/store", + ) +} + +// Start CA +func CertificateAuthority() error { + env := map[string]string{ + "STEPPATH": filepath.Join(x.Must(os.Getwd()), "/tmp/step"), + } + return sh.RunWithV( + env, + "step-ca", + "$STEPPATH/config/ca.json", + "--password-file=$STEPPATH/password.txt", + ) +} + +// Generate gRPC from protocal buffers +func Protos() error { + for _, file := range x.Must(filepath.Glob("./protos/*.proto")) { + if err := sh.RunV( + "protoc", + "--proto_path=./protos", + "--go_out=pkg/rpc", + "--go_opt=paths=source_relative", + "--go-grpc_out=pkg/rpc", + "--go-grpc_opt=paths=source_relative", + "--ruby_out=lib/authx/rpc", + "--twirp_ruby_out=lib/authx/rpc", + file, + ); err != nil { + return err + } + } + + return nil +} + +// Run All the servers +func Servers(ctx context.Context) { + mg.CtxDeps(ctx, CertificateAuthority, Nats, Idp, UI, Api, Authzd, CertificateAuthority, Gateway) +} + +// Run the end to end tests +func Test(ctx context.Context) error { + mg.CtxDeps(ctx, func() error { + return sh.RunV("go", "clean", "-testcache") + }) + return sh.RunV("go", "test", "-shuffle=on", "-v", "./...") +} + +func Graphviz() error { + files := []string{ + "doc/share/authz/sns.dot", + } + for _, file := range files { + if err := sh.RunV("dot", "-Tpng", "-O", file); err != nil { + return err + } + } + + return nil +} + +// Generate documentation +func Docs(ctx context.Context) { + mg.CtxDeps(ctx, Graphviz) +} -- cgit v1.2.3