Skip to content

Commit

Permalink
feat: support install go
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed May 7, 2020
1 parent 0f537aa commit a310a1d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
10 changes: 9 additions & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ var installDocker = &cobra.Command{
},
}

var installGo = &cobra.Command{
Use: "go",
Short: "安装go",
Run: func(cmd *cobra.Command, args []string) {
install.GoInstall()
},
}

var installK8s = &cobra.Command{
Use: "k8s",
Short: "安装k8s",
Expand Down Expand Up @@ -67,5 +75,5 @@ func init() {
installNfs.PersistentFlags().StringVar(&install.NfsPath, "nfspath", "/k8sdata", "nfs路径")
installNfs.PersistentFlags().StringVar(&install.DefaultSc, "nfssc", "nfs-data", "默认nfs storageclass")

installCmd.AddCommand(installDocker, installTools, installK8s, installNfs)
installCmd.AddCommand(installDocker, installGo, installTools, installK8s, installNfs)
}
1 change: 0 additions & 1 deletion install/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func K8sInstall() {
if i.EnableIngress {
i.IngressInstall()
}
klog.Info(i.EnableNfs)
if i.EnableNfs {
i.NfsInstall()
i.NfsDeploy()
Expand Down
12 changes: 9 additions & 3 deletions install/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ package install

func NfsInstall() {
i := &InstallConfig{
Hosts: Hosts,
Hosts: Hosts,
EnableNfs: EnableNfs,
ExtendNfsAddr: ExtendNfsAddr,
NfsPath: NfsPath,
DefaultSc: DefaultSc,
}
if i.EnableNfs {
i.NfsInstall()
i.NfsDeploy()
}
i.K8sInstall()

}
56 changes: 56 additions & 0 deletions install/docker.go → install/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ func DockerInstall() {
i.DockerInstall()
}

func GoInstall() {
i := &InstallConfig{
Hosts: Hosts,
}
i.GoInstall()
}

// DockerInstall docker 安装操作
func (i *InstallConfig) DockerInstall() {
var wg sync.WaitGroup
Expand All @@ -32,6 +39,55 @@ func (i *InstallConfig) DockerInstall() {
wg.Wait()
}

// GoInstall go 安装操作
func (i *InstallConfig) GoInstall() {
var wg sync.WaitGroup
dockerprecmd := fmt.Sprintf("echo '%s' > /tmp/go.install", goscript)
dockercmd := fmt.Sprintf("bash /tmp/go.install")
for _, ip := range i.Hosts {
wg.Add(1)
go func(ip string) {
defer wg.Done()
_ = SSHConfig.Cmd(ip, dockerprecmd)
_ = SSHConfig.Cmd(ip, dockercmd)
}(ip)
}
wg.Wait()
}

const goscript = `
#!/bin/bash
go::install(){
pushd /tmp
# 下载
wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
# 解压
tar -C /usr/local -xzf go1.14.2.linux-amd64.tar.gz
popd
}
go::config(){
cat >> /root/.bashrc <<EOF
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
export GOPATH="/root/go"
export GOBIN="$GOPATH/bin"
export PATH=$PATH:$GOBIN:/usr/local/go/bin
EOF
source /root/.bashrc
}
go::test(){
go env
}
go::install
go::config
go::test
`

const dockerscript = `
#!/bin/bash
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.5
0.4

0 comments on commit a310a1d

Please sign in to comment.