easydeploy

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 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.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. Local/Remote/Upload method can be called multiple times to fit your deployment needs.
  4. 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
	Sensitive()
}

Command is the command interface

func BuildSimpleCommand added in v1.0.0

func BuildSimpleCommand(fn func(Deploy, *ServerConfig, ...interface{}) error, args ...interface{}) Command

BuildSimpleCommand build the simple command

func Tar added in v1.0.0

func Tar(tgzPath, targetPath string) Command

Tar pack the targetPath and put tarball to tgzPath, targetPath and tgzPath should both the absolute path.

func UnTar added in v1.0.0

func UnTar(tgzPath, targetPath string) Command

UnTar unpack the tarball specified by tgzPath and extract it to the path specified by targetPath

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)
	DownloadF(remotePath, localPath string)
	AddCommand(command Command)
	MaxConcurrency(num int)
	Start() []*DeployReport
	Verbose(verbose bool)
	// contains filtered or unexported methods
}

Deploy is the deploy interface

type DeployReport

type DeployReport struct {
	SrvConf *ServerConfig

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

DeployReport is the report of deploy process

func (*DeployReport) String

func (rp *DeployReport) String() string

type Deployer

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

Deployer is the main entry point

func (*Deployer) AddCommand added in v1.0.0

func (sc *Deployer) AddCommand(command Command)

AddCommand register a custom command

func (*Deployer) DownloadF added in v1.0.4

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

DownloadF register a upload command

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)

RegisterDeployServer register a deploy server

func (*Deployer) Remote

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

Remote register a command to be run on remote host

func (*Deployer) SLocal added in v1.0.6

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

SLocal register a command to be run on localhost

func (*Deployer) SRemote added in v1.0.6

func (sc *Deployer) SRemote(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)

Upload register a upload command

func (*Deployer) Verbose

func (sc *Deployer) Verbose(verbose bool)

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

type DownloadCommand added in v1.0.4

type DownloadCommand struct {
	LocalPath  string
	RemotePath string
	// contains filtered or unexported fields
}

DownloadCommand is the download command

func (*DownloadCommand) Run added in v1.0.4

func (downloadCmd *DownloadCommand) Run(deployCtx Deploy, srvConf *ServerConfig) error

Run the download command

func (*DownloadCommand) Sensitive added in v1.0.6

func (downloadCmd *DownloadCommand) Sensitive()

type LocalCommand

type LocalCommand struct {
	CmdStr string
	// contains filtered or unexported fields
}

LocalCommand is a local command

func (*LocalCommand) Run

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

Run the local command

func (*LocalCommand) Sensitive added in v1.0.6

func (localCmd *LocalCommand) Sensitive()

type RemoteCommand

type RemoteCommand struct {
	CmdStr string
	// contains filtered or unexported fields
}

RemoteCommand is a remote command

func (*RemoteCommand) Run

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

Run the remote command on the remote server

func (*RemoteCommand) Sensitive added in v1.0.6

func (remoteCmd *RemoteCommand) Sensitive()

type ServerConfig

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

ServerConfig is the ssh server config used to connect to remote server

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

MakeSSHConfig converts ServerConfig to easyssh.SSHConfig to ease using easyssh

func (*ServerConfig) Simple

func (sc *ServerConfig) Simple() string

Simple is too simple too naive to say anything about it

func (*ServerConfig) String

func (sc *ServerConfig) String() string

type SimpleCommand added in v1.0.0

type SimpleCommand struct {
	Handler func(Deploy, *ServerConfig, ...interface{}) error
	Args    []interface{}
	// contains filtered or unexported fields
}

SimpleCommand represents a simple customized command

func (*SimpleCommand) Run added in v1.0.0

func (cmd *SimpleCommand) Run(deployCtx Deploy, srvConf *ServerConfig) error

Run this simple customized command

func (*SimpleCommand) Sensitive added in v1.0.6

func (cmd *SimpleCommand) Sensitive()

type UploadCommand

type UploadCommand struct {
	LocalPath  string
	RemotePath string
	// contains filtered or unexported fields
}

UploadCommand is the upload command

func (*UploadCommand) Run

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

Run the upload command

func (*UploadCommand) Sensitive added in v1.0.6

func (uploadCmd *UploadCommand) Sensitive()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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