deploy

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid = errors.New("invalid data")
	ErrMissing = errors.New("nothing to deploy")
)

Error message.

View Source
var ServerLess = &devNull{}

ServerLess is a /dev/null server instance to force the pushing of all data.

Functions

func Key

func Key(parts ...string) (k string)

Key returns the name of the variable used as key in the cache.

Types

type Changes

type Changes struct {
	Var string
	Log map[string][2]interface{}
}

Changes returns all changes computed by variable.

type Dest

type Dest interface {
	Bulk(data map[string]interface{}) error
	Lookup(key string) (interface{}, bool)
}

Dest must be implemented by any client to deploy data.

type Release

type Release struct {
	// contains filtered or unexported fields
}

Release represents a new deployment.

func New

func New(src Source, server Dest, more ...Dest) *Release

New returns a new Release.

Example
package main

import (
	"fmt"

	"strconv"

	"github.com/rvflash/eve/client"
	"github.com/rvflash/eve/deploy"

	cache "github.com/rvflash/eve/rpc"
)

// rpc is the test's RPC client.
type rpc int

// Call implements the client.Caller interface
func (c rpc) Call(service string, args, reply interface{}) error {
	switch service {
	case "Cache.Bulk":
		switch int(c) {
		case 0:
			*reply.(*bool) = false
		default:
			*reply.(*bool) = true
		}
		return nil
	case "Cache.Get":
		switch args {
		case "0_BOOL":
			reply.(*cache.Item).Value = false
			return nil
		case "0_INT":
			reply.(*cache.Item).Value = 12
			return nil
		case "0_STR":
			reply.(*cache.Item).Value = "rv"
			return nil
		}
		return cache.ErrNotFound
	}
	return nil
}

// Close implements the client.Caller interface
func (c rpc) Close() error {
	return nil
}

var rpcClient = client.NewRPC(rpc(1))

// src is the test's source.
type src int

// Key implements the deploy.Source interface.
func (s src) Key() []byte {
	return []byte(strconv.Itoa(int(s)))
}

// EnvsValues implements the deploy.Source interface.
func (s src) EnvsValues() (firstEnvValues, secondEnvValues []string) {
	switch s {
	case twoEnv:
		return []string{"dev"}, []string{"fr", "en"}
	case oneEnv:
		return []string{"dev"}, []string{""}
	case errEnv:
		return nil, nil

	}
	return []string{""}, []string{""}
}

// ToDeploy implements the deploy.Source interface.
func (s src) ToDeploy(firstEnvValues, secondEnvValues []string) map[string]interface{} {
	switch s {
	case twoEnv:
		return map[string]interface{}{"2_DEV_FR_BOOL": true, "2_DEV_FR_FLOAT": 3.14}
	case oneEnv:
		return map[string]interface{}{"1_DEV_BOOL": true, "1_DEV_FLOAT": 3.14}
	case noEnv:
		if len(firstEnvValues) == 0 || len(secondEnvValues) == 0 {
			return nil
		}
		return map[string]interface{}{"0_BOOL": true, "0_FLOAT": 3.14, "0_STR": nil, "0_INT": 12}
	}
	return nil
}

// Sources without, or with one or two environments.
const (
	noEnv src = iota
	oneEnv
	twoEnv
	errEnv
)

func main() {
	// Defines the project to deploy and which values of environments to push.
	r := deploy.New(noEnv, rpcClient)
	if err := r.Checkout(); err != nil {
		fmt.Println(err.Error())
		return
	}
	// Gets the list of variables to change.
	for key, value := range r.Diff() {
		fmt.Printf("%v: %s\n", key, value)
	}
	// Gets counters to show differences with cached data.
	task := r.Status()
	fmt.Printf(
		"Add: %d (%d%%), Delete: %d (%d%%), Update: %d (%d%%), No change: %d (%d%%)\n",
		task.Add, task.PctOfAdd(),
		task.Del, task.PctOfDel(),
		task.Upd, task.PctOfDel(),
		task.NoOp, task.PctOfNoOp(),
	)
	// Pushes these changes in production.
	if err := r.Push(); err != nil {
		fmt.Println(err.Error())
	}
}
Output:

func (*Release) Checkout

func (d *Release) Checkout(envs ...[]string) error

Checkout allows to define until 2 environments. The adding's order is important, the first must be the first environment defined in the EVE's project. It returns an error if the number of environment is unexpected.

func (*Release) Diff

func (d *Release) Diff() map[string]*Changes

Diff fetches from and merge data to return only the differences according to their values in one of the cache instance. For a given key, if it not exists in cache, a nil value is returned. If it exists with an other value, its value is returned. If it exists with the same value, nothing is returned.

func (*Release) FirstEnvValues

func (d *Release) FirstEnvValues() []string

FirstEnvValues returns the values of the first environment used to checkout the release.

func (*Release) Log

func (d *Release) Log() map[string][2]interface{}

Log shows the push's logs. For each key, it returns the value before and after the push.

func (*Release) Push

func (d *Release) Push(only ...string) error

Push uploads via RPC to the cache servers all the required data in one bulk. It can take as parameter the exclusive list of variable's names to push. This list do not have the project ID or envs names as components. It returns on error if the process fails.

func (*Release) Replicate

func (d *Release) Replicate() int

Replicate returns the real number of servers used to save the data.

func (*Release) SecondEnvValues

func (d *Release) SecondEnvValues() []string

SecondEnvValues returns the values of the second environment used to checkout the release.

func (*Release) Status

func (d *Release) Status() *Task

Status gives various counters about the tasks to do to deploy it.

type Source

type Source interface {
	Key() []byte
	EnvsValues() (firstEnvValues, secondEnvValues []string)
	ToDeploy(firstEnvValues, secondEnvValues []string) map[string]interface{}
}

Source must be implemented by any source want to be deployed. Key returns the identifier of the project. EnvsValues returns the values of each environments behind the project. ToDeploy gives the list of variable to deploy, with their deploy's name as key.

type Task

type Task struct {
	Add, Del, Upd, NoOp uint64
}

Task maintains counter of change.

func (*Task) All

func (t *Task) All() uint64

All returns the sum of tasks to perform.

func (*Task) PctOfAdd

func (t *Task) PctOfAdd() uint64

PctOfAdd returns the percentage of addition.

func (*Task) PctOfDel

func (t *Task) PctOfDel() uint64

PctOfDel returns the percentage of deletion.

func (*Task) PctOfNoOp

func (t *Task) PctOfNoOp() uint64

PctOfNoOp returns the percentage of no operation.

func (*Task) PctOfUpd

func (t *Task) PctOfUpd() uint64

PctOfUpd returns the percentage of update.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL