Documentation ¶
Index ¶
- Constants
- Variables
- func Deploy(g *Group, cfg *DeployConfig, reDeploy bool)
- func Setup(g *Group, cfg *DeployConfig)
- type DeployConfig
- type Group
- func (g *Group) Error(i int) error
- func (g *Group) Errors() []error
- func (g *Group) Ignore() *Group
- func (g *Group) Loose(on bool) *Group
- func (g *Group) Parallel() *Group
- func (g *Group) Printf(format string, args ...any) *Group
- func (g *Group) Println(args ...any) *Group
- func (g *Group) Run(cmds ...string) *Group
- func (g *Group) Sequence() *Group
- type Server
Constants ¶
View Source
const ( SequenceMode = 0 ParallelMode = 1 LooseMode = 1 << 1 )
View Source
const ( EnsureDocker = `which docker || (apt-get update -y && apt-get install docker.io -y)` EnsureCurl = `which curl || (apt-get update -y && apt-get install curl)` EnsureTraefik = `` // fixme 为了方便调试,这里加了 insecure /* 258-byte string literal not displayed */ )
Variables ¶
View Source
var ( DockerLoginRegistry = func(usr, pwd string) string { return fmt.Sprintf(`docker login -u %s -p %s`, usr, pwd) } DockerRemoveImage = func(image, tag string) string { return "docker image rm --force " + image + ":" + tag } DockerPullImage = func(image, tag string) string { return "docker pull " + image + ":" + tag } DockerStartTraefik = `docker start traefik` DockerRunHealthcheck = func(service, port, image, tag string, env map[string]string) string { cmd := `docker run --detach` cmd += fmt.Sprintf(` --name healthcheck-%s-%s`, service, tag) cmd += fmt.Sprintf(` --publish 3999:%s`, port) cmd += fmt.Sprintf(` --label service=healthcheck-%s`, service) for k, v := range env { cmd += " -e " + k + "=" + v } cmd += " " + image + ":" + tag return cmd } HealthCheck = func(entrypoint string) string { return `curl --silent --output /dev/null --write-out '%{http_code}' --max-time 2 ` + entrypoint } DockerStopContainer = func(name string) string { return fmt.Sprintf(`docker container ls --all --filter name=%s --quiet | xargs docker stop`, name) } DockerRemoveContainer = func(name string) string { return fmt.Sprintf(`docker container ls --all --filter name=%s --quiet | xargs docker container rm`, name) } DockerStartApplicationContainer = func(service, port, image, tag, healthcheck string, env map[string]string) string { return strings.Join([]string{`docker run --detach --restart unless-stopped`, `--log-opt max-size=10m`, `--name ` + service + "-" + tag, func() string { entries := make([]string, 0, len(env)) for k, v := range env { entries = append(entries, "-e "+k+"="+v) } return strings.Join(entries, " ") }(), `--label service=` + service, `--label role="web"`, fmt.Sprintf(`--label traefik.http.routers.%s.rule="PathPrefix(\"/\")"`, service), fmt.Sprintf(`--label traefik.http.services.%s.loadbalancer.healthcheck.path="%s"`, service, healthcheck), fmt.Sprintf(`--label traefik.http.services.%s.loadbalancer.healthcheck.interval="1s"`, service), fmt.Sprintf(`--label traefik.http.middlewares.%s.retry.attempts="5"`, service), fmt.Sprintf(`--label traefik.http.middlewares.%s.retry.initialinterval="500ms"`, service), image + ":" + tag, }, " ") } DockerPruneOldContainers = func(service string) string { return fmt.Sprintf(`docker container prune --force --filter label=service=%s --filter until=72h`, service) } DockerPruneOldImages = func(service string) string { return fmt.Sprintf(`docker image prune --all --force --filter label=service=%s --filter until=168h`, service) } )
View Source
var ( HostKeyCallback ssh.HostKeyCallback Signer ssh.Signer )
View Source
var CommandCounter uint32
Functions ¶
func Deploy ¶
func Deploy(g *Group, cfg *DeployConfig, reDeploy bool)
func Setup ¶
func Setup(g *Group, cfg *DeployConfig)
Types ¶
type DeployConfig ¶
type DeployConfig struct { Service string `yaml:"service"` Port string `yaml:"port"` Image string `yaml:"image"` Servers []string `yaml:"servers"` HealthCheck string `yaml:"health_check,omitempty"` SshConfig struct { Username string `yaml:"usr"` } `yaml:"ssh,omitempty"` Registry struct { // todo customize registry center Username any `yaml:"usr"` Password any `yaml:"pwd"` } `yaml:"registry"` Env []string `yaml:"env"` // contains filtered or unexported fields }
func LoadDeployConfig ¶
func LoadDeployConfig() (*DeployConfig, error)
Click to show internal directories.
Click to hide internal directories.