//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") } // Generate gRPC from protocal buffers func Protos() error { outDir := "lib/authx/rpc" for _, file := range x.Must(filepath.Glob("./protos/*.proto")) { if err := sh.RunV( "protoc", "--proto_path=./protos", "--ruby_out="+outDir, "--twirp_ruby_out="+outDir, file, ); err != nil { return err } } return nil } // Run All the servers func Servers(ctx context.Context) { mg.CtxDeps(ctx, Idp, UI, Api, 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", "./...") }