愉快的使用cursor

This commit is contained in:
zeaslity
2025-02-26 09:25:24 +08:00
parent 60a1849207
commit b8170e00d4
11 changed files with 554 additions and 89 deletions

View File

@@ -1,11 +1,13 @@
package cmd
import (
"agent-wdd/cmd/beans"
"agent-wdd/config"
"agent-wdd/log"
"agent-wdd/op"
"agent-wdd/utils"
"fmt"
"runtime"
"github.com/spf13/cobra"
)
@@ -18,9 +20,18 @@ var (
"deltarpm", "net-tools", "iputils", "bind-utils", "lsof", "curl", "wget", "vim", "mtr", "htop",
}
dockerLocalInstallPath = "/root/wdd/docker-20.10.15.tgz" // 本地安装docker的文件路径
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
)
func init() {
switch runtime.GOARCH {
case "amd64":
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
case "arm64":
dockerLocalInstallPath = "/root/wdd/docker-arm64-20.10.15.tgz" // 本地安装docker的文件路径
}
}
// 添加base子命令
func addBaseSubcommands(cmd *cobra.Command) {
// 1.1 docker
@@ -88,7 +99,7 @@ func addDockerSubcommands(cmd *cobra.Command) {
}
// 没有传递参数,使用默认参数
version := "26.0.7"
version := "20.10.15"
log.Info("Installing Docker version: %s", version)
// 安装docker
@@ -113,6 +124,9 @@ func addDockerSubcommands(cmd *cobra.Command) {
Short: "本地安装Docker",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.Info("Installing Docker from local file: %s", dockerLocalInstallPath)
exist := utils.FileExistAndNotNull(dockerLocalInstallPath)
if !exist {
log.Error("Docker local install file not found: %s", dockerLocalInstallPath)
@@ -120,7 +134,72 @@ func addDockerSubcommands(cmd *cobra.Command) {
}
// 解压文件
utils.Unzip(dockerLocalInstallPath, "/root/wdd")
utils.UnzipFile(dockerLocalInstallPath, "/root/wdd")
// 安装docker
err := utils.MoveFolerToAnother("/root/wdd/docker", "/usr/bin")
if err != nil {
log.Error("Failed to move Docker binaries: %s", err.Error())
return
}
// 设置权限
chmodCmd := []string{"chmod", "777", "-R", "/usr/bin/docker*"}
ok, resultLog := op.SingleLineCommandExecutor(chmodCmd)
if !ok {
log.Error("Failed to set permissions for Docker binaries: %s", resultLog)
return
}
// 配置并启动Docker服务
// systemd daemonize docker
utils.AppendOverwriteContentToFile(beans.ContainerdDaemonService, beans.ContainerdServiceFile)
if !utils.FileExistAndNotNull(beans.ContainerdServiceFile) {
log.Error("docker deamon file not exists !")
}
utils.AppendOverwriteContentToFile(beans.DockerSocketDaemonService, beans.DockerSocketFile)
if !utils.FileExistAndNotNull(beans.DockerSocketFile) {
log.Error("docker deamon file not exists !")
}
utils.AppendOverwriteContentToFile(beans.DockerDaemonService, beans.DockerServiceFile)
if !utils.FileExistAndNotNull(beans.DockerServiceFile) {
log.Error("docker deamon file not exists !")
}
log.Info("docker dameon file append success !")
ok, resultLog = op.SystemdDaemonReload()
if !ok {
log.Error("daemon reload error ! %s", resultLog)
return
}
op.SingleLineCommandExecutor([]string{"systemctl", "unmask", "containerd"})
op.SingleLineCommandExecutor([]string{"systemctl", "unmask", "docker.socket"})
op.SingleLineCommandExecutor([]string{"systemctl", "unmask", "docker"})
op.SingleLineCommandExecutor([]string{"groupadd", "docker"})
op.SingleLineCommandExecutor([]string{"usermod", "-aG", "docker", "root"})
op.SingleLineCommandExecutor([]string{"newgrp", "docker"})
systemdUp, resultLog := op.SystemdUp("containerd")
if !systemdUp {
log.Error("[InstallDockerBastion] - start containerd service error ! %s", resultLog)
return
}
ok, resultLog = op.SystemdUp("docker.socket")
if !ok {
log.Error("[InstallDockerBastion] - start docker.socket error ! %s", resultLog)
return
}
ok, resultLog = op.SystemdUp("docker")
if !ok {
log.Error("[InstallDockerBastion] - start docker service error ! %s", resultLog)
return
}
log.Info("Docker installed successfully from local file!")
},
}

View File

@@ -0,0 +1,121 @@
package beans
var ContainerdServiceFile = "/lib/systemd/system/containerd.service"
var DockerSocketFile = "/lib/systemd/system/docker.socket"
var DockerServiceFile = "/lib/systemd/system/docker.service"
var ContainerdDaemonService = `
# Copyright The containerd Authors.
#
# 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.
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[installPrefix]
WantedBy=multi-user.target
`
var DockerSocketDaemonService = `
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[installPrefix]
WantedBy=sockets.target
`
var DockerDaemonService = `
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500
[installPrefix]
WantedBy=multi-user.target
`
var DockerDeamonConfig = `
{
"insecure-registries": [
"DockerRegisterDomain:8033",
"harbor.wdd.io:8033"
]
}
`