From b1f64bdb65ddcf1a225077e8bfe96069a49de494 Mon Sep 17 00:00:00 2001 From: timfeirg Date: Mon, 31 Oct 2016 18:08:30 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=9C=9F=E6=98=AF=E5=8F=97=E5=A4=9F?= =?UTF-8?q?=E4=BA=86=E8=BF=99=E4=B8=AA=20libgit2=20=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 37 ++++--------------------------------- devtools/libgit2.rb.patch | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 33 deletions(-) create mode 100644 devtools/libgit2.rb.patch diff --git a/README.md b/README.md index 9a79bc48c..f9c9a619e 100644 --- a/README.md +++ b/README.md @@ -5,39 +5,10 @@ Core We use v0.23.4 because v0.24 sucks ```shell -$ wget https://github.com/libgit2/libgit2/archive/v0.23.4.zip -$ unzip v0.23.4.zip -``` -Install dependencies: `libssh2`, `http-parser`, `cmake`, `libcurl`. - -```shell -On Mac OSX: -$ brew install libssh2 http-parser cmake libcurl - -On CentOS: -$ yum install libssh2-devel http-parser cmake libcurl-devel -``` -Then install libgit2. - -```shell -$ cmake . -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DUSE_SSH=YES -$ make && make install -``` -Note on Mac OSX may need to set CFLAGS="-std=c99". -Now libgit2 is installed under `/usr/local/lib` as default. We still need to set pkg-config and link dynamic libraries. - -```shell -On Mac OSX: -$ cd /usr/local/lib/pkgconfig -$ ln -s /path/to/libgit2/pkgconfig/libgit2.pc libgit2.pc -$ cd /usr/local/lib -$ ln -s /path/to/libgit2/libgit2.23.dylib libgit2.23.dylib - -On CentOS: -$ cd /usr/lib64/pkgconfig/ -$ ln -s /usr/local/lib/pkgconfig/libgit2.pc libgit2.pc -$ cd /usr/lib64 -$ ln -s /usr/local/lib/libgit2.so.23 libgit2.so.23 +cp devtools/libgit2.rb.patch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula +cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula +git apply libgit2.rb.patch && git add libgit2.rb && git commit -m "patch libgit2 version for eru-core" && rm libgit2.rb.patch +cd - ``` ## setup dev environment diff --git a/devtools/libgit2.rb.patch b/devtools/libgit2.rb.patch new file mode 100644 index 000000000..b0bd1a261 --- /dev/null +++ b/devtools/libgit2.rb.patch @@ -0,0 +1,15 @@ +diff --git a/Formula/libgit2.rb b/Formula/libgit2.rb +index b91f4ff..45205f1 100644 +--- a/Formula/libgit2.rb ++++ b/Formula/libgit2.rb +@@ -1,8 +1,8 @@ + class Libgit2 < Formula + desc "C library of Git core methods that is re-entrant and linkable" + homepage "https://libgit2.github.com/" +- url "https://github.com/libgit2/libgit2/archive/v0.24.2.tar.gz" +- sha256 "00f0a7403143fba69601accc80cacf49becc568b890ba232f300c1b2a37475e6" ++ url "https://github.com/libgit2/libgit2/archive/v0.23.4.tar.gz" ++ sha256 "c7f5e2d7381dbc4d7e878013d14f9993ae8a41bd23f032718e39ffba57894029" + head "https://github.com/libgit2/libgit2.git" + + bottle do From 40c708a21dc83f7fa9c0d7c2a901bd71fb66f0f1 Mon Sep 17 00:00:00 2001 From: timfeirg Date: Mon, 31 Oct 2016 18:56:52 +0800 Subject: [PATCH 2/7] citadel knows nothing about core error --- cluster/calcium/create_container.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index 5c7d3b218..981e96b96 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -30,16 +30,35 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions) } } +// when shits go wrong before doCreateContainerWithCPUPeriod, don't just return +// the channel and return an error, because citadel don't know what's going on +func (c *calcium) createErrorMessage(err error) *types.CreateContainerMessage { + log.Errorf("Got error %s", err.Error()) + m := &types.CreateContainerMessage{ + Podname: "", + Nodename: "", + ContainerID: "", + ContainerName: "", + Error: err.Error(), + Success: false, + CPU: nil, + Memory: 0, + } + return m +} + func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) { ch := make(chan *types.CreateContainerMessage) if opts.Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准 - return ch, fmt.Errorf("Minimum memory limit allowed is 4MB") + err := fmt.Errorf("Minimum memory limit allowed is 4MB") + ch <- c.createErrorMessage(err) + return ch, err } cpuandmem, _, err := c.getCPUAndMem(opts.Podname, opts.Nodename, 1.0) if err != nil { - log.Errorf("Got error %v after getCPUAndMem", err) + ch <- c.createErrorMessage(err) return ch, err } nodesInfo := utils.GetNodesInfo(cpuandmem) From fc5f16dde3e6a413a246d55f762c85e406785e9b Mon Sep 17 00:00:00 2001 From: timfeirg Date: Tue, 1 Nov 2016 22:56:48 +0800 Subject: [PATCH 3/7] update readme --- Makefile | 27 ++++++++++++++------------- README.md | 22 ++++++++++++++++------ devtools/upgrade-eru-core.sh | 22 +++++++++++++++------- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 28c3cde5c..3bfef6ba4 100644 --- a/Makefile +++ b/Makefile @@ -15,19 +15,20 @@ python: cd ./rpc/gen/; python -m grpc.tools.protoc -I. --python_out=. --grpc_python_out=. core.proto; mv core_pb2.py ../../devtools/ deps: - go get github.com/docker/docker - go get github.com/docker/engine-api - go get github.com/docker/go-units - go get github.com/docker/go-connections - go get github.com/coreos/etcd - go get github.com/Sirupsen/logrus - go get github.com/stretchr/testify - go get github.com/golang/protobuf/proto - go get github.com/codegangsta/cli - go get gopkg.in/yaml.v2 - go get gopkg.in/libgit2/git2go.v23 - go get golang.org/x/net/context - go get google.golang.org/grpc + go get github.com/docker/engine-api || echo "oops" + go get github.com/docker/go-units || echo "oops" + go get github.com/docker/go-connections || echo "oops" + go get github.com/docker/distribution || echo "oops" + go get github.com/Sirupsen/logrus || echo "oops" + go get github.com/stretchr/testify || echo "oops" + go get github.com/golang/protobuf/{proto,protoc-gen-go} || echo "oops" + go get github.com/codegangsta/cli || echo "oops" + go get gopkg.in/yaml.v2 || echo "oops" + go get gopkg.in/libgit2/git2go.v23 || echo "oops" + go get golang.org/x/net/context || echo "oops" + go get google.golang.org/grpc || echo "oops" + go get github.com/coreos/etcd || echo "oops" + go get github.com/docker/docker || echo "oops" build: go build -ldflags "$(GO_LDFLAGS)" -a -tags netgo -installsuffix netgo -o eru-core diff --git a/README.md b/README.md index f9c9a619e..366977806 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,22 @@ cd - ## setup dev environment ```shell -$ git config --global url."git@gitlab.ricebook.net:".insteadOf "https://gitlab.ricebook.net/" -$ go get gitlab.ricebook.net/platform/core.git -$ mv $GOPATH/src/gitlab.ricebook.net/platform/core.git $GOPATH/src/gitlab.ricebook.net/platform/core -$ cd $GOPATH/src/gitlab.ricebook.net/platform/core && go install -$ ln -s $GOPATH/src/gitlab.ricebook.net/platform/core $MY_WORK_SPACE/eru-core2 -$ make deps +git config --global url."git@gitlab.ricebook.net:".insteadOf "https://gitlab.ricebook.net/" +go get gitlab.ricebook.net/platform/core.git +mv $GOPATH/src/gitlab.ricebook.net/platform/core.git $GOPATH/src/gitlab.ricebook.net/platform/core +cd $GOPATH/src/gitlab.ricebook.net/platform/core +make deps +make build +``` + +## Upgrade core on test/production server + +```shell +make build +# test server +devtools/upgrade-eru-core.sh test eru-core +# prod server +devtools/upgrade-eru-core.sh ``` ### GRPC diff --git a/devtools/upgrade-eru-core.sh b/devtools/upgrade-eru-core.sh index e84102229..538ff7028 100755 --- a/devtools/upgrade-eru-core.sh +++ b/devtools/upgrade-eru-core.sh @@ -1,8 +1,16 @@ -#!/bin/sh +#!/bin/bash -ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo yum --enablerepo=ricebook clean metadata' -ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo yum reinstall -y eru-core' -ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo systemctl daemon-reload' -ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo systemctl restart eru-core.service' -ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo git --work-tree=/opt/citadel --git-dir=/opt/citadel/.git pull' -ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo systemctl restart citadel' +if [ $1 == "test" ]; then + rsync -a /Users/timfeirg/gocode/src/gitlab.ricebook.net/platform/core sa-ricebook:~ + ssh sa-ricebook -t 'sudo rm -rf /root/.go/src/gitlab.ricebook.net/platform/core' + ssh sa-ricebook -t 'sudo mv ~/core /root/.go/src/gitlab.ricebook.net/platform/core' + # ssh zzz1 -t 'sudo mv eru-core /usr/bin/eru-core' + # ssh zzz1 -t 'sudo systemctl restart eru-core.service' +else + ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo yum --enablerepo=ricebook clean metadata' + ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo yum reinstall -y eru-core' + ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo systemctl daemon-reload' + ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo systemctl restart eru-core.service' + ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo git --work-tree=/opt/citadel --git-dir=/opt/citadel/.git pull' + ssh liuyifu@c2-eru-1.ricebook.link -t 'sudo systemctl restart citadel' +fi From fe8356e343cdb8333c4c5ddada4a07aeeb4de22f Mon Sep 17 00:00:00 2001 From: timfeirg Date: Wed, 2 Nov 2016 12:29:28 +0800 Subject: [PATCH 4/7] display core error message in citadel --- VERSION | 2 +- cluster/calcium/create_container.go | 10 ++++++---- rpc/rpc.go | 7 +++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index c00621855..879be8a98 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.6 +0.7.7 diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index 981e96b96..baad8e811 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -32,7 +32,7 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions) // when shits go wrong before doCreateContainerWithCPUPeriod, don't just return // the channel and return an error, because citadel don't know what's going on -func (c *calcium) createErrorMessage(err error) *types.CreateContainerMessage { +func (c *calcium) sendErrorMessage(err error, ch chan<- *types.CreateContainerMessage) { log.Errorf("Got error %s", err.Error()) m := &types.CreateContainerMessage{ Podname: "", @@ -44,7 +44,8 @@ func (c *calcium) createErrorMessage(err error) *types.CreateContainerMessage { CPU: nil, Memory: 0, } - return m + ch <- m + close(ch) } func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) { @@ -52,13 +53,13 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De if opts.Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准 err := fmt.Errorf("Minimum memory limit allowed is 4MB") - ch <- c.createErrorMessage(err) + go c.sendErrorMessage(err, ch) return ch, err } cpuandmem, _, err := c.getCPUAndMem(opts.Podname, opts.Nodename, 1.0) if err != nil { - ch <- c.createErrorMessage(err) + go c.sendErrorMessage(err, ch) return ch, err } nodesInfo := utils.GetNodesInfo(cpuandmem) @@ -67,6 +68,7 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De plan, err := utils.AllocContainerPlan(nodesInfo, cpuQuota, opts.Memory, opts.Count) // 还是以 Bytes 作单位, 不转换了 if err != nil { + go c.sendErrorMessage(err, ch) return ch, err } diff --git a/rpc/rpc.go b/rpc/rpc.go index fc78e9cc5..e40f09241 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -182,10 +182,9 @@ func (v *virbranium) CreateContainer(opts *pb.DeployOptions, stream pb.CoreRPC_C return err } - ch, err := v.cluster.CreateContainer(specs, toCoreDeployOptions(opts)) - if err != nil { - return err - } + // ignore err because the error message will be sent to ch, and citadel + // will receive them + ch, _ := v.cluster.CreateContainer(specs, toCoreDeployOptions(opts)) for m := range ch { if err := stream.Send(toRPCCreateContainerMessage(m)); err != nil { From 385a3703569640e455ffb9623e0b49337074627d Mon Sep 17 00:00:00 2001 From: timfeirg Date: Tue, 8 Nov 2016 15:23:35 +0800 Subject: [PATCH 5/7] Revert "display core error message in citadel" This reverts commit fe8356e343cdb8333c4c5ddada4a07aeeb4de22f. --- VERSION | 2 +- cluster/calcium/create_container.go | 10 ++++------ rpc/rpc.go | 7 ++++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/VERSION b/VERSION index 879be8a98..c00621855 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.7 +0.7.6 diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index baad8e811..981e96b96 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -32,7 +32,7 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions) // when shits go wrong before doCreateContainerWithCPUPeriod, don't just return // the channel and return an error, because citadel don't know what's going on -func (c *calcium) sendErrorMessage(err error, ch chan<- *types.CreateContainerMessage) { +func (c *calcium) createErrorMessage(err error) *types.CreateContainerMessage { log.Errorf("Got error %s", err.Error()) m := &types.CreateContainerMessage{ Podname: "", @@ -44,8 +44,7 @@ func (c *calcium) sendErrorMessage(err error, ch chan<- *types.CreateContainerMe CPU: nil, Memory: 0, } - ch <- m - close(ch) + return m } func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) { @@ -53,13 +52,13 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De if opts.Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准 err := fmt.Errorf("Minimum memory limit allowed is 4MB") - go c.sendErrorMessage(err, ch) + ch <- c.createErrorMessage(err) return ch, err } cpuandmem, _, err := c.getCPUAndMem(opts.Podname, opts.Nodename, 1.0) if err != nil { - go c.sendErrorMessage(err, ch) + ch <- c.createErrorMessage(err) return ch, err } nodesInfo := utils.GetNodesInfo(cpuandmem) @@ -68,7 +67,6 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De plan, err := utils.AllocContainerPlan(nodesInfo, cpuQuota, opts.Memory, opts.Count) // 还是以 Bytes 作单位, 不转换了 if err != nil { - go c.sendErrorMessage(err, ch) return ch, err } diff --git a/rpc/rpc.go b/rpc/rpc.go index e40f09241..fc78e9cc5 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -182,9 +182,10 @@ func (v *virbranium) CreateContainer(opts *pb.DeployOptions, stream pb.CoreRPC_C return err } - // ignore err because the error message will be sent to ch, and citadel - // will receive them - ch, _ := v.cluster.CreateContainer(specs, toCoreDeployOptions(opts)) + ch, err := v.cluster.CreateContainer(specs, toCoreDeployOptions(opts)) + if err != nil { + return err + } for m := range ch { if err := stream.Send(toRPCCreateContainerMessage(m)); err != nil { From f3e75ea22384b0d7495abd3831d54b74eb7f3eb5 Mon Sep 17 00:00:00 2001 From: timfeirg Date: Tue, 8 Nov 2016 15:24:03 +0800 Subject: [PATCH 6/7] Revert "citadel knows nothing about core error" This reverts commit 40c708a21dc83f7fa9c0d7c2a901bd71fb66f0f1. --- cluster/calcium/create_container.go | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index 981e96b96..5c7d3b218 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -30,35 +30,16 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions) } } -// when shits go wrong before doCreateContainerWithCPUPeriod, don't just return -// the channel and return an error, because citadel don't know what's going on -func (c *calcium) createErrorMessage(err error) *types.CreateContainerMessage { - log.Errorf("Got error %s", err.Error()) - m := &types.CreateContainerMessage{ - Podname: "", - Nodename: "", - ContainerID: "", - ContainerName: "", - Error: err.Error(), - Success: false, - CPU: nil, - Memory: 0, - } - return m -} - func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) { ch := make(chan *types.CreateContainerMessage) if opts.Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准 - err := fmt.Errorf("Minimum memory limit allowed is 4MB") - ch <- c.createErrorMessage(err) - return ch, err + return ch, fmt.Errorf("Minimum memory limit allowed is 4MB") } cpuandmem, _, err := c.getCPUAndMem(opts.Podname, opts.Nodename, 1.0) if err != nil { - ch <- c.createErrorMessage(err) + log.Errorf("Got error %v after getCPUAndMem", err) return ch, err } nodesInfo := utils.GetNodesInfo(cpuandmem) From 358d86380f0db4f71987d9955cce858fb583fa84 Mon Sep 17 00:00:00 2001 From: timfeirg Date: Tue, 8 Nov 2016 16:20:09 +0800 Subject: [PATCH 7/7] only build for master, use sa-ricebook for custom builds --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2ed5e673c..5a2fdd661 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,10 +7,14 @@ stages: - rpm test: stage: test + only: + - master script: - "make test" build: stage: build + only: + - master script: - make build artifacts: @@ -19,6 +23,8 @@ build: expire_in: 1 week rpm: stage: rpm + only: + - master script: - "./make-rpm" dependencies: