Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Aug 4, 2017
1 parent ce6cb2e commit b3b030e
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 72 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.35
1.0.0
4 changes: 3 additions & 1 deletion cluster/calcium/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package calcium
import (
"compress/gzip"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -45,7 +46,8 @@ func (c *calcium) Backup(id, srcPath string) (*types.BackupMessage, error) {
return nil, err
}

backupFile := filepath.Join(baseDir, stat.Name+"-"+container.ShortID()+"-"+ident+"-"+now+".tar.gz")
filename := fmt.Sprintf("%s-%s-%s-%s.tar.gz", stat.Name, container.ShortID(), ident, now)
backupFile := filepath.Join(baseDir, filename)
log.Debugf("Creating %s", backupFile)
file, err := os.Create(backupFile)
if err != nil {
Expand Down
19 changes: 8 additions & 11 deletions cluster/calcium/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package calcium

import (
"bytes"
"context"
"encoding/json"
"fmt"
"html/template"
Expand All @@ -16,14 +17,13 @@ import (
"github.com/docker/docker/pkg/archive"
"gitlab.ricebook.net/platform/core/types"
"gitlab.ricebook.net/platform/core/utils"
"golang.org/x/net/context"
"gopkg.in/yaml.v2"
)

// FIXME in alpine, useradd rename as adduser
const (
FROM = "FROM %s"
FROMAS = "FROM %s as %s"
// TODO 在alpine中,useradd不会成功
COMMON = `ENV UID {{.UID}}
ENV Appname {{.Appname}}
ENV Appdir {{.Appdir}}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
return ch, err
}

// ensure .git directory is removed
// ensure source code is safe
// we don't want any history files to be retrieved
if err := c.source.Security(cloneDir); err != nil {
return ch, err
Expand Down Expand Up @@ -181,17 +181,17 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t

go func() {
defer resp.Body.Close()
defer close(ch)
decoder := json.NewDecoder(resp.Body)
for {
message := &types.BuildImageMessage{}
err := decoder.Decode(message)
if err != nil {
if err == io.EOF {
break
} else {
close(ch)
return
}
log.Errorf("Decode build image message failed %v", err)
return
}
ch <- message
}
Expand All @@ -201,7 +201,6 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
rc, err := node.Engine.ImagePush(context.Background(), tag, enginetypes.ImagePushOptions{RegistryAuth: "Khadgar"})
if err != nil {
ch <- makeErrorBuildImageMessage(err)
close(ch)
return
}

Expand All @@ -213,10 +212,9 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
if err != nil {
if err == io.EOF {
break
} else {
close(ch)
return
}
log.Errorf("Decode push image message failed %v", err)
return
}
ch <- message
}
Expand All @@ -230,7 +228,6 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
})

ch <- &types.BuildImageMessage{Status: "finished", Progress: tag}
close(ch)
}()

return ch, nil
Expand Down
9 changes: 3 additions & 6 deletions cluster/calcium/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ type calcium struct {
const (
AFTER_START = "after_start"
BEFORE_STOP = "before_stop"
)

const (
GITLAB = "gitlab"
GITHUB = "github"
GITLAB = "gitlab"
GITHUB = "github"
)

// New returns a new cluster config
Expand Down Expand Up @@ -63,6 +60,6 @@ func New(config types.Config) (*calcium, error) {
return &calcium{store: store, config: config, scheduler: scheduler, network: titanium, source: scm}, nil
}

func (c *calcium) ResetSotre(s store.Store) {
func (c *calcium) SetStore(s store.Store) {
c.store = s
}
16 changes: 2 additions & 14 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package calcium

import (
"context"
"fmt"
"path/filepath"
"strconv"
Expand All @@ -16,7 +17,6 @@ import (
"gitlab.ricebook.net/platform/core/stats"
"gitlab.ricebook.net/platform/core/types"
"gitlab.ricebook.net/platform/core/utils"
"golang.org/x/net/context"
)

const (
Expand Down Expand Up @@ -475,12 +475,11 @@ func (c *calcium) makeContainerOptions(index int, quota map[string]int, specs ty
}

// 只要声明了ports,就免费赠送tcp健康检查,如果需要http健康检查,还要单独声明 healthcheck_url
containerLabels["healthcheck"] = "tcp"
if entry.HealthCheckUrl != "" {
containerLabels["healthcheck"] = "http"
containerLabels["healthcheck_url"] = entry.HealthCheckUrl
containerLabels["healthcheck_expected_code"] = strconv.Itoa(entry.HealthCheckExpectedCode)
} else {
containerLabels["healthcheck"] = "tcp"
}

// 要把after_start和before_stop写进去
Expand Down Expand Up @@ -559,17 +558,6 @@ func (c *calcium) makeContainerOptions(index int, quota map[string]int, specs ty
Privileged: entry.Privileged != "",
Resources: resource,
}
// this is empty because we don't use any plugin for Docker
// networkConfig := &enginenetwork.NetworkingConfig{
// EndpointsConfig: map[string]*enginenetwork.EndpointSettings{},
// }

// for networkID, ipv4 := range opts.Networks {
// networkConfig.EndpointsConfig[networkID] = &enginenetwork.EndpointSettings{
// NetworkID: networkID,
// IPAMConfig: &enginenetwork.EndpointIPAMConfig{IPv4Address: ipv4},
// }
// }
networkConfig := &enginenetwork.NetworkingConfig{}
return config, hostConfig, networkConfig, containerName, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package calcium

import (
"context"
"fmt"
"io"
"io/ioutil"
Expand All @@ -16,7 +17,6 @@ import (
"gitlab.ricebook.net/platform/core/lock"
"gitlab.ricebook.net/platform/core/types"
"gitlab.ricebook.net/platform/core/utils"
"golang.org/x/net/context"
)

func (c *calcium) Lock(name string, timeout int) (lock.DistributedLock, error) {
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/image.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package calcium

import (
"context"
"strings"
"sync"

log "github.com/Sirupsen/logrus"
enginetypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"gitlab.ricebook.net/platform/core/types"
"golang.org/x/net/context"
)

const maxPuller = 10
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/remove_container.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package calcium

import (
"context"
"fmt"
"sync"
"time"

log "github.com/Sirupsen/logrus"
enginetypes "github.com/docker/docker/api/types"
"gitlab.ricebook.net/platform/core/types"
"golang.org/x/net/context"
)

type imageBucket struct {
Expand Down
13 changes: 6 additions & 7 deletions cluster/calcium/remove_image.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package calcium

import (
"context"
"fmt"
"sync"

enginetypes "github.com/docker/docker/api/types"
"gitlab.ricebook.net/platform/core/types"
"golang.org/x/net/context"
)

// remove images
Expand All @@ -23,27 +24,28 @@ func (c *calcium) RemoveImage(podname, nodename string, images []string) (chan *
}

go func() {
defer close(ch)
wg := sync.WaitGroup{}
wg.Add(len(images))
defer wg.Wait()

for _, image := range images {
go func(image string) {
defer wg.Done()

messages := []string{}
success := true

ms, err := node.Engine.ImageRemove(context.Background(), image, opts)
if err != nil {
success = false
messages = append(messages, err.Error())
} else {
for _, m := range ms {
if m.Untagged != "" {
messages = append(messages, "Untagged: "+m.Untagged)
messages = append(messages, fmt.Sprintf("Untagged: %s", m.Untagged))
}
if m.Deleted != "" {
messages = append(messages, "Deleted: "+m.Deleted)
messages = append(messages, fmt.Sprintf("Deleted: %s", m.Deleted))
}
}
}
Expand All @@ -54,9 +56,6 @@ func (c *calcium) RemoveImage(podname, nodename string, images []string) (chan *
}
}(image)
}

wg.Wait()
close(ch)
}()

return ch, nil
Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/run_and_wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package calcium

import (
"bufio"
"context"
"fmt"
"io"
"sync"
Expand All @@ -11,7 +12,6 @@ import (
enginetypes "github.com/docker/docker/api/types"
"gitlab.ricebook.net/platform/core/types"
"gitlab.ricebook.net/platform/core/utils"
"golang.org/x/net/context"
)

func (c *calcium) RunAndWait(specs types.Specs, opts *types.DeployOptions, stdin io.ReadCloser) (chan *types.RunAndWaitMessage, error) {
Expand Down
2 changes: 1 addition & 1 deletion lock/etcdlock/lock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package etcdlock

import (
"context"
"fmt"
"os"
"strings"
Expand All @@ -9,7 +10,6 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/coreos/etcd/client"
"golang.org/x/net/context"
)

const (
Expand Down
16 changes: 7 additions & 9 deletions network/calico/plugin.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package calico

import (
"context"
"fmt"
"net"

log "github.com/Sirupsen/logrus"
enginetypes "github.com/docker/docker/api/types"
enginefilters "github.com/docker/docker/api/types/filters"
enginenetwork "github.com/docker/docker/api/types/network"
"gitlab.ricebook.net/platform/core/types"
"gitlab.ricebook.net/platform/core/utils"
"golang.org/x/net/context"
)

type titanium struct{}
Expand Down Expand Up @@ -79,19 +80,16 @@ func (t *titanium) ListNetworks(ctx context.Context) ([]*types.Network, error) {
return networks, fmt.Errorf("Not actually a `engineapi.Client` for value engine in context")
}

ns, err := engine.NetworkList(context.Background(), enginetypes.NetworkListOptions{})
filters := enginefilters.NewArgs()
filters.Add("driver", t.Name())
ns, err := engine.NetworkList(
context.Background(),
enginetypes.NetworkListOptions{Filters: filters})
if err != nil {
return networks, err
}

driver := t.Name()
for _, n := range ns {
// TODO 之后可以用filter driver=xxx
// 但是现在版本的API还没有给出
if n.Driver != driver {
continue
}

subnets := []string{}
for _, config := range n.IPAM.Config {
subnets = append(subnets, config.Subnet)
Expand Down
3 changes: 2 additions & 1 deletion network/network.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package network

import (
"context"

"gitlab.ricebook.net/platform/core/types"
"golang.org/x/net/context"
)

type Network interface {
Expand Down
4 changes: 2 additions & 2 deletions rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"golang.org/x/net/context"
"context"

log "github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -222,7 +222,7 @@ func initConfig(mStore *mockstore.MockStore) (types.Config, *vibranium) {
if err != nil {
log.Fatal(err)
}
cluster.ResetSotre(mStore)
cluster.SetStore(mStore)
vibranium := New(cluster, config)

return config, vibranium
Expand Down
Loading

0 comments on commit b3b030e

Please sign in to comment.