This commit is contained in:
zeaslity
2025-02-26 17:49:03 +08:00
parent c751c21871
commit e8f0e0d4a9
3 changed files with 58 additions and 4 deletions

View File

@@ -20,15 +20,18 @@ var (
"deltarpm", "net-tools", "iputils", "bind-utils", "lsof", "curl", "wget", "vim", "mtr", "htop",
}
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
dockerComposeLocalInstallPath = "/root/wdd/docker-compose-v2.18.0-linux-amd64" // 本地安装docker compose的文件路径
)
func init() {
switch runtime.GOARCH {
case "amd64":
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
dockerComposeLocalInstallPath = "/root/wdd/docker-compose-v2.18.0-linux-amd64" // 本地安装docker compose的文件路径
case "arm64":
dockerLocalInstallPath = "/root/wdd/docker-arm64-20.10.15.tgz" // 本地安装docker的文件路径
dockerLocalInstallPath = "/root/wdd/docker-arm64-20.10.15.tgz" // 本地安装docker的文件路径
dockerComposeLocalInstallPath = "/root/wdd/docker-compose-v2.18.0-linux-arm64" // 本地安装docker compose的文件路径
}
}
@@ -293,6 +296,13 @@ func addDockerComposeSubcommands(cmd *cobra.Command) {
Short: "卸载Docker Compose",
Run: func(cmd *cobra.Command, args []string) {
log.Info("Removing Docker Compose...")
if utils.RemoveFile("/usr/local/bin/docker-compose") {
log.Info("Docker Compose removed successfully!")
} else {
log.Error("Failed to remove Docker Compose!")
}
},
}
@@ -302,6 +312,29 @@ func addDockerComposeSubcommands(cmd *cobra.Command) {
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.Info("Installing Docker Compose from local file...")
exist := utils.FileExistAndNotNull(dockerLocalInstallPath)
if !exist {
log.Error("Docker local install file not found: %s", dockerLocalInstallPath)
return
}
// move file to /usr/local/bin
err := utils.MoveFolerToAnother(dockerComposeLocalInstallPath, "/usr/local/bin")
if err != nil {
log.Error("Failed to move Docker Compose binaries: %s", err.Error())
return
}
// set permission
chmodCmd := []string{"chmod", "+x", "/usr/local/bin/docker-compose"}
ok, resultLog := op.SingleLineCommandExecutor(chmodCmd)
if !ok {
log.Error("Failed to set permissions for Docker Compose binaries: %s", resultLog)
return
}
log.Info("Docker Compose installed successfully from local file!")
},
}
@@ -310,6 +343,12 @@ func addDockerComposeSubcommands(cmd *cobra.Command) {
Short: "查看Docker Compose版本",
Run: func(cmd *cobra.Command, args []string) {
log.Info("Docker Compose version...")
ok, resultLog := op.SingleLineCommandExecutor([]string{"docker-compose", "--version"})
if !ok {
log.Error("Failed to get Docker Compose version: %s", resultLog)
return
}
log.Info("Docker Compose version: %s", resultLog)
},
}