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
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ genrule(
# gazelle:exclude pkg/app/helloworld/service/service.pb.validate.go
# gazelle:exclude pkg/app/api/service/webservice/service.pb.validate.go
# gazelle:exclude pkg/app/api/service/pipedservice/service.pb.validate.go
# gazelle:exclude pkg/app/api/service/apiservice/service.pb.validate.go
# gazelle:exclude pkg/model/apikey.pb.validate.go
# gazelle:exclude pkg/model/application.pb.validate.go
# gazelle:exclude pkg/model/application_live_state.pb.validate.go
Expand All @@ -51,6 +52,7 @@ genrule(
# gazelle:exclude pkg/model/deployment.pb.validate.go
# gazelle:exclude pkg/model/environment.pb.validate.go
# gazelle:exclude pkg/model/event.pb.validate.go
# gazelle:exclude pkg/model/insight.pb.validate.go
# gazelle:exclude pkg/model/logblock.pb.validate.go
# gazelle:exclude pkg/model/piped.pb.validate.go
# gazelle:exclude pkg/model/piped_stats.pb.validate.go
Expand Down
1 change: 1 addition & 0 deletions cmd/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ def all_images():
cmds = {
"piped": "piped",
"pipecd": "pipecd",
"pipectl": "pipectl",
"helloworld": "helloworld",
}
images = {}
Expand Down
1 change: 1 addition & 0 deletions cmd/pipecd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//pkg/admin:go_default_library",
"//pkg/app/api/apikeyverifier:go_default_library",
"//pkg/app/api/applicationlivestatestore:go_default_library",
"//pkg/app/api/authhandler:go_default_library",
"//pkg/app/api/commandstore:go_default_library",
Expand Down
45 changes: 36 additions & 9 deletions cmd/pipecd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/pipe-cd/pipe/pkg/admin"
"github.com/pipe-cd/pipe/pkg/app/api/apikeyverifier"
"github.com/pipe-cd/pipe/pkg/app/api/applicationlivestatestore"
"github.com/pipe-cd/pipe/pkg/app/api/authhandler"
"github.com/pipe-cd/pipe/pkg/app/api/commandstore"
Expand Down Expand Up @@ -65,6 +66,7 @@ type server struct {
pipedAPIPort int
webAPIPort int
httpPort int
apiPort int
adminPort int
staticDir string
cacheAddress string
Expand All @@ -87,6 +89,7 @@ func NewServerCommand() *cobra.Command {
pipedAPIPort: 9080,
webAPIPort: 9081,
httpPort: 9082,
apiPort: 9083,
adminPort: 9085,
staticDir: "pkg/app/web/public_files",
cacheAddress: "cache:6379",
Expand All @@ -101,6 +104,7 @@ func NewServerCommand() *cobra.Command {
cmd.Flags().IntVar(&s.pipedAPIPort, "piped-api-port", s.pipedAPIPort, "The port number used to run a grpc server that serving serves incoming piped requests.")
cmd.Flags().IntVar(&s.webAPIPort, "web-api-port", s.webAPIPort, "The port number used to run a grpc server that serves incoming web requests.")
cmd.Flags().IntVar(&s.httpPort, "http-port", s.httpPort, "The port number used to run a http server that serves incoming http requests such as auth callbacks or webhook events.")
cmd.Flags().IntVar(&s.apiPort, "api-port", s.apiPort, "The port number used to run a grpc server for external apis.")
cmd.Flags().IntVar(&s.adminPort, "admin-port", s.adminPort, "The port number used to run a HTTP server for admin tasks such as metrics, healthz.")
cmd.Flags().StringVar(&s.staticDir, "static-dir", s.staticDir, "The directory where contains static assets.")
cmd.Flags().StringVar(&s.cacheAddress, "cache-address", s.cacheAddress, "The address to cache service.")
Expand Down Expand Up @@ -136,11 +140,6 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error {
}
t.Logger.Info("successfully loaded control-plane configuration")

var (
pipedAPIServer *rpc.Server
webAPIServer *rpc.Server
)

ds, err := createDatastore(ctx, cfg, t.Logger)
if err != nil {
t.Logger.Error("failed to create datastore", zap.Error(err))
Expand Down Expand Up @@ -204,9 +203,37 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error {
opts = append(opts, rpc.WithGRPCReflection())
}

pipedAPIServer = rpc.NewServer(service, opts...)
server := rpc.NewServer(service, opts...)
group.Go(func() error {
return server.Run(ctx)
})
}

// Start a gRPC server for handling external API requests.
{
var (
verifier = apikeyverifier.NewVerifier(
ctx,
datastore.NewAPIKeyStore(ds),
t.Logger,
)
service = grpcapi.NewAPI(ds, cmds, t.Logger)
opts = []rpc.Option{
rpc.WithPort(s.apiPort),
rpc.WithGracePeriod(s.gracePeriod),
rpc.WithLogger(t.Logger),
rpc.WithLogUnaryInterceptor(t.Logger),
rpc.WithAPIKeyAuthUnaryInterceptor(verifier, t.Logger),
rpc.WithRequestValidationUnaryInterceptor(),
}
)
if s.tls {
opts = append(opts, rpc.WithTLS(s.certFile, s.keyFile))
}

server := rpc.NewServer(service, opts...)
group.Go(func() error {
return pipedAPIServer.Run(ctx)
return server.Run(ctx)
})
}

Expand Down Expand Up @@ -239,9 +266,9 @@ func (s *server) run(ctx context.Context, t cli.Telemetry) error {
opts = append(opts, rpc.WithGRPCReflection())
}

webAPIServer = rpc.NewServer(service, opts...)
server := rpc.NewServer(service, opts...)
group.Go(func() error {
return webAPIServer.Run(ctx)
return server.Run(ctx)
})
}

Expand Down
23 changes: 23 additions & 0 deletions cmd/pipectl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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/pipectl",
visibility = ["//visibility:private"],
deps = ["//pkg/cli:go_default_library"],
)

go_binary(
name = "pipectl",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)

app_image(
name = "pipectl_app",
binary = ":pipectl",
repository = "pipectl",
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions cmd/pipectl/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
labels:
- area/pipectl
34 changes: 34 additions & 0 deletions cmd/pipectl/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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/cli"
)

func main() {
app := cli.NewApp(
"pipectl",
"The command line tool for PipeCD.",
)

app.AddCommands()

if err := app.Run(); err != nil {
log.Fatal(err)
}
}
3 changes: 3 additions & 0 deletions manifests/pipecd/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ spec:
- name: http
containerPort: 9082
protocol: TCP
- name: api
containerPort: 9083
protocol: TCP
- name: admin
containerPort: 9085
protocol: TCP
Expand Down
19 changes: 19 additions & 0 deletions manifests/pipecd/templates/envoy-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ data:
grpc:
route:
cluster: server-web-api
- match:
prefix: /pipe.api.service.apiservice.APIService/
grpc:
route:
cluster: server-api
- match:
prefix: /
route:
Expand Down Expand Up @@ -111,6 +116,20 @@ data:
socket_address:
address: {{ include "pipecd.fullname" . }}-server
port_value: 9081
- name: server-api
http2_protocol_options: {}
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
load_assignment:
cluster_name: server-api
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{ include "pipecd.fullname" . }}-server
port_value: 9083
- name: server-http
#http2_protocol_options: {}
connect_timeout: 0.25s
Expand Down
3 changes: 3 additions & 0 deletions manifests/pipecd/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ spec:
- name: http
port: 9082
targetPort: http
- name: api
port: 9083
targetPort: api
- name: admin
port: 9085
targetPort: admin
Expand Down
3 changes: 3 additions & 0 deletions pkg/app/api/grpcapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"api.go",
"deployment_config_templates.go",
"piped_api.go",
"web_api.go",
Expand All @@ -13,6 +14,7 @@ go_library(
deps = [
"//pkg/app/api/applicationlivestatestore:go_default_library",
"//pkg/app/api/commandstore:go_default_library",
"//pkg/app/api/service/apiservice:go_default_library",
"//pkg/app/api/service/pipedservice:go_default_library",
"//pkg/app/api/service/webservice:go_default_library",
"//pkg/app/api/stagelogstore:go_default_library",
Expand All @@ -36,6 +38,7 @@ go_test(
name = "go_default_test",
size = "small",
srcs = [
"api_test.go",
"piped_api_test.go",
"web_api_test.go",
],
Expand Down
67 changes: 67 additions & 0 deletions pkg/app/api/grpcapi/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 grpcapi

import (
"context"

"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pipe-cd/pipe/pkg/app/api/commandstore"
"github.com/pipe-cd/pipe/pkg/app/api/service/apiservice"
"github.com/pipe-cd/pipe/pkg/datastore"
)

// API implements the behaviors for the gRPC definitions of API.
type API struct {
applicationStore datastore.ApplicationStore
deploymentStore datastore.DeploymentStore
pipedStore datastore.PipedStore
commandStore commandstore.Store

logger *zap.Logger
}

// NewAPI creates a new API instance.
func NewAPI(
ds datastore.DataStore,
cmds commandstore.Store,
logger *zap.Logger,
) *API {
a := &API{
applicationStore: datastore.NewApplicationStore(ds),
deploymentStore: datastore.NewDeploymentStore(ds),
pipedStore: datastore.NewPipedStore(ds),
commandStore: cmds,
logger: logger.Named("api"),
}
return a
}

// Register registers all handling of this service into the specified gRPC server.
func (a *API) Register(server *grpc.Server) {
apiservice.RegisterAPIServiceServer(server, a)
}

func (a *API) AddApplication(_ context.Context, _ *apiservice.AddApplicationRequest) (*apiservice.AddApplicationResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

func (a *API) SyncApplication(_ context.Context, _ *apiservice.SyncApplicationRequest) (*apiservice.SyncApplicationResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
15 changes: 15 additions & 0 deletions pkg/app/api/grpcapi/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 grpcapi
37 changes: 37 additions & 0 deletions pkg/app/api/service/apiservice/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("//bazel:pgv_go_proto.bzl", "pgv_go_proto_library")

proto_library(
name = "apiservice_proto",
srcs = ["service.proto"],
visibility = ["//visibility:public"],
# keep
deps = [
"//pkg/model:model_proto",
"@com_github_envoyproxy_protoc_gen_validate//validate:validate_proto",
],
)

pgv_go_proto_library(
name = "apiservice_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/pipe-cd/pipe/pkg/app/api/service/apiservice",
proto = ":apiservice_proto",
visibility = ["//visibility:public"],
deps = [
"//pkg/model:go_default_library",
],
)

go_library(
name = "go_default_library",
srcs = ["client.go"],
embed = [":apiservice_go_proto"],
importpath = "github.com/pipe-cd/pipe/pkg/app/api/service/apiservice",
visibility = ["//visibility:public"],
deps = [
"//pkg/rpc/rpcclient:go_default_library",
"@org_golang_google_grpc//:go_default_library",
],
)
Loading