easydeploy

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: MIT Imports: 4 Imported by: 0

README

easydeploy

Deployment

To my opinion, a simple deployment just the following four steps:

  • prepare the artifacts to be deployed
  • put the prepared artifacts to your deploy servers
  • restart deploy servers
  • do some clean

Now with easydeploy you can:

import (
	"github.com/gaols/easydeploy"
	"github.com/gaols/easyssh"
)

deployer := &easydeploy.Deployer{
    SrvConf: []*easydeploy.ServerConfig{
        easydeploy.NewSrvConf("gaols@192.168.1.100:22/123456"),
        easydeploy.NewSrvConf("gaols@192.168.1.103:22/123456"),
    },
}

// step 1
deployer.Local("/path/to/your/prepare-artifacts.sh")
// step 2
deployer.Upload("/path/to/your/artifacts", "/path/to/remote")
// step 3
deployer.Remote("/path/to/your/restart-server-on-remote.sh")
// step 4
deployer.OnceDoneDeploy(func(isDeployOk bool) error {
    _, err := easyssh.Local("ls -l /home/tmp")
    return err
})
deployer.Verbose()
deployer.Start()

Notes

  1. Upload(localPath, remotePath string) upload a local file or local dir to its corresponding remote path, the remotePath should contain the file name if the localPath is a regular file, however, if the localPath to copy is dir, the remotePath must be the dir into which the localPath will be copied.
  2. The local commands and remote commands you registered by calling Local/Remote/Upload to deployer will not run until Start() method being called.
  3. If you'd like to run the local or remote shell command manually, please refer to easyssh.

So easy to deploy

A simple deploy sample

Documentation

Overview

Package easydeploy makes your deployment easy

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	Run(deployCtx Deploy, srvConf *ServerConfig) error
}

type Deploy

type Deploy interface {
	RegisterDeployServer(srvConf *ServerConfig)
	OnceBeforeDeploy(fn func() error)
	OnceDoneDeploy(fn func(bool) error)
	Local(cmd string, args ...interface{})
	Remote(cmd string, args ...interface{})
	Upload(localPath, remotePath string)
	MaxConcurrency(num int)
	Start() []*DeployReport
	Verbose()
	// contains filtered or unexported methods
}

type DeployReport

type DeployReport struct {
	SrvConf *ServerConfig

	Start    time.Time
	Consumed int64
	CmdRuns  int
	Cmds     int
	// contains filtered or unexported fields
}

func (*DeployReport) String

func (rp *DeployReport) String() string

type Deployer

type Deployer struct {
	SrvConf []*ServerConfig
	// contains filtered or unexported fields
}

func (*Deployer) Local

func (sc *Deployer) Local(cmd string, args ...interface{})

Local register a command to be run on localhost

func (*Deployer) MaxConcurrency

func (sc *Deployer) MaxConcurrency(num int)

MaxConcurrency controls how many deployments will run simultaneously if you deploy to multiple servers. 0 means all deployments will start asynchronously.

func (*Deployer) OnceBeforeDeploy

func (sc *Deployer) OnceBeforeDeploy(fn func() error)

OnceBeforeDeploy called only once before deployment

func (*Deployer) OnceDoneDeploy

func (sc *Deployer) OnceDoneDeploy(fn func(bool) error)

OnceDoneDeploy called only once when deployment is done even if deployment failed

func (*Deployer) RegisterDeployServer

func (sc *Deployer) RegisterDeployServer(srvConf *ServerConfig)

Local register a command to be run on localhost

func (*Deployer) Remote

func (sc *Deployer) Remote(cmd string, args ...interface{})

Remote register a command to be run on remote host

func (*Deployer) Start

func (sc *Deployer) Start() []*DeployReport

Start will start the deploy process

func (*Deployer) Upload

func (sc *Deployer) Upload(localPath, remotePath string)

Remote register a upload command

func (*Deployer) Verbose

func (sc *Deployer) Verbose()

Verbose should be called before deployment start if you want to see the each command output.

type LocalCommand

type LocalCommand struct {
	CmdStr string
}

func (*LocalCommand) Run

func (localCmd *LocalCommand) Run(deployCtx Deploy, srvConf *ServerConfig) error

type RemoteCommand

type RemoteCommand struct {
	CmdStr string
}

func (*RemoteCommand) Run

func (remoteCmd *RemoteCommand) Run(deployCtx Deploy, srvConf *ServerConfig) error

type ServerConfig

type ServerConfig struct {
	User     string
	Server   string
	Key      string
	Port     string
	Password string
}

readonly

func NewSrvConf

func NewSrvConf(format string) *ServerConfig

NewSrvConf parse server config from string with format: user@host:port/password

func (*ServerConfig) MakeSSHConfig

func (sc *ServerConfig) MakeSSHConfig() *easyssh.SSHConfig

func (*ServerConfig) Simple

func (sc *ServerConfig) Simple() string

func (*ServerConfig) String

func (sc *ServerConfig) String() string

type UploadCommand

type UploadCommand struct {
	LocalPath  string
	RemotePath string
}

func (*UploadCommand) Run

func (uploadCmd *UploadCommand) Run(deployCtx Deploy, srvConf *ServerConfig) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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