-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da788c4
commit 337a0d5
Showing
5 changed files
with
209 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright © 2019 NAME HERE <EMAIL ADDRESS> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const urlPrefix = "https://download.docker.com/linux/static/stable/x86_64/docker-%s.tgz" | ||
|
||
// printCmd represents the print command | ||
var printCmd = &cobra.Command{ | ||
Use: "print", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
versions := []string{ | ||
"docker-17.03.0-ce.tgz", | ||
"docker-17.03.1-ce.tgz", | ||
"docker-17.03.2-ce.tgz", | ||
"docker-17.06.0-ce.tgz", | ||
"docker-17.06.1-ce.tgz", | ||
"docker-17.06.2-ce.tgz", | ||
"docker-17.09.0-ce.tgz", | ||
"docker-17.09.1-ce.tgz", | ||
"docker-17.12.0-ce.tgz", | ||
"docker-17.12.1-ce.tgz", | ||
"docker-18.03.0-ce.tgz", | ||
"docker-18.03.1-ce.tgz", | ||
"docker-18.06.0-ce.tgz", | ||
"docker-18.06.1-ce.tgz", | ||
"docker-18.06.2-ce.tgz", | ||
"docker-18.06.3-ce.tgz", | ||
"docker-18.09.0.tgz", | ||
"docker-18.09.1.tgz", | ||
"docker-18.09.2.tgz", | ||
"docker-18.09.3.tgz", | ||
"docker-18.09.4.tgz", | ||
"docker-18.09.5.tgz", | ||
"docker-18.09.6.tgz", | ||
"docker-18.09.7.tgz", | ||
"docker-18.09.8.tgz", | ||
"docker-19.03.0.tgz", | ||
} | ||
|
||
for _, v := range versions { | ||
println(fmt.Sprintf(urlPrefix, v)) | ||
} | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(printCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// printCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// printCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package install | ||
|
||
import ( | ||
"bytes" | ||
"github.com/wonderivan/logger" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
func tarDocker(host string) { | ||
cmd := "tar --strip-components=1 -xvzf /root/docker.tgz -C /usr/local/bin" | ||
Cmd(host, cmd) | ||
} | ||
func configDocker(host string) { | ||
cmd := "mkdir -p " + DockerLib | ||
Cmd(host, cmd) | ||
cmd = "echo \"" + string(dockerConfig(RegistryArr, DockerLib)) + "\" > /etc/docker/daemon.json" | ||
Cmd(host, cmd) | ||
} | ||
func enableDocker(host string) { | ||
cmd := "echo \"" + string(dockerServiceFile()) + "\" > /usr/lib/systemd/system/docker.service" | ||
Cmd(host, cmd) | ||
cmd = "systemctl enable docker.service && systemctl restart docker.service" | ||
Cmd(host, cmd) | ||
} | ||
|
||
func uninstallDocker(host string) { | ||
cmd := "systemctl stop docker.service && systemctl disable docker.service" | ||
Cmd(host, cmd) | ||
cmd = "rm -rf /usr/local/bin/docker* && rm -rf /var/lib/docker && rm -rf /etc/docker/* " | ||
Cmd(host, cmd) | ||
cmd = "rm -rf " + DockerLib | ||
Cmd(host, cmd) | ||
} | ||
|
||
func dockerServiceFile() []byte { | ||
var templateText = string(`[Unit] | ||
Description=Docker Application Container Engine | ||
Documentation=https://docs.docker.com | ||
After=network.target | ||
[Service] | ||
Type=notify | ||
ExecStart=/usr/local/bin/dockerd | ||
ExecReload=/bin/kill -s HUP $MAINPID | ||
LimitNOFILE=infinity | ||
LimitNPROC=infinity | ||
LimitCORE=infinity | ||
TimeoutStartSec=0 | ||
Delegate=yes | ||
KillMode=process | ||
[Install] | ||
WantedBy=multi-user.target | ||
`) | ||
return []byte(templateText) | ||
} | ||
|
||
func dockerConfig(registryArr []string, dir string) []byte { | ||
var templateText = string(`{ | ||
"registry-mirrors": [ | ||
"http://373a6594.m.daocloud.io" | ||
], | ||
"insecure-registries": | ||
[{{.DOCKER_REGISTRY}}], | ||
"graph":"{{.DOCKER_LIB}}" | ||
}`) | ||
tmpl, err := template.New("text").Parse(templateText) | ||
if err != nil { | ||
logger.Error("template parse failed:", err) | ||
panic(1) | ||
} | ||
var envMap = make(map[string]interface{}) | ||
registry := strings.Join(registryArr, ",") | ||
envMap["DOCKER_REGISTRY"] = registry | ||
envMap["DOCKER_LIB"] = dir | ||
var buffer bytes.Buffer | ||
_ = tmpl.Execute(&buffer, envMap) | ||
return buffer.Bytes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package install | ||
|
||
//username | ||
var ( | ||
User string | ||
Passwd string | ||
Hosts []string | ||
RegistryArr []string | ||
DockerLib string | ||
PkgUrl string | ||
) | ||
|
||
type DockerInstaller struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package install | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
//SendPackage is | ||
func (s *DockerInstaller) SendPackage(url string) { | ||
pkg := path.Base(url) | ||
//only http | ||
isHttp := strings.HasPrefix(url, "http") | ||
wgetCommand := "" | ||
if isHttp { | ||
wgetParam := "" | ||
if strings.HasPrefix(url, "https") { | ||
wgetParam = "--no-check-certificate" | ||
} | ||
wgetCommand = fmt.Sprintf(" wget %s ", wgetParam) | ||
} | ||
remoteCmd := fmt.Sprintf("cd /root && %s %s ", wgetCommand, url) | ||
kubeLocal := fmt.Sprintf("/root/%s", pkg) | ||
var wm sync.WaitGroup | ||
for _, master := range Hosts { | ||
wm.Add(1) | ||
go func(master string) { | ||
defer wm.Done() | ||
if isHttp { | ||
go WatchFileSize(master, kubeLocal, GetFileSize(url)) | ||
Cmd(master, remoteCmd) | ||
} else { | ||
Copy(master, url, kubeLocal) | ||
} | ||
}(master) | ||
} | ||
wm.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters