diff --git a/backend/builds/go.mod b/backend/builds/go.mod index de684f7593..bc0cc2216f 100644 --- a/backend/builds/go.mod +++ b/backend/builds/go.mod @@ -5,6 +5,7 @@ go 1.12 replace github.com/spotify/backstage/proto => ../proto require ( + github.com/prometheus/common v0.9.1 github.com/spotify/backstage/proto v0.0.0-00010101000000-000000000000 google.golang.org/grpc v1.27.1 ) diff --git a/backend/builds/go.sum b/backend/builds/go.sum index 2193d76f62..4bfe18f317 100644 --- a/backend/builds/go.sum +++ b/backend/builds/go.sum @@ -1,19 +1,69 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -22,17 +72,25 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -50,5 +108,10 @@ google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/backend/builds/main.go b/backend/builds/main.go index 6dbf49de1f..19c4141b03 100644 --- a/backend/builds/main.go +++ b/backend/builds/main.go @@ -7,6 +7,7 @@ import ( "github.com/spotify/backstage/builds/ghactions" "github.com/spotify/backstage/builds/service" buildsv1 "github.com/spotify/backstage/proto/builds/v1" + inventoryv1 "github.com/spotify/backstage/proto/inventory/v1" "google.golang.org/grpc" ) @@ -22,12 +23,19 @@ func main() { } grpcServer := grpc.NewServer() + conn, err := grpc.Dial("inventory:50051", grpc.WithInsecure()) + if err != nil { + log.Fatal("Cannot connect to inventory service") + } + + inventory := inventoryv1.NewInventoryClient(conn) + ghClient, err := ghactions.NewFromEnv() if err != nil { log.Fatalf("Failed to create github client, %s", err) } - buildsv1.RegisterBuildsServer(grpcServer, service.New(ghClient)) + buildsv1.RegisterBuildsServer(grpcServer, service.New(ghClient, inventory)) log.Println("Serving Builds Service") grpcServer.Serve(lis) diff --git a/backend/builds/service/service.go b/backend/builds/service/service.go index d792704242..9bdc70421c 100644 --- a/backend/builds/service/service.go +++ b/backend/builds/service/service.go @@ -5,27 +5,62 @@ import ( "fmt" "regexp" + "github.com/prometheus/common/log" "github.com/spotify/backstage/builds/ghactions" buildsv1 "github.com/spotify/backstage/proto/builds/v1" + inventoryv1 "github.com/spotify/backstage/proto/inventory/v1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) type service struct { - ghClient *ghactions.Client + ghClient *ghactions.Client + inventory inventoryv1.InventoryClient } var _ buildsv1.BuildsServer = (*service)(nil) // New creates a new identity data server -func New(ghClient *ghactions.Client) buildsv1.BuildsServer { - return &service{ghClient} +func New(ghClient *ghactions.Client, inventory inventoryv1.InventoryClient) buildsv1.BuildsServer { + return &service{ghClient, inventory} } func (s *service) ListBuilds(ctx context.Context, req *buildsv1.ListBuildsRequest) (*buildsv1.ListBuildsReply, error) { + uri := req.GetEntityUri() + kind, id, err := s.parseEntityURI(uri) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "Invalid build URI '%s', %s", uri, err) + } + owner := "spotify" repo := "backstage" + ownerReq, err := s.inventory.GetFact(ctx, &inventoryv1.GetFactRequest{ + EntityUri: fmt.Sprintf("boss://%s/%s", kind, id), + Name: "githubOwner", + }) + if err != nil { + log.Errorf("Failed to fetch owner for %s, defaulting to %s", uri, owner) + } + if ownerReq.GetFact().GetValue() != "" { + owner = ownerReq.Fact.GetValue() + } else { + log.Errorf("No owner found for %s, defaulting to %s", uri, owner) + } + + repotReq, err := s.inventory.GetFact(ctx, &inventoryv1.GetFactRequest{ + EntityUri: fmt.Sprintf("boss://%s/%s", kind, id), + Name: "githubRepo", + }) + if err != nil { + log.Errorf("Failed to fetch repo for %s, defaulting to %s", uri, repo) + } + if repotReq.GetFact().GetValue() != "" { + repo = repotReq.GetFact().GetValue() + } else { + log.Errorf("No repo found for %s, defaulting to %s", uri, owner) + } + result, err := s.ghClient.ListWorkflowRuns(ctx, owner, repo) if err != nil { return nil, status.Errorf(codes.Internal, "Failed to fetch workflow runs for %s/%s, %s", owner, repo, err) @@ -104,17 +139,32 @@ func (s *service) transformBuild(owner, repo string, run *ghactions.WorkflowRunR } } -var entityURIRegex = regexp.MustCompile("^entity:build:([^/:]+)/([^/:]+)/([^/:]+)$") +var buildURIRegex = regexp.MustCompile("^entity:build:([^/:]+)/([^/:]+)/([^/:]+)$") func (s *service) parseBuildURI(uri string) (owner, repo, runID string, err error) { if uri == "" { return "", "", "", fmt.Errorf("uri is empty") } - match := entityURIRegex.FindStringSubmatch(uri) + match := buildURIRegex.FindStringSubmatch(uri) if match == nil { return "", "", "", fmt.Errorf("uri does not match") } return match[1], match[2], match[3], nil } + +var entityURIRegex = regexp.MustCompile("^entity:([^:]+):([^:]+)$") + +func (s *service) parseEntityURI(uri string) (kind, id string, err error) { + if uri == "" { + return "", "", fmt.Errorf("uri is empty") + } + + match := entityURIRegex.FindStringSubmatch(uri) + if match == nil { + return "", "", fmt.Errorf("uri does not match") + } + + return match[1], match[2], nil +} diff --git a/backend/inventory/app/server.go b/backend/inventory/app/server.go index eb5850c4b2..d000047ebd 100644 --- a/backend/inventory/app/server.go +++ b/backend/inventory/app/server.go @@ -39,10 +39,18 @@ func (s *Server) ListEntities(ctx context.Context, req *pb.ListEntitiesRequest) } func (s *Server) CreateEntity(ctx context.Context, req *pb.CreateEntityRequest) (*pb.CreateEntityReply, error) { - err := s.Storage.CreateEntity(req.GetEntity().GetUri()) + uri := req.GetEntity().GetUri() + err := s.Storage.CreateEntity(uri) if err != nil { return nil, status.Error(codes.Internal, "could not create entity") } + for _, fact := range req.GetEntity().GetFacts() { + if fact.GetName() != "" { + if err := s.Storage.SetFact(uri, fact.GetName(), fact.GetValue()); err != nil { + return nil, status.Errorf(codes.Internal, "failed to set fact %s, %s", fact.GetName(), err) + } + } + } return &pb.CreateEntityReply{Entity: req.GetEntity()}, nil } diff --git a/backend/scaffolder/app/server.go b/backend/scaffolder/app/server.go index eab414a596..bdb164f58a 100644 --- a/backend/scaffolder/app/server.go +++ b/backend/scaffolder/app/server.go @@ -5,9 +5,8 @@ import ( "fmt" "github.com/golang/protobuf/jsonpb" identity "github.com/spotify/backstage/backend/proto/identity/v1" - pb "github.com/spotify/backstage/backend/proto/scaffolder/v1" - inventory "github.com/spotify/backstage/backend/proto/inventory/v1" + pb "github.com/spotify/backstage/backend/proto/scaffolder/v1" "github.com/spotify/backstage/scaffolder/fs" "github.com/spotify/backstage/scaffolder/lib" "github.com/spotify/backstage/scaffolder/repository" @@ -15,6 +14,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "log" + "os" ) // Server is the inventory Grpc server @@ -105,6 +105,20 @@ func (s *Server) Create(ctx context.Context, req *pb.CreateRequest) (*pb.CreateR _, err = s.inventory.CreateEntity(ctx, &inventory.CreateEntityRequest{ Entity: &inventory.Entity{ Uri: fmt.Sprintf("boss://service/%s", req.ComponentId), + Facts: []*inventory.Fact{ + { + Name: "githubOwner", + Value: os.Getenv("BOSS_GH_USERNAME"), + }, + { + Name: "githubRepo", + Value: req.ComponentId, + }, + { + Name: "backstageTemplate", + Value: req.TemplateId, + }, + }, }, }) diff --git a/backend/scaffolder/lib/cutter.go b/backend/scaffolder/lib/cutter.go index 501e643dec..98b313761c 100644 --- a/backend/scaffolder/lib/cutter.go +++ b/backend/scaffolder/lib/cutter.go @@ -28,6 +28,7 @@ func (c *Cutter) WriteMetadata(template CookieCutterTemplate) error { } temporaryCookieCutter["component_id"] = template.ComponentID + temporaryCookieCutter["_copy_without_render"] = []string{".github/workflows/*"} finalMetadata, _ := json.Marshal(temporaryCookieCutter) file, err := os.Create(fmt.Sprintf("%s/cookiecutter.json", template.Path)) diff --git a/backend/scaffolder/templates/react-ssr-template/{{cookiecutter.component_id}}/.github/workflows b/backend/scaffolder/templates/react-ssr-template/{{cookiecutter.component_id}}/.github/workflows/build.yml similarity index 96% rename from backend/scaffolder/templates/react-ssr-template/{{cookiecutter.component_id}}/.github/workflows rename to backend/scaffolder/templates/react-ssr-template/{{cookiecutter.component_id}}/.github/workflows/build.yml index 9087876ce2..b82f29562e 100644 --- a/backend/scaffolder/templates/react-ssr-template/{{cookiecutter.component_id}}/.github/workflows +++ b/backend/scaffolder/templates/react-ssr-template/{{cookiecutter.component_id}}/.github/workflows/build.yml @@ -1,9 +1,6 @@ name: Frontend CI -on: - push: - paths: - - '.' +on: [push] jobs: build: diff --git a/docker-compose.yaml b/docker-compose.yaml index 239e0aaf85..bc9e80b2bd 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -37,6 +37,10 @@ services: service: builds restart: unless-stopped env_file: secrets.env + depends_on: + - inventory + links: + - inventory scaffolder: depends_on: diff --git a/frontend/packages/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx b/frontend/packages/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx index 88875c8dcf..6b78460d05 100644 --- a/frontend/packages/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx +++ b/frontend/packages/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx @@ -1,5 +1,5 @@ import React, { FC } from 'react'; -import { RelativeEntityLink } from '@backstage/core'; +import { RelativeEntityLink, useEntity } from '@backstage/core'; import { BuildsClient } from '../../apis/builds'; import { useAsync } from 'react-use'; import { @@ -27,7 +27,8 @@ const useStyles = makeStyles(theme => ({ const BuildInfoCard: FC<{}> = () => { const classes = useStyles(); - const status = useAsync(() => client.listBuilds('entity:spotify:backstage')); + const { kind, id } = useEntity(); + const status = useAsync(() => client.listBuilds(`entity:${kind}:${id}`)); let content: JSX.Element; diff --git a/frontend/packages/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx b/frontend/packages/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx index 4f2f32d0b6..5e684060bf 100644 --- a/frontend/packages/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx +++ b/frontend/packages/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx @@ -13,7 +13,7 @@ import { makeStyles, Theme, } from '@material-ui/core'; -import { RelativeEntityLink } from '@backstage/core'; +import { RelativeEntityLink, useEntity } from '@backstage/core'; import { BuildsClient } from '../../apis/builds'; import { useAsync } from 'react-use'; import BuildStatusIndicator from '../BuildStatusIndicator'; @@ -42,7 +42,8 @@ const useStyles = makeStyles(theme => ({ const BuildListPage: FC<{}> = () => { const classes = useStyles(); - const status = useAsync(() => client.listBuilds('entity:spotify:backstage')); + const { kind, id } = useEntity(); + const status = useAsync(() => client.listBuilds(`entity:${kind}:${id}`)); let content: JSX.Element;