Skip to content

Commit 456a5ef

Browse files
authored
Merge pull request #10 from ysicing/b2
fix(upgrade): fix linux upgrade
2 parents 91e7597 + 7b7e63f commit 456a5ef

22 files changed

+1168
-50
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Ergo CHANGELOG
22

3+
- v2.0.2
4+
- repo新增redis,etcd,mongodb,consul,minio,postgresql,rabbitmq
5+
36
- v2.0.1
47
- repo新增mysql
58
- plugin初步支持plugin, 参考kubectl plugin

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ergo upgrade
4545
- [x] `list` 列出支持的软件包
4646
- [x] `install` 安装软件包
4747
- [x] containerd
48-
- [x] mysql
48+
- [x] mysql,redis,etcd,mongodb,consul,minio,postgresql,rabbitmq
4949
- [x] `dump` dump安装脚本
5050
- [x] upgrade
5151
- [x] version

cmd/debian.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func newDebianCmd(f factory.Factory) *cobra.Command {
2727
// log: log.GetInstance(),
2828
}
2929
debian := &cobra.Command{
30-
Use: "debian",
30+
Use: "debian [flags]",
3131
Short: "初始化debian, 升级debian内核",
3232
Aliases: []string{"deb"},
3333
Args: cobra.NoArgs,

cmd/ops.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func newOPSCmd(f factory.Factory) *cobra.Command {
5353
log: f.GetLog(),
5454
}
5555
ops := &cobra.Command{
56-
Use: "ops",
56+
Use: "ops [flags]",
5757
Short: "基础运维",
5858
Version: "2.0.0",
5959
Args: cobra.NoArgs,

cmd/repo.go

+45-15
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ import (
88
"github.com/manifoldco/promptui"
99
"github.com/spf13/cobra"
1010
"github.com/ysicing/ergo/cmd/flags"
11-
install2 "github.com/ysicing/ergo/pkg/ergo/repo"
11+
install "github.com/ysicing/ergo/pkg/ergo/repo"
1212
"github.com/ysicing/ergo/pkg/util/factory"
1313
sshutil "github.com/ysicing/ergo/pkg/util/ssh"
1414
"strings"
1515
)
1616

1717
type RepoCmd struct {
1818
*flags.GlobalFlags
19-
local bool
20-
sshcfg sshutil.SSH
21-
ips []string
22-
output string
19+
local bool
20+
sshcfg sshutil.SSH
21+
ips []string
22+
output string
23+
volumes bool
24+
all bool
2325
}
2426

2527
// newRepoCmd ergo repo tools
@@ -29,7 +31,7 @@ func newRepoCmd(f factory.Factory) *cobra.Command {
2931
}
3032
repocmd.sshcfg.Log = f.GetLog()
3133
repo := &cobra.Command{
32-
Use: "repo",
34+
Use: "repo [flags]",
3335
Short: "包管理工具",
3436
Args: cobra.NoArgs,
3537
Version: "2.0.1",
@@ -58,11 +60,22 @@ func newRepoCmd(f factory.Factory) *cobra.Command {
5860
return repocmd.Dump()
5961
},
6062
}
63+
down := &cobra.Command{
64+
Use: "down",
65+
Short: "down",
66+
Version: "2.0.2",
67+
RunE: func(cobraCmd *cobra.Command, args []string) error {
68+
return repocmd.Down(args)
69+
},
70+
}
6171
repo.AddCommand(list)
6272
list.PersistentFlags().StringVarP(&repocmd.output, "output", "o", "", "prints the output in the specified format. Allowed values: table, json, yaml (default table)")
6373
repo.AddCommand(install)
6474
repo.AddCommand(dump)
6575
dump.PersistentFlags().StringVarP(&repocmd.output, "output", "o", "", "dump file, 默认stdout, 支持file")
76+
repo.AddCommand(down)
77+
down.PersistentFlags().BoolVar(&repocmd.all, "all", false, "Remove All Package")
78+
down.PersistentFlags().BoolVarP(&repocmd.volumes, "volumes", "v", false, "Remove named volumes declared in the volumes section of the Compose file and anonymous volumes attached to containers.")
6679
repo.PersistentFlags().StringVar(&repocmd.sshcfg.User, "user", "root", "用户")
6780
repo.PersistentFlags().StringVar(&repocmd.sshcfg.Pass, "pass", "", "密码")
6881
repo.PersistentFlags().StringVar(&repocmd.sshcfg.PkFile, "pk", "", "私钥")
@@ -73,13 +86,27 @@ func newRepoCmd(f factory.Factory) *cobra.Command {
7386
}
7487

7588
func (repo *RepoCmd) List() error {
76-
return install2.ShowPackage(repo.output)
89+
return install.ShowPackage(repo.output)
90+
}
91+
92+
func (repo *RepoCmd) Down(args []string) error {
93+
if repo.all {
94+
var n []string
95+
for _, p := range install.InstallPackages {
96+
n = append(n, p.Name)
97+
}
98+
return install.DownService(n, repo.volumes)
99+
}
100+
if len(args) == 0 {
101+
return fmt.Errorf("参数不全. eg: ergo repo down etcd redis --debug --volumes")
102+
}
103+
return install.DownService(args, repo.volumes)
77104
}
78105

79106
func (repo *RepoCmd) Dump() error {
80107
repo.sshcfg.Log.Infof("开始加载可用安装程序")
81108
searcher := func(input string, index int) bool {
82-
packages := install2.InstallPackages[index]
109+
packages := install.InstallPackages[index]
83110
name := strings.Replace(strings.ToLower(packages.Name), " ", "", -1)
84111
input = strings.Replace(strings.ToLower(input), " ", "", -1)
85112
return strings.Contains(name, input)
@@ -92,7 +119,7 @@ func (repo *RepoCmd) Dump() error {
92119
}
93120
prompt := promptui.Select{
94121
Label: "选择Dump软件包",
95-
Items: install2.InstallPackages,
122+
Items: install.InstallPackages,
96123
Searcher: searcher,
97124
Size: 4,
98125
Templates: templates,
@@ -101,16 +128,16 @@ func (repo *RepoCmd) Dump() error {
101128
if err != nil {
102129
return fmt.Errorf("选择异常: %v", err)
103130
}
104-
pn := install2.InstallPackages[selectid].Name
131+
pn := install.InstallPackages[selectid].Name
105132
repo.sshcfg.Log.Infof("\U0001F389 Dumping %v", pn)
106-
i := install2.NewInstall(install2.Meta{SSH: repo.sshcfg}, pn)
133+
i := install.NewInstall(install.Meta{SSH: repo.sshcfg}, pn)
107134
return i.Dump(repo.output)
108135
}
109136

110137
func (repo *RepoCmd) Install() error {
111138
repo.sshcfg.Log.Infof("开始加载可用安装程序")
112139
searcher := func(input string, index int) bool {
113-
packages := install2.InstallPackages[index]
140+
packages := install.InstallPackages[index]
114141
name := strings.Replace(strings.ToLower(packages.Name), " ", "", -1)
115142
input = strings.Replace(strings.ToLower(input), " ", "", -1)
116143
return strings.Contains(name, input)
@@ -129,7 +156,7 @@ func (repo *RepoCmd) Install() error {
129156
}
130157
prompt := promptui.Select{
131158
Label: "选择安装的软件包",
132-
Items: install2.InstallPackages,
159+
Items: install.InstallPackages,
133160
Searcher: searcher,
134161
Size: 4,
135162
Templates: templates,
@@ -138,9 +165,12 @@ func (repo *RepoCmd) Install() error {
138165
if err != nil {
139166
return fmt.Errorf("选择异常: %v", err)
140167
}
141-
pn := install2.InstallPackages[selectid].Name
168+
pn := install.InstallPackages[selectid].Name
142169
repo.sshcfg.Log.Infof("选择安装: %v", pn)
143-
i := install2.NewInstall(install2.Meta{SSH: repo.sshcfg, Local: repo.local, IPs: repo.ips}, pn)
170+
if len(repo.ips) == 0 && repo.local {
171+
return fmt.Errorf("配置ip或者本地调试")
172+
}
173+
i := install.NewInstall(install.Meta{SSH: repo.sshcfg, Local: repo.local, IPs: repo.ips}, pn)
144174
repo.sshcfg.Log.StartWait(fmt.Sprintf("开始安装: %v", pn))
145175
defer repo.sshcfg.Log.StopWait()
146176
if err := i.Install(); err != nil {

deploy.sh

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
#!/bin/bash
22

3-
ergo init vm --vmname istio --vmnum 3
3+
ergo debian init --local --debug
44

5-
ergo init debian --ip 11.11.11.111 --ip 11.11.11.112 --ip 11.11.11.113
6-
7-
ergo install docker --ip 11.11.11.111 --ip 11.11.11.112 --ip 11.11.11.113
8-
9-
ergo install tools --ip 11.11.11.111 --ip 11.11.11.112 --ip 11.11.11.113
10-
11-
# 安装master单节点
12-
ergo install k8s --enablenfs=true --mip 11.11.11.111
13-
# 安装多节点
14-
ergo install k8s --enablenfs=true --mip 11.11.11.111 --wip 11.11.11.112-11.11.11.113
5+
ergo debian upcore --ip 11.11.11.11 --pk ~/.ssh/id_rsa --debug

docs/jetbrains.svg

+66
Loading

go.mod

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.16
55
require (
66
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1016
77
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
8+
github.com/blang/semver v3.5.1+incompatible
89
github.com/ergoapi/util v0.0.7
910
github.com/fatih/color v1.13.0 // indirect
1011
github.com/go-logr/logr v1.1.0 // indirect
@@ -21,6 +22,7 @@ require (
2122
github.com/mitchellh/mapstructure v1.4.2 // indirect
2223
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
2324
github.com/pkg/sftp v1.13.4
25+
github.com/rhysd/go-github-selfupdate v1.2.3
2426
github.com/shirou/gopsutil/v3 v3.21.8
2527
github.com/sirupsen/logrus v1.8.1
2628
github.com/sohaha/zlsgo v0.1.65
@@ -30,10 +32,12 @@ require (
3032
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.222
3133
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.222
3234
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.222
35+
github.com/ulikunitz/xz v0.5.10 // indirect
3336
github.com/wangle201210/githubapi v0.0.0-20200804144924-cde7bbdc36ab
3437
github.com/ysicing/ext v0.0.0-20201215110233-f154cb6815c6
3538
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
36-
golang.org/x/net v0.0.0-20210929193557-e81a3d93ecf6 // indirect
39+
golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 // indirect
40+
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1 // indirect
3741
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
3842
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
3943
golang.org/x/text v0.3.7 // indirect

0 commit comments

Comments
 (0)