From 00b18161e1c55e6565bb9479f2f8917d32f7d8bd Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 10:53:58 +0800 Subject: [PATCH 01/12] fix: remove private error check --- pkg/kt/command/util.go | 2 +- pkg/kt/util/ssh.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kt/command/util.go b/pkg/kt/command/util.go index 16e0600..e7d3d77 100644 --- a/pkg/kt/command/util.go +++ b/pkg/kt/command/util.go @@ -126,7 +126,7 @@ func removePrivateKey(options *options.DaemonOptions) { splits := strings.Split(options.RuntimeOptions.SSHCM, "-") component, version := splits[1], splits[len(splits)-1] file := util.PrivateKeyPath(component, version) - if err := os.Remove(file); !os.IsNotExist(err) { + if err := os.Remove(file); os.IsNotExist(err) { log.Error().Err(err).Msgf("can't delete %s", file) } } diff --git a/pkg/kt/util/ssh.go b/pkg/kt/util/ssh.go index b448256..6ea92df 100644 --- a/pkg/kt/util/ssh.go +++ b/pkg/kt/util/ssh.go @@ -60,7 +60,7 @@ func Generate(privateKeyPath string) (*SSHGenerator, error) { // PrivateKeyPath ... func PrivateKeyPath(component, identifier string) string { - return fmt.Sprintf("%s/ktctl/%s/"+vars.SSHPrivateKeyName, HomeDir(), component, identifier) + return fmt.Sprintf("%s/.ktctl/%s/"+vars.SSHPrivateKeyName, HomeDir(), component, identifier) } // generatePrivateKey creates a RSA Private Key of specified byte size From 15a121d8122da467c382352bc3b565fb8ee5d685 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 11:00:48 +0800 Subject: [PATCH 02/12] ci: use datetime as default tag value. --- Makefile | 2 +- docker/shadow/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7f3bbaf..94149af 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PREFIX ?= registry.cn-hangzhou.aliyuncs.com/rdc-incubator -TAG ?= latest +TAG ?= $(shell date +%s) SHADOW_IMAGE = kt-connect-shadow SHADOW_BASE_IMAGE = shadow-base BUILDER_IMAGE = builder diff --git a/docker/shadow/Dockerfile b/docker/shadow/Dockerfile index fd3b787..cc8d5dd 100644 --- a/docker/shadow/Dockerfile +++ b/docker/shadow/Dockerfile @@ -10,4 +10,4 @@ RUN apt-get install -y net-tools ADD docker/shadow/run.sh /run.sh RUN chmod 755 /run.sh -CMD ["/run.sh"] \ No newline at end of file +ENTRYPOINT ["/run.sh"] \ No newline at end of file From 655af047d5fcc5982c94a095526f694c38f5573c Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 11:14:13 +0800 Subject: [PATCH 03/12] feat: make shadow debug able --- pkg/kt/cluster/kubernetes.go | 74 +++++++++++++++++++++--------------- pkg/kt/cluster/types.go | 2 +- pkg/kt/command/connect.go | 2 +- pkg/kt/command/exchange.go | 2 +- pkg/kt/command/mesh.go | 2 +- pkg/kt/command/run.go | 2 +- 6 files changed, 48 insertions(+), 36 deletions(-) diff --git a/pkg/kt/cluster/kubernetes.go b/pkg/kt/cluster/kubernetes.go index 829bbfa..5831836 100644 --- a/pkg/kt/cluster/kubernetes.go +++ b/pkg/kt/cluster/kubernetes.go @@ -39,8 +39,8 @@ func (k *Kubernetes) Deployment(name, namespace string) (deployment *appV1.Deplo } // CreateShadow create shadow -func (k *Kubernetes) CreateShadow(name, namespace, image string, labels map[string]string) (podIP, podName, sshcm string, credential *util.SSHCredential, err error) { - return CreateShadow(k.Clientset, name, labels, namespace, image) +func (k *Kubernetes) CreateShadow(name, namespace, image string, labels map[string]string, debug bool) (podIP, podName, sshcm string, credential *util.SSHCredential, err error) { + return CreateShadow(k.Clientset, name, labels, namespace, image, debug) } // CreateService create kubernetes service @@ -143,6 +143,7 @@ func CreateShadow( labels map[string]string, namespace, image string, + debug bool, ) (podIP, podName, sshcm string, credential *util.SSHCredential, err error) { component, version := labels["kt-component"], labels["version"] @@ -175,7 +176,7 @@ func CreateShadow( labels["kt"] = name client := clientset.AppsV1().Deployments(namespace) - deployment := generatorDeployment(namespace, name, labels, image, sshcm) + deployment := generatorDeployment(namespace, name, labels, image, sshcm, debug) result, err := client.Create(deployment) if err != nil { return @@ -289,7 +290,43 @@ func generateService(name, namespace string, labels map[string]string, port int) } -func generatorDeployment(namespace, name string, labels map[string]string, image, volume string) *appV1.Deployment { +func generatorDeployment(namespace, name string, labels map[string]string, image, volume string, debug bool) *appV1.Deployment { + + args := []string{} + if debug { + args = append(args, "--debug") + } + + container := v1.Container{ + Name: "standalone", + Image: image, + ImagePullPolicy: "Always", + Args: args, + VolumeMounts: []v1.VolumeMount{ + { + Name: "ssh-public-key", + MountPath: fmt.Sprintf("/root/%s", vars.SSHAuthKey), + }, + }, + } + + sshVolume := v1.Volume{ + Name: "ssh-public-key", + VolumeSource: v1.VolumeSource{ + ConfigMap: &v1.ConfigMapVolumeSource{ + LocalObjectReference: v1.LocalObjectReference{ + Name: volume, + }, + Items: []v1.KeyToPath{ + { + Key: vars.SSHAuthKey, + Path: "authorized_keys", + }, + }, + }, + }, + } + return &appV1.Deployment{ ObjectMeta: metaV1.ObjectMeta{ Name: name, @@ -306,35 +343,10 @@ func generatorDeployment(namespace, name string, labels map[string]string, image }, Spec: v1.PodSpec{ Containers: []v1.Container{ - { - Name: "standalone", - Image: image, - ImagePullPolicy: "Always", - VolumeMounts: []v1.VolumeMount{ - { - Name: "ssh-public-key", - MountPath: fmt.Sprintf("/root/%s", vars.SSHAuthKey), - }, - }, - }, + container, }, Volumes: []v1.Volume{ - { - Name: "ssh-public-key", - VolumeSource: v1.VolumeSource{ - ConfigMap: &v1.ConfigMapVolumeSource{ - LocalObjectReference: v1.LocalObjectReference{ - Name: volume, - }, - Items: []v1.KeyToPath{ - { - Key: vars.SSHAuthKey, - Path: "authorized_keys", - }, - }, - }, - }, - }, + sshVolume, }, }, }, diff --git a/pkg/kt/cluster/types.go b/pkg/kt/cluster/types.go index 33d09be..942be6f 100644 --- a/pkg/kt/cluster/types.go +++ b/pkg/kt/cluster/types.go @@ -26,7 +26,7 @@ type KubernetesInterface interface { Scale(deployment *appV1.Deployment, replicas *int32) (err error) ServiceHosts(namespace string) (hosts map[string]string) ClusterCrids(podCIDR string) (cidrs []string, err error) - CreateShadow(name, namespace, image string, labels map[string]string) (podIP, podName, sshcm string, credential *util.SSHCredential, err error) + CreateShadow(name, namespace, image string, labels map[string]string, debug bool) (podIP, podName, sshcm string, credential *util.SSHCredential, err error) CreateService(name, namespace string, port int, labels map[string]string) (*coreV1.Service, error) } diff --git a/pkg/kt/command/connect.go b/pkg/kt/command/connect.go index ac55b5f..3c24559 100644 --- a/pkg/kt/command/connect.go +++ b/pkg/kt/command/connect.go @@ -110,7 +110,7 @@ func connectToCluster(shadow connect.ShadowInterface, kubernetes cluster.Kuberne workload := fmt.Sprintf("kt-connect-daemon-%s", strings.ToLower(util.RandomString(5))) endPointIP, podName, sshcm, credential, err := kubernetes.CreateShadow( - workload, options.Namespace, options.Image, labels(workload, options), + workload, options.Namespace, options.Image, labels(workload, options), options.Debug, ) if err != nil { diff --git a/pkg/kt/command/exchange.go b/pkg/kt/command/exchange.go index 7d46b37..08cb935 100644 --- a/pkg/kt/command/exchange.go +++ b/pkg/kt/command/exchange.go @@ -70,7 +70,7 @@ func (action *Action) Exchange(exchange string, options *options.DaemonOptions) workload := app.GetName() + "-kt-" + strings.ToLower(util.RandomString(5)) podIP, podName, sshcm, credential, err := kubernetes.CreateShadow( - workload, options.Namespace, options.Image, getExchangeLabels(options.Labels, workload, app)) + workload, options.Namespace, options.Image, getExchangeLabels(options.Labels, workload, app), options.Debug) log.Info().Msgf("create exchange shadow %s in namespace %s", workload, options.Namespace) if err != nil { diff --git a/pkg/kt/command/mesh.go b/pkg/kt/command/mesh.go index dc7efb8..dc42851 100644 --- a/pkg/kt/command/mesh.go +++ b/pkg/kt/command/mesh.go @@ -73,7 +73,7 @@ func (action *Action) Mesh(mesh string, options *options.DaemonOptions) error { workload := app.GetObjectMeta().GetName() + "-kt-" + meshVersion labels := getMeshLabels(workload, meshVersion, app, options) - podIP, podName, sshcm, credential, err := kubernetes.CreateShadow(workload, options.Namespace, options.Image, labels) + podIP, podName, sshcm, credential, err := kubernetes.CreateShadow(workload, options.Namespace, options.Image, labels, options.Debug) if err != nil { return err } diff --git a/pkg/kt/command/run.go b/pkg/kt/command/run.go index 48dd899..e33d348 100644 --- a/pkg/kt/command/run.go +++ b/pkg/kt/command/run.go @@ -64,7 +64,7 @@ func (action *Action) Run(service string, options *options.DaemonOptions) error labels[k] = v } - podIP, podName, sshcm, credential, err := kubernetes.CreateShadow(service, options.Namespace, options.Image, labels) + podIP, podName, sshcm, credential, err := kubernetes.CreateShadow(service, options.Namespace, options.Image, labels, options.Debug) if err != nil { return err } From 06a066922579087f4481e4d5265c839868600732 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 11:19:49 +0800 Subject: [PATCH 04/12] test: add mock generator to makefile and regenerate mock --- Makefile | 6 ++++++ pkg/kt/command/connect_test.go | 6 +++--- pkg/mockd/mock/action_mock.go | 5 +++-- pkg/mockd/mock/connect_mock.go | 5 +++-- pkg/mockd/mock/kubernetes_mock.go | 13 +++++++------ 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 94149af..a005777 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,12 @@ BUILDER_IMAGE = builder DASHBOARD_IMAGE = kt-connect-dashboard SERVER_IMAGE = kt-connect-server +# generate mock +generate-mock: + mockgen -source=pkg/kt/command/types.go -destination=pkg/mockd/mock/action_mock.go -package=mock + mockgen -source=pkg/kt/cluster/types.go -destination=pkg/mockd/mock/kubernetes_mock.go -package=mock + mockgen -source=pkg/kt/connect/types.go -destination=pkg/mockd/mock/connect_mock.go -package=mock + # run unit test unit-test: mkdir -p artifacts/report/coverage diff --git a/pkg/kt/command/connect_test.go b/pkg/kt/command/connect_test.go index 8389dd1..a421bb8 100644 --- a/pkg/kt/command/connect_test.go +++ b/pkg/kt/command/connect_test.go @@ -59,7 +59,7 @@ func Test_shouldConnectToCluster(t *testing.T) { ctl := gomock.NewController(t) kubernetes := mock.NewMockKubernetesInterface(ctl) shadow := mock.NewMockShadowInterface(ctl) - kubernetes.EXPECT().CreateShadow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("172.168.0.2", "shadowName", "sshcm", nil, nil).AnyTimes() + kubernetes.EXPECT().CreateShadow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("172.168.0.2", "shadowName", "sshcm", nil, nil).AnyTimes() kubernetes.EXPECT().ClusterCrids(gomock.Any()).Return([]string{"10.10.10.0/24"}, nil) shadow.EXPECT().Outbound("shadowName", "172.168.0.2", gomock.Any(), []string{"10.10.10.0/24"}).Return(nil) @@ -90,7 +90,7 @@ func Test_shouldConnectClusterFailWhenFailCreateShadow(t *testing.T) { ctl := gomock.NewController(t) kubernetesInterface := mock.NewMockKubernetesInterface(ctl) shadowInterface := mock.NewMockShadowInterface(ctl) - kubernetesInterface.EXPECT().CreateShadow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("", "", "", nil, errors.New("")).AnyTimes() + kubernetesInterface.EXPECT().CreateShadow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("", "", "", nil, errors.New("")).AnyTimes() type args struct { shadow connect.ShadowInterface @@ -115,7 +115,7 @@ func Test_shouldConnectClusterFailWhenFailGetCrids(t *testing.T) { ctl := gomock.NewController(t) kubernetes := mock.NewMockKubernetesInterface(ctl) shadow := mock.NewMockShadowInterface(ctl) - kubernetes.EXPECT().CreateShadow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("172.168.0.2", "shadowName", "sshcm", nil, nil).AnyTimes() + kubernetes.EXPECT().CreateShadow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("172.168.0.2", "shadowName", "sshcm", nil, nil).AnyTimes() kubernetes.EXPECT().ClusterCrids(gomock.Any()).Return([]string{}, errors.New("fail to get crid")) type args struct { diff --git a/pkg/mockd/mock/action_mock.go b/pkg/mockd/mock/action_mock.go index 01f3deb..fa08b21 100644 --- a/pkg/mockd/mock/action_mock.go +++ b/pkg/mockd/mock/action_mock.go @@ -1,13 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: ../kt/command/types.go +// Source: pkg/kt/command/types.go // Package mock is a generated GoMock package. package mock import ( + reflect "reflect" + options "github.com/alibaba/kt-connect/pkg/kt/options" gomock "github.com/golang/mock/gomock" - reflect "reflect" ) // MockActionInterface is a mock of ActionInterface interface diff --git a/pkg/mockd/mock/connect_mock.go b/pkg/mockd/mock/connect_mock.go index e5a8dab..cfde45a 100644 --- a/pkg/mockd/mock/connect_mock.go +++ b/pkg/mockd/mock/connect_mock.go @@ -1,13 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: ../kt/connect/types.go +// Source: pkg/kt/connect/types.go // Package mock is a generated GoMock package. package mock import ( + reflect "reflect" + util "github.com/alibaba/kt-connect/pkg/kt/util" gomock "github.com/golang/mock/gomock" - reflect "reflect" ) // MockShadowInterface is a mock of ShadowInterface interface diff --git a/pkg/mockd/mock/kubernetes_mock.go b/pkg/mockd/mock/kubernetes_mock.go index eaa9e0c..bdfe2ae 100644 --- a/pkg/mockd/mock/kubernetes_mock.go +++ b/pkg/mockd/mock/kubernetes_mock.go @@ -1,15 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: ../kt/cluster/types.go +// Source: pkg/kt/cluster/types.go // Package mock is a generated GoMock package. package mock import ( + reflect "reflect" + util "github.com/alibaba/kt-connect/pkg/kt/util" gomock "github.com/golang/mock/gomock" v1 "k8s.io/api/apps/v1" v10 "k8s.io/api/core/v1" - reflect "reflect" ) // MockKubernetesInterface is a mock of KubernetesInterface interface @@ -94,9 +95,9 @@ func (mr *MockKubernetesInterfaceMockRecorder) ClusterCrids(podCIDR interface{}) } // CreateShadow mocks base method -func (m *MockKubernetesInterface) CreateShadow(name, namespace, image string, labels map[string]string) (string, string, string, *util.SSHCredential, error) { +func (m *MockKubernetesInterface) CreateShadow(name, namespace, image string, labels map[string]string, debug bool) (string, string, string, *util.SSHCredential, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateShadow", name, namespace, image, labels) + ret := m.ctrl.Call(m, "CreateShadow", name, namespace, image, labels, debug) ret0, _ := ret[0].(string) ret1, _ := ret[1].(string) ret2, _ := ret[2].(string) @@ -106,9 +107,9 @@ func (m *MockKubernetesInterface) CreateShadow(name, namespace, image string, la } // CreateShadow indicates an expected call of CreateShadow -func (mr *MockKubernetesInterfaceMockRecorder) CreateShadow(name, namespace, image, labels interface{}) *gomock.Call { +func (mr *MockKubernetesInterfaceMockRecorder) CreateShadow(name, namespace, image, labels, debug interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateShadow", reflect.TypeOf((*MockKubernetesInterface)(nil).CreateShadow), name, namespace, image, labels) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateShadow", reflect.TypeOf((*MockKubernetesInterface)(nil).CreateShadow), name, namespace, image, labels, debug) } // CreateService mocks base method From e67c54ee64fe0879b74864aa6a49f4befe74ce88 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 12:52:40 +0800 Subject: [PATCH 05/12] feat: add bug log --- cmd/shadow/main.go | 6 ++++-- pkg/kt/cluster/kubernetes.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/shadow/main.go b/cmd/shadow/main.go index 5f5e39c..823ab66 100644 --- a/cmd/shadow/main.go +++ b/cmd/shadow/main.go @@ -14,11 +14,13 @@ func init() { } func main() { - log.Info().Msg("Start kt connect proxy") + log.Info().Msg("shadow staring...") srv := dnsserver.NewDNSServerDefault() err := srv.ListenAndServe() if err != nil { + log.Error().Msg(err.Error()) panic(err.Error()) } - log.Info().Msgf("DNS Server Start At 53...\n") + log.Info().Msg("shadow(DNS) start at 53 successful") + log.Info().Msg("shadow start successful") } diff --git a/pkg/kt/cluster/kubernetes.go b/pkg/kt/cluster/kubernetes.go index 5831836..11faadd 100644 --- a/pkg/kt/cluster/kubernetes.go +++ b/pkg/kt/cluster/kubernetes.go @@ -294,7 +294,8 @@ func generatorDeployment(namespace, name string, labels map[string]string, image args := []string{} if debug { - args = append(args, "--debug") + log.Debug().Msg("create shadow with debug mode") + //args = append(args, "--debug") } container := v1.Container{ From 2bd3122ead705f6f824eef90eb1aca3fedae146d Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 13:00:27 +0800 Subject: [PATCH 06/12] ci: clean dockerfile. --- Makefile | 15 +++++---------- docker/apiserver/Dockerfile | 12 +----------- docker/builder/Dockerfile | 12 ------------ docker/dashboard/Dockerfile | 2 +- {config => docker/dashboard}/nginx/default.conf | 0 docker/shadow/Dockerfile_dlv | 7 ++++++- 6 files changed, 13 insertions(+), 35 deletions(-) delete mode 100644 docker/builder/Dockerfile rename {config => docker/dashboard}/nginx/default.conf (100%) diff --git a/Makefile b/Makefile index a005777..9e75f03 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ unit-test: go tool cover -html=artifacts/report/coverage/cover.out -o artifacts/report/coverage/index.html # build kt project -build: build-connect build-shadow +build: build-connect build-shadow build-server build-dashboard # build ktctl build-connect: @@ -37,23 +37,18 @@ build-shadow: docker build -t $(PREFIX)/$(SHADOW_IMAGE):$(TAG) -f docker/shadow/Dockerfile . docker push $(PREFIX)/$(SHADOW_IMAGE):$(TAG) -# build this first,it's the base image -build-builder: - docker build -t $(PREFIX)/$(BUILDER_IMAGE):$(TAG) -f docker/builder/Dockerfile . - # dlv for debug build-shadow-dlv: bin/build-shadow-dlv build-dashboard: - docker build -t $(PREFIX)/$(DASHBOARD_IMAGE):$(TAG) -f docker/dashboard/Dockerfile . && \ + docker build -t $(PREFIX)/$(DASHBOARD_IMAGE):$(TAG) -f docker/dashboard/Dockerfile . + docker push $(PREFIX)/$(DASHBOARD_IMAGE):$(TAG) build-server: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o artifacts/apiserver/apiserver-linux-amd64 cmd/server/main.go docker build -t $(PREFIX)/$(SERVER_IMAGE):$(TAG) -f docker/apiserver/Dockerfile . - -release-docker: build-builder build-shadow-base build-shadow build-connect build-dashboard build-server - docker push $(PREFIX)/$(SHADOW_IMAGE) - # todo: push as you want + docker push $(PREFIX)/$(SERVER_IMAGE):$(TAG) git-release: bin/release \ No newline at end of file diff --git a/docker/apiserver/Dockerfile b/docker/apiserver/Dockerfile index 7f2e5d9..27a6fd7 100644 --- a/docker/apiserver/Dockerfile +++ b/docker/apiserver/Dockerfile @@ -1,13 +1,3 @@ -FROM registry.cn-hangzhou.aliyuncs.com/rdc-incubator/builder as build-deps -LABEL MAINTAINER yunlong -ENV GO111MODULE on - -WORKDIR /go/src/github.com/alibaba/kt-connect -COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o output/kt-apiserver-linux-amd64 cmd/server/main.go - FROM alpine -COPY --from=build-deps /go/src/github.com/alibaba/kt-connect/output/kt-apiserver-linux-amd64 /usr/local/bin/kt-apiserver -LABEL MAINTAINER yunlong - +COPY artifacts/apiserver/apiserver-linux-amd64 /usr/local/bin/kt-apiserver CMD ["kt-apiserver"] \ No newline at end of file diff --git a/docker/builder/Dockerfile b/docker/builder/Dockerfile deleted file mode 100644 index db7edd3..0000000 --- a/docker/builder/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM golang:1.13 -LABEL MAINTAINER yunlong -ENV GO111MODULE on - -# Install go debugger -RUN go get -u github.com/go-delve/delve/cmd/dlv - -# Install project dependences -WORKDIR /go/src/github.com/alibaba/kt-connect -COPY go.mod . -COPY go.sum . -RUN go mod download diff --git a/docker/dashboard/Dockerfile b/docker/dashboard/Dockerfile index 469f6c8..abbb559 100644 --- a/docker/dashboard/Dockerfile +++ b/docker/dashboard/Dockerfile @@ -9,6 +9,6 @@ RUN cnpm run build FROM nginx:1.15 ENV APP_ENV PROD COPY --from=build-deps /usr/src/app/build /usr/share/nginx/html -ADD config/nginx/default.conf /etc/nginx/conf.d/default.conf +ADD docker/dashboard/nginx/default.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/config/nginx/default.conf b/docker/dashboard/nginx/default.conf similarity index 100% rename from config/nginx/default.conf rename to docker/dashboard/nginx/default.conf diff --git a/docker/shadow/Dockerfile_dlv b/docker/shadow/Dockerfile_dlv index f2bf7ff..1b1d053 100644 --- a/docker/shadow/Dockerfile_dlv +++ b/docker/shadow/Dockerfile_dlv @@ -1,4 +1,9 @@ -FROM registry.cn-hangzhou.aliyuncs.com/rdc-incubator/builder +FROM golang:1.13 +LABEL MAINTAINER yunlong +ENV GO111MODULE on + +# Install go debugger +RUN go get -u github.com/go-delve/delve/cmd/dlv FROM registry.cn-hangzhou.aliyuncs.com/rdc-incubator/kt-connect-shadow:latest COPY --from=0 /go/bin/dlv /usr/sbin/dlv From cd757a932f27f43e2db1319f2149966d3c84dc58 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 13:02:50 +0800 Subject: [PATCH 07/12] ci: clean up travis script --- .travis.yml | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 88b442c..374c2a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,6 @@ services: env: global: - - REGISTRY=registry.cn-hangzhou.aliyuncs.com - - NAMESPACE=registry.cn-hangzhou.aliyuncs.com/rdc-incubator - - BUILDER_REPO=builder - - SHADOW_BASE_REPO=shadow-base - - SHADOW_REPO=kt-connect-shadow - - DASHBOARD_REPO=kt-connect-dashboard - SERVER_REPO=kt-connect-server before_script: @@ -21,31 +15,9 @@ before_script: # - openssl aes-256-cbc -K $encrypted_b5106b5f3da7_key -iv $encrypted_b5106b5f3da7_iv -in test/integration/testdata/config.yaml.enc -out test/integration/testdata/config.yaml -d script: -# Unit Test -- make -f Makefile -B unit-test -# ktctl -- make -f Makefile build-connect -# Outhers -- docker pull ${NAMESPACE}/${SHADOW_BASE_REPO} || true -- docker pull ${NAMESPACE}/${SHADOW_REPO} || true -- docker pull golang:1.11 || true -- docker pull node:9.11.1 || true -- docker pull alpine || true -- docker build -t ${NAMESPACE}/${BUILDER_REPO} -f docker/builder/Dockerfile . -- docker build -t ${NAMESPACE}/${SHADOW_BASE_REPO} -f docker/shadow/Dockerfile_base . -- docker build -t ${NAMESPACE}/${SHADOW_REPO}:${TAG} --cache-from ${NAMESPACE}/${SHADOW_REPO} -f docker/shadow/Dockerfile . -- docker build -t ${NAMESPACE}/${SERVER_REPO}:${TAG} -f docker/apiserver/Dockerfile . -- docker build -t ${NAMESPACE}/${DASHBOARD_REPO}:${TAG} -f docker/dashboard/Dockerfile . -- docker tag ${NAMESPACE}/${SHADOW_REPO}:${TAG} ${NAMESPACE}/${SHADOW_REPO} - -after_success: - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin ${REGISTRY} -- docker push ${NAMESPACE}/${SHADOW_REPO}:${TAG} -- docker push ${NAMESPACE}/${SHADOW_REPO} -- docker push ${NAMESPACE}/${DASHBOARD_REPO}:${TAG} -- docker push ${NAMESPACE}/${SERVER_REPO}:${TAG} -- docker push ${NAMESPACE}/${BUILDER_REPO} -- docker push ${NAMESPACE}/${SHADOW_BASE_REPO} +- make unit-test +- make build deploy: provider: releases From 7ea21682cc802bde29e8fb6801b2f6fbae8279b3 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 13:04:22 +0800 Subject: [PATCH 08/12] ci: add go mod cache --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 374c2a5..05ace23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ language: go go: - 1.13.x +cache: + directories: + - $GOPATH/pkg/mod + services: - docker From a46629bf0a35cd1c3dc412e211ee6129db86c8a5 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 13:07:09 +0800 Subject: [PATCH 09/12] ci: fixed docker login error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 05ace23..77aceb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ services: env: global: - - SERVER_REPO=kt-connect-server + - REGISTRY=registry.cn-hangzhou.aliyuncs.com before_script: - export TAG=$(echo $TRAVIS_BRANCH | sed "s/\//-/") From 98c12f08e4613c5824b991f1ed8112522399bac6 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 13:31:56 +0800 Subject: [PATCH 10/12] add cc test report to travis --- .gitignore | 3 ++- .travis.yml | 7 +++++++ Makefile | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2a5ed0a..8a1f524 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ note/ .jvmrc .DS_Store -vendor/ \ No newline at end of file +vendor/ +c.out \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 77aceb3..71292a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,10 @@ env: before_script: - export TAG=$(echo $TRAVIS_BRANCH | sed "s/\//-/") + - echo "TAG=${TAG}" + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build # - openssl aes-256-cbc -K $encrypted_b5106b5f3da7_key -iv $encrypted_b5106b5f3da7_iv -in test/integration/testdata/config.yaml.enc -out test/integration/testdata/config.yaml -d script: @@ -23,6 +27,9 @@ script: - make unit-test - make build +after_script: +- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT + deploy: provider: releases api_key: diff --git a/Makefile b/Makefile index 9e75f03..f0b088c 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,8 @@ generate-mock: # run unit test unit-test: mkdir -p artifacts/report/coverage - go test -v -json -cover -coverprofile artifacts/report/coverage/cover.out ./... - go tool cover -html=artifacts/report/coverage/cover.out -o artifacts/report/coverage/index.html + go test -v -json -cover -coverprofile c.out ./... + go tool cover -html=c.out -o artifacts/report/coverage/index.html # build kt project build: build-connect build-shadow build-server build-dashboard From 20aa93884c9c68dd68ab7fbed9a3102eded0f0eb Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 13:58:15 +0800 Subject: [PATCH 11/12] add test coverage badges --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fe951f..1a5ce9c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ KT Connect =========== -[![Build Status](https://travis-ci.org/alibaba/kt-connect.svg?branch=master)](https://travis-ci.org/alibaba/kt-connect) ![License](https://img.shields.io/github/license/alibaba/kt-connect.svg) +[![Build Status](https://travis-ci.org/alibaba/kt-connect.svg?branch=master)](https://travis-ci.org/alibaba/kt-connect) +[![Test Coverage](https://api.codeclimate.com/v1/badges/eb13b3946784bd7c67cc/test_coverage)](https://codeclimate.com/github/alibaba/kt-connect/test_coverage) +![License](https://img.shields.io/github/license/alibaba/kt-connect.svg) Management and Integration with your Kubernetes dev environment more efficient. From 8e6e4f9817c738db253b5d6607391e360ec3b5b8 Mon Sep 17 00:00:00 2001 From: yunlzheng Date: Thu, 12 Mar 2020 13:58:53 +0800 Subject: [PATCH 12/12] ci: add test coverage badges --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a5ce9c..3e9738d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ KT Connect =========== [![Build Status](https://travis-ci.org/alibaba/kt-connect.svg?branch=master)](https://travis-ci.org/alibaba/kt-connect) -[![Test Coverage](https://api.codeclimate.com/v1/badges/eb13b3946784bd7c67cc/test_coverage)](https://codeclimate.com/github/alibaba/kt-connect/test_coverage) +[![Test Coverage](https://api.codeclimate.com/v1/badges/eb13b3946784bd7c67cc/test_coverage)](https://codeclimate.com/github/alibaba/kt-connect/test_coverage) +[![Maintainability](https://api.codeclimate.com/v1/badges/eb13b3946784bd7c67cc/maintainability)](https://codeclimate.com/github/alibaba/kt-connect/maintainability) ![License](https://img.shields.io/github/license/alibaba/kt-connect.svg) Management and Integration with your Kubernetes dev environment more efficient.