From b05e045ef00083a3c37d5bc4bff65b483c164dc0 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 7 Feb 2020 14:31:55 +0100 Subject: [PATCH 1/3] chore(scaffolder): Reworking some issues with the scaffolder setup and cookiecutter --- backend/scaffolder/app/server.go | 9 +++++---- backend/scaffolder/lib/git.go | 5 ++++- .../react-ssr-template/template-info.json | 19 +------------------ secrets.env.example | 1 + 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/backend/scaffolder/app/server.go b/backend/scaffolder/app/server.go index d3422e1819..9678a3fe79 100644 --- a/backend/scaffolder/app/server.go +++ b/backend/scaffolder/app/server.go @@ -39,8 +39,9 @@ func (s *Server) Create(ctx context.Context, req *pb.CreateRequest) (*pb.CreateR Org: req.Org, Private: req.Private, } + if _, err := s.github.CreateRepository(repo); err != nil { - return nil, status.Error(codes.Internal, fmt.Sprintf("Could not create repository %s/%s", req.Org, req.ComponentId)) + return nil, status.Error(codes.Internal, fmt.Sprintf("Could not create repository %s/%s %s", req.Org, req.ComponentId, err)) } // move the template into a temporary directory @@ -51,7 +52,7 @@ func (s *Server) Create(ctx context.Context, req *pb.CreateRequest) (*pb.CreateR ) if err != nil { - return nil, status.Error(codes.Internal, "Could not prepare the template") + return nil, status.Error(codes.Internal, fmt.Sprintf("Could not prepare the template %s", err)) } // get the optional metadatafields from the json @@ -59,7 +60,7 @@ func (s *Server) Create(ctx context.Context, req *pb.CreateRequest) (*pb.CreateR cutterMetadata, err := marshaler.MarshalToString(req.Metadata) if err != nil { - return nil, status.Error(codes.Internal, "Could not marshal the cookiecutter metadata") + return nil, status.Error(codes.Internal, fmt.Sprintf("Could not marshal the cookiecutter metadata %s", err)) } cookieTemplate := lib.CookieCutterTemplate{ @@ -86,7 +87,7 @@ func (s *Server) Create(ctx context.Context, req *pb.CreateRequest) (*pb.CreateR } if err := s.git.Push(pushOptions); err != nil { - return nil, status.Error(codes.Internal, "Failed to push the repository to Github") + return nil, status.Error(codes.Internal, fmt.Sprinf("Failed to push the repository to Github %s", err)) } return &pb.CreateReply{ diff --git a/backend/scaffolder/lib/git.go b/backend/scaffolder/lib/git.go index 38306a208b..4ccf818445 100644 --- a/backend/scaffolder/lib/git.go +++ b/backend/scaffolder/lib/git.go @@ -23,7 +23,10 @@ type PushRepositoryOptions struct { // Push will push the repository to github func (g *Git) Push(options PushRepositoryOptions) error { // use git bindings to add the remote with access token and push to the directory - repo, err := git.PlainInit(options.TempFolder, false) + repo, err := git.PlainInit( + fmt.Sprintf("%s/%s", options.TempFolder, options.ComponentID), + false, + ) if err != nil { log.Printf("Failed to init the git repository") return err diff --git a/backend/scaffolder/templates/react-ssr-template/template-info.json b/backend/scaffolder/templates/react-ssr-template/template-info.json index 9d99168e07..f1d3efd9fe 100644 --- a/backend/scaffolder/templates/react-ssr-template/template-info.json +++ b/backend/scaffolder/templates/react-ssr-template/template-info.json @@ -2,22 +2,5 @@ "id": "react-ssr-template", "name": "React SSR", "description": "Next.js application skeleton for creating isomorphic web applications.", - "ownerId": "ownerId", - "fields": [ - { - "id": "description", - "title": "description", - "type": "text", - "description": "Description of the component", - "validators": [ - { "type": "required" }, - { "type": "string-range", "min": 4, "max": 33 }, - { - "type": "regex", - "match": "^[a-z][a-z0-9]+$", - "message": "Owner names must consist only of lowercase letters" - } - ] - } - ] + "ownerId": "ownerId" } \ No newline at end of file diff --git a/secrets.env.example b/secrets.env.example index c83bd2158b..94635d7100 100644 --- a/secrets.env.example +++ b/secrets.env.example @@ -2,3 +2,4 @@ NODE_ENV=development NODE_DEBUG=true REACT_APP_GRAPHQL_API="" BOSS_GH_ACCESS_TOKEN="" +BOSS_GH_USERNAME="" From c00304a14300923d7882efe803dca7fac3f21085 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 7 Feb 2020 15:05:45 +0100 Subject: [PATCH 2/3] chore: fixing docker compose --- docker-compose.yaml | 4 ++++ secrets.env.example | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index ddde99b79a..b917b64aeb 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -41,6 +41,10 @@ services: env_file: secrets.env scaffolder: + depends_on: + - inventory + links: + - inventory container_name: boss-scaffolder build: context: backend diff --git a/secrets.env.example b/secrets.env.example index 94635d7100..cad253f585 100644 --- a/secrets.env.example +++ b/secrets.env.example @@ -1,5 +1,5 @@ NODE_ENV=development NODE_DEBUG=true -REACT_APP_GRAPHQL_API="" -BOSS_GH_ACCESS_TOKEN="" -BOSS_GH_USERNAME="" +REACT_APP_GRAPHQL_API= +BOSS_GH_ACCESS_TOKEN= +BOSS_GH_USERNAME= From f44fa8f5562e50a9ccb4609d038ec96de703cfae Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 7 Feb 2020 15:06:11 +0100 Subject: [PATCH 3/3] feat(scaffolder): uipdating scaffolder --- backend/scaffolder/app/server.go | 13 ++++++++++++- backend/scaffolder/lib/git.go | 1 + .../template-info.json | 6 ++++++ .../ios-swift-app-template/template-info.json | 6 ++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/template-info.json create mode 100644 backend/scaffolder/templates/ios-swift-app-template/template-info.json diff --git a/backend/scaffolder/app/server.go b/backend/scaffolder/app/server.go index 9678a3fe79..3be05cfc4a 100644 --- a/backend/scaffolder/app/server.go +++ b/backend/scaffolder/app/server.go @@ -6,6 +6,9 @@ import ( "github.com/golang/protobuf/jsonpb" identity "github.com/spotify/backstage/backend/proto/identity/v1" pb "github.com/spotify/backstage/backend/proto/scaffolder/v1" + + // "google.golang.org/grpc" + inventory "github.com/spotify/backstage/backend/proto/inventory/v1" "github.com/spotify/backstage/scaffolder/fs" "github.com/spotify/backstage/scaffolder/lib" "github.com/spotify/backstage/scaffolder/repository" @@ -21,10 +24,18 @@ type Server struct { fs *fs.Filesystem cookie *lib.Cutter git *lib.Git + inventory inventory.InventoryClient } // NewServer creates a new server for with all the things func NewServer() *Server { + // conn, errc := grpc.Dial("http://inventory:50051") + + // if err != nil { + // log.Fatal("Cannot connect to inventory service") + // } + + //inventory: inventory.NewInventoryClient(conn), return &Server{ github: lib.NewGithubClient(), } @@ -87,7 +98,7 @@ func (s *Server) Create(ctx context.Context, req *pb.CreateRequest) (*pb.CreateR } if err := s.git.Push(pushOptions); err != nil { - return nil, status.Error(codes.Internal, fmt.Sprinf("Failed to push the repository to Github %s", err)) + return nil, status.Error(codes.Internal, fmt.Sprintf("Failed to push the repository to Github %s", err)) } return &pb.CreateReply{ diff --git a/backend/scaffolder/lib/git.go b/backend/scaffolder/lib/git.go index 4ccf818445..455fae5850 100644 --- a/backend/scaffolder/lib/git.go +++ b/backend/scaffolder/lib/git.go @@ -27,6 +27,7 @@ func (g *Git) Push(options PushRepositoryOptions) error { fmt.Sprintf("%s/%s", options.TempFolder, options.ComponentID), false, ) + if err != nil { log.Printf("Failed to init the git repository") return err diff --git a/backend/scaffolder/templates/android-kotlin-module-template/template-info.json b/backend/scaffolder/templates/android-kotlin-module-template/template-info.json new file mode 100644 index 0000000000..b7c4e51790 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/template-info.json @@ -0,0 +1,6 @@ +{ + "id": "android-kotlin-module", + "name": "Kotlin Module", + "description": "Kotlin module sample", + "ownerId": "ownerId" +} \ No newline at end of file diff --git a/backend/scaffolder/templates/ios-swift-app-template/template-info.json b/backend/scaffolder/templates/ios-swift-app-template/template-info.json new file mode 100644 index 0000000000..4e29396ce6 --- /dev/null +++ b/backend/scaffolder/templates/ios-swift-app-template/template-info.json @@ -0,0 +1,6 @@ +{ + "id": "ios-swift-app-template", + "name": "Swift App", + "description": "The a sample swift app", + "ownerId": "ownerId" +} \ No newline at end of file