summaryrefslogtreecommitdiff
path: root/magefile.go
blob: 5e1779952a51447cdfe6829e45d36a4613e822cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//go:build mage
// +build mage

package main

import (
	"context"
	"runtime"

	"github.com/magefile/mage/mg"
	"github.com/magefile/mage/sh"
)

// Default target to run when none is specified
// If not set, running mage will list available targets
var Default = Run

// 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 gRPC Server
func Rpc(ctx context.Context) error {
	mg.CtxDeps(ctx, Protos)
	env := map[string]string{
		"PORT": "50051",
		"HOST": "localhost",
	}
	return sh.RunWithV(env, "ruby", "./bin/rpc")
}

// Open a web browser to the login page
func Browser() error {
	url := "http://localhost:8080/ui/sessions/new"
	if runtime.GOOS == "linux" {
		return sh.RunV("xdg-open", url)
	} else {
		return sh.RunV("open", url)
	}
}

// Generate gRPC from protocal buffers
func Protos() error {
	return sh.RunV(
		"grpc_tools_ruby_protoc",
		"--proto_path=./protos",
		"--ruby_out=lib",
		"--grpc_out=lib",
		"protos/ability.proto",
	)
}

// Run All the servers
func Run(ctx context.Context) {
	mg.CtxDeps(ctx, Idp, UI, Api, Rpc, Gateway)
}