diff --git a/cmd/image.bzl b/cmd/image.bzl index 71aa29b9b6..43d59d2979 100644 --- a/cmd/image.bzl +++ b/cmd/image.bzl @@ -1,8 +1,7 @@ def all_images(): cmds = { "piped": "piped", - "server": "server", - "ops": "ops", + "pipecd": "pipecd", "helloworld": "helloworld", } images = {} diff --git a/cmd/ops/BUILD.bazel b/cmd/ops/BUILD.bazel deleted file mode 100644 index 31e9a6b491..0000000000 --- a/cmd/ops/BUILD.bazel +++ /dev/null @@ -1,26 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") -load("//bazel:image.bzl", "app_image") - -go_library( - name = "go_default_library", - srcs = ["main.go"], - importpath = "github.com/pipe-cd/pipe/cmd/ops", - visibility = ["//visibility:private"], - deps = [ - "//pkg/app/ops/cmd/server:go_default_library", - "//pkg/cli:go_default_library", - ], -) - -go_binary( - name = "ops", - embed = [":go_default_library"], - visibility = ["//visibility:public"], -) - -app_image( - name = "ops_app", - binary = ":ops", - repository = "ops", - visibility = ["//visibility:public"], -) diff --git a/cmd/ops/OWNERS b/cmd/ops/OWNERS deleted file mode 100644 index d3c75e1199..0000000000 --- a/cmd/ops/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -labels: - - area/ops diff --git a/cmd/ops/main.go b/cmd/ops/main.go deleted file mode 100644 index f9ea2c260c..0000000000 --- a/cmd/ops/main.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2020 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "log" - - "github.com/pipe-cd/pipe/pkg/app/ops/cmd/server" - "github.com/pipe-cd/pipe/pkg/cli" -) - -func main() { - app := cli.NewApp( - "ops", - "A single component for operating owner tasks such as adding new project, deleting old data.", - ) - app.AddCommands( - server.NewCommand(), - ) - if err := app.Run(); err != nil { - log.Fatal(err) - } -} diff --git a/cmd/server/BUILD.bazel b/cmd/pipecd/BUILD.bazel similarity index 89% rename from cmd/server/BUILD.bazel rename to cmd/pipecd/BUILD.bazel index 0978dd0125..cba832d612 100644 --- a/cmd/server/BUILD.bazel +++ b/cmd/pipecd/BUILD.bazel @@ -5,9 +5,10 @@ go_library( name = "go_default_library", srcs = [ "main.go", + "ops.go", "server.go", ], - importpath = "github.com/pipe-cd/pipe/cmd/server", + importpath = "github.com/pipe-cd/pipe/cmd/pipecd", visibility = ["//visibility:private"], deps = [ "//pkg/admin:go_default_library", @@ -18,6 +19,7 @@ go_library( "//pkg/app/api/pipedverifier:go_default_library", "//pkg/app/api/service/webservice:go_default_library", "//pkg/app/api/stagelogstore:go_default_library", + "//pkg/app/ops/handler:go_default_library", "//pkg/cache/rediscache:go_default_library", "//pkg/cli:go_default_library", "//pkg/config:go_default_library", @@ -42,7 +44,7 @@ go_library( ) go_binary( - name = "server", + name = "pipecd", data = [ "//pkg/app/web:public_files", ], @@ -51,8 +53,8 @@ go_binary( ) app_image( - name = "server_app", - binary = ":server", - repository = "server", + name = "pipecd_app", + binary = ":pipecd", + repository = "pipecd", visibility = ["//visibility:public"], ) diff --git a/cmd/server/OWNERS b/cmd/pipecd/OWNERS similarity index 100% rename from cmd/server/OWNERS rename to cmd/pipecd/OWNERS diff --git a/cmd/ops/README.md b/cmd/pipecd/README.md similarity index 100% rename from cmd/ops/README.md rename to cmd/pipecd/README.md diff --git a/cmd/server/main.go b/cmd/pipecd/main.go similarity index 86% rename from cmd/server/main.go rename to cmd/pipecd/main.go index 0d4c2670cf..b537d81b93 100644 --- a/cmd/server/main.go +++ b/cmd/pipecd/main.go @@ -22,11 +22,12 @@ import ( func main() { app := cli.NewApp( - "server", - "A server for handling incoming gRPC, HTTP requests and serving static assets for web.", + "pipecd", + "Control-plane component for PipeCD.", ) app.AddCommands( - NewCommand(), + NewServerCommand(), + NewOpsCommand(), ) if err := app.Run(); err != nil { log.Fatal(err) diff --git a/pkg/app/ops/cmd/server/server.go b/cmd/pipecd/ops.go similarity index 63% rename from pkg/app/ops/cmd/server/server.go rename to cmd/pipecd/ops.go index 71b0ae46cc..2fb5d57bc7 100644 --- a/pkg/app/ops/cmd/server/server.go +++ b/cmd/pipecd/ops.go @@ -12,12 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package server +package main import ( "context" - "errors" - "fmt" "net/http" "time" @@ -28,29 +26,25 @@ import ( "github.com/pipe-cd/pipe/pkg/admin" "github.com/pipe-cd/pipe/pkg/app/ops/handler" "github.com/pipe-cd/pipe/pkg/cli" - "github.com/pipe-cd/pipe/pkg/config" "github.com/pipe-cd/pipe/pkg/datastore" - "github.com/pipe-cd/pipe/pkg/datastore/firestore" - "github.com/pipe-cd/pipe/pkg/datastore/mongodb" - "github.com/pipe-cd/pipe/pkg/model" "github.com/pipe-cd/pipe/pkg/version" ) -type server struct { +type ops struct { httpPort int adminPort int gracePeriod time.Duration configFile string } -func NewCommand() *cobra.Command { - s := &server{ +func NewOpsCommand() *cobra.Command { + s := &ops{ httpPort: 9082, adminPort: 9085, gracePeriod: 15 * time.Second, } cmd := &cobra.Command{ - Use: "server", + Use: "ops", Short: "Start running ops server.", RunE: cli.WithContext(s.run), } @@ -62,11 +56,11 @@ func NewCommand() *cobra.Command { return cmd } -func (s *server) run(ctx context.Context, t cli.Telemetry) error { +func (s *ops) run(ctx context.Context, t cli.Telemetry) error { group, ctx := errgroup.WithContext(ctx) // Load control plane configuration from the specified file. - cfg, err := s.loadConfig() + cfg, err := loadConfig(s.configFile) if err != nil { t.Logger.Error("failed to load control-plane configuration", zap.String("config-file", s.configFile), @@ -76,7 +70,7 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error { } // Connect to the data store. - ds, err := s.createDatastore(ctx, cfg, t.Logger) + ds, err := createDatastore(ctx, cfg, t.Logger) if err != nil { t.Logger.Error("failed to create datastore", zap.Error(err)) return err @@ -126,46 +120,3 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error { } return nil } - -func (s *server) loadConfig() (*config.ControlPlaneSpec, error) { - cfg, err := config.LoadFromYAML(s.configFile) - if err != nil { - return nil, err - } - if cfg.Kind != config.KindControlPlane { - return nil, fmt.Errorf("wrong configuration kind for control-plane: %v", cfg.Kind) - } - return cfg.ControlPlaneSpec, nil -} - -func (s *server) createDatastore(ctx context.Context, cfg *config.ControlPlaneSpec, logger *zap.Logger) (datastore.DataStore, error) { - switch cfg.Datastore.Type { - case model.DataStoreFirestore: - fsConfig := cfg.Datastore.FirestoreConfig - options := []firestore.Option{ - firestore.WithCredentialsFile(fsConfig.CredentialsFile), - firestore.WithLogger(logger), - } - return firestore.NewFireStore(ctx, fsConfig.Project, fsConfig.Namespace, fsConfig.Environment, options...) - - case model.DataStoreDynamoDB: - return nil, errors.New("dynamodb is unimplemented yet") - - case model.DataStoreMongoDB: - mdConfig := cfg.Datastore.MongoDBConfig - options := []mongodb.Option{ - mongodb.WithLogger(logger), - } - if mdConfig.UsernameFile != "" || mdConfig.PasswordFile != "" { - options = append(options, mongodb.WithAuthenticationFile(mdConfig.UsernameFile, mdConfig.PasswordFile)) - } - return mongodb.NewMongoDB( - ctx, - mdConfig.URL, - mdConfig.Database, - options..., - ) - default: - return nil, fmt.Errorf("unknown datastore type %q", cfg.Datastore.Type) - } -} diff --git a/cmd/server/server.go b/cmd/pipecd/server.go similarity index 95% rename from cmd/server/server.go rename to cmd/pipecd/server.go index 5450159d7f..9b8f08fce2 100644 --- a/cmd/server/server.go +++ b/cmd/pipecd/server.go @@ -81,8 +81,8 @@ type server struct { enableGRPCReflection bool } -// NewCommand creates a new cobra command for executing api server. -func NewCommand() *cobra.Command { +// NewServerCommand creates a new cobra command for executing api server. +func NewServerCommand() *cobra.Command { s := &server{ pipedAPIPort: 9080, webAPIPort: 9081, @@ -126,7 +126,7 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error { group, ctx := errgroup.WithContext(ctx) // Load control plane configuration from the specified file. - cfg, err := s.loadConfig() + cfg, err := loadConfig(s.configFile) if err != nil { t.Logger.Error("failed to load control-plane configuration", zap.String("config-file", s.configFile), @@ -141,7 +141,7 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error { webAPIServer *rpc.Server ) - ds, err := s.createDatastore(ctx, cfg, t.Logger) + ds, err := createDatastore(ctx, cfg, t.Logger) if err != nil { t.Logger.Error("failed to create datastore", zap.Error(err)) return err @@ -154,7 +154,7 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error { }() t.Logger.Info("succesfully connected to data store") - fs, err := s.createFilestore(ctx, cfg, t.Logger) + fs, err := createFilestore(ctx, cfg, t.Logger) if err != nil { t.Logger.Error("failed to create filestore", zap.Error(err)) return err @@ -354,8 +354,8 @@ func runHTTPServer(ctx context.Context, httpServer *http.Server, gracePeriod tim return <-doneCh } -func (s *server) loadConfig() (*config.ControlPlaneSpec, error) { - cfg, err := config.LoadFromYAML(s.configFile) +func loadConfig(file string) (*config.ControlPlaneSpec, error) { + cfg, err := config.LoadFromYAML(file) if err != nil { return nil, err } @@ -365,7 +365,7 @@ func (s *server) loadConfig() (*config.ControlPlaneSpec, error) { return cfg.ControlPlaneSpec, nil } -func (s *server) createDatastore(ctx context.Context, cfg *config.ControlPlaneSpec, logger *zap.Logger) (datastore.DataStore, error) { +func createDatastore(ctx context.Context, cfg *config.ControlPlaneSpec, logger *zap.Logger) (datastore.DataStore, error) { switch cfg.Datastore.Type { case model.DataStoreFirestore: fsConfig := cfg.Datastore.FirestoreConfig @@ -396,7 +396,7 @@ func (s *server) createDatastore(ctx context.Context, cfg *config.ControlPlaneSp } } -func (s *server) createFilestore(ctx context.Context, cfg *config.ControlPlaneSpec, logger *zap.Logger) (filestore.Store, error) { +func createFilestore(ctx context.Context, cfg *config.ControlPlaneSpec, logger *zap.Logger) (filestore.Store, error) { ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() diff --git a/cmd/server/README.md b/cmd/server/README.md deleted file mode 100644 index 5b5a5cd503..0000000000 --- a/cmd/server/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Development - -See [this documentation](https://pipecd.dev/docs/contribution-guidelines/control-plane-development/). diff --git a/docs/content/en/docs/contribution-guidelines/control-plane-development.md b/docs/content/en/docs/contribution-guidelines/control-plane-development.md index 660e495aa7..4715a8ed21 100644 --- a/docs/content/en/docs/contribution-guidelines/control-plane-development.md +++ b/docs/content/en/docs/contribution-guidelines/control-plane-development.md @@ -8,8 +8,7 @@ description: > ## Source code structure -- [cmd/server](https://github.com/pipe-cd/pipe/tree/master/cmd/server): entrypoint for binary of control-plane server. - +- [cmd/pipecd](https://github.com/pipe-cd/pipe/tree/master/cmd/pipecd): entrypoint for binary of control-plane server. - [pkg/app/api](https://github.com/pipe-cd/pipe/tree/master/pkg/app/api): contains source code for control-plane api. - [pkg/app/web](https://github.com/pipe-cd/pipe/tree/master/pkg/app/web): contains source code for control-plane web. - [pkg](https://github.com/pipe-cd/pipe/tree/master/pkg): contains shared source code for all components of both `piped` and `control-plane`. diff --git a/manifests/pipecd/templates/deployment.yaml b/manifests/pipecd/templates/deployment.yaml index 3581678b84..05f7ed7d4c 100644 --- a/manifests/pipecd/templates/deployment.yaml +++ b/manifests/pipecd/templates/deployment.yaml @@ -86,7 +86,7 @@ spec: spec: containers: - name: server - image: "gcr.io/pipecd/server:{{ .Chart.AppVersion }}" + image: "gcr.io/pipecd/pipecd:{{ .Chart.AppVersion }}" imagePullPolicy: IfNotPresent args: - server @@ -205,10 +205,10 @@ spec: spec: containers: - name: ops - image: "gcr.io/pipecd/ops:{{ .Chart.AppVersion }}" + image: "gcr.io/pipecd/pipecd:{{ .Chart.AppVersion }}" imagePullPolicy: IfNotPresent args: - - server + - ops - --config-file=/etc/pipecd-config/{{ .Values.config.fileName }} ports: - name: http diff --git a/pkg/app/ops/cmd/server/BUILD.bazel b/pkg/app/ops/cmd/server/BUILD.bazel deleted file mode 100644 index 5fb31a49b6..0000000000 --- a/pkg/app/ops/cmd/server/BUILD.bazel +++ /dev/null @@ -1,22 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["server.go"], - importpath = "github.com/pipe-cd/pipe/pkg/app/ops/cmd/server", - visibility = ["//visibility:public"], - deps = [ - "//pkg/admin:go_default_library", - "//pkg/app/ops/handler:go_default_library", - "//pkg/cli:go_default_library", - "//pkg/config:go_default_library", - "//pkg/datastore:go_default_library", - "//pkg/datastore/firestore:go_default_library", - "//pkg/datastore/mongodb:go_default_library", - "//pkg/model:go_default_library", - "//pkg/version:go_default_library", - "@com_github_spf13_cobra//:go_default_library", - "@org_golang_x_sync//errgroup:go_default_library", - "@org_uber_go_zap//:go_default_library", - ], -) diff --git a/pkg/model/BUILD.bazel b/pkg/model/BUILD.bazel index cc55ea480c..f2c0765703 100644 --- a/pkg/model/BUILD.bazel +++ b/pkg/model/BUILD.bazel @@ -12,8 +12,8 @@ proto_library( "deployment.proto", "environment.proto", "event.proto", - "logblock.proto", "insight.proto", + "logblock.proto", "piped.proto", "piped_stats.proto", "project.proto",