Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/image.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
def all_images():
cmds = {
"piped": "piped",
"server": "server",
"ops": "ops",
"pipecd": "pipecd",
"helloworld": "helloworld",
}
images = {}
Expand Down
26 changes: 0 additions & 26 deletions cmd/ops/BUILD.bazel

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/ops/OWNERS

This file was deleted.

35 changes: 0 additions & 35 deletions cmd/ops/main.go

This file was deleted.

12 changes: 7 additions & 5 deletions cmd/server/BUILD.bazel → cmd/pipecd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -42,7 +44,7 @@ go_library(
)

go_binary(
name = "server",
name = "pipecd",
data = [
"//pkg/app/web:public_files",
],
Expand All @@ -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"],
)
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions cmd/server/main.go → cmd/pipecd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
65 changes: 8 additions & 57 deletions pkg/app/ops/cmd/server/server.go → cmd/pipecd/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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),
}
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
18 changes: 9 additions & 9 deletions cmd/server/server.go → cmd/pipecd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 0 additions & 3 deletions cmd/server/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
6 changes: 3 additions & 3 deletions manifests/pipecd/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions pkg/app/ops/cmd/server/BUILD.bazel

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/model/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down