Documentation ¶
Index ¶
- Variables
- func Key(parts ...string) (k string)
- type Changes
- type Dest
- type Release
- func (d *Release) Checkout(envs ...[]string) error
- func (d *Release) Diff() map[string]*Changes
- func (d *Release) FirstEnvValues() []string
- func (d *Release) Log() map[string][2]interface{}
- func (d *Release) Push(only ...string) error
- func (d *Release) Replicate() int
- func (d *Release) SecondEnvValues() []string
- func (d *Release) Status() *Task
- type Source
- type Task
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalid = errors.New("invalid data") ErrMissing = errors.New("nothing to deploy") )
Error message.
var ServerLess = &devNull{}
ServerLess is a /dev/null server instance to force the pushing of all data.
Functions ¶
Types ¶
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 ¶
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 ¶
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 ¶
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 ¶
FirstEnvValues returns the values of the first environment used to checkout the release.
func (*Release) Log ¶
Log shows the push's logs. For each key, it returns the value before and after the push.
func (*Release) Push ¶
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) SecondEnvValues ¶
SecondEnvValues returns the values of the second environment used to checkout the release.
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.