devOps

package module
v0.0.0-...-7c000f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

README

做这个devOps是为了什么?

首先这个仅仅是个日常运维小工具,主要是方便开发人员用自己擅长的代码去处理常用的命令及操作。

devOps都用了什么?

  • github.com/bndr/gojenkins
  • mysqldump
  • expect
  • RDS_for_docker 用docker还原RDS物理备份 「查看详情
  • elasticsearch 基础操作

devOps有哪些功能?

  • jenkins build job
jenkinsConn, err := devOps.CreateJenkinsConn(
    "http://jenkins.local.com/",
    "admin",
    "111111")
if err != nil {
    return
}
//build
err = jenkinsConn.BuildJobWithGitParam(
    "testJenkinsApi",
    "any",
    "v1.0.201909111800")
if err != nil {
    return
}
  • scp 拉取文件
scpInfo := devOps.NewScpInfo()
scpInfo.Host = "172.16.0.225"
scpInfo.Port = 22
scpInfo.User = "jjc"
scpInfo.Password = "1"
scpInfo.ReadFilePath = "~/abc"
scpInfo.LocalSaveFilePath = fmt.Sprintf("/data/%d", time.Now().UnixNano())
scpInfo.Do()
  • ssh 执行命令
sshClient := devOps.NewSSHClient()
sshClient.User = "jjc"
sshClient.Password = "1"
sshClient.Host = "172.16.0.225"
sshClient.Port = 22

err := sshClient.SSHConnect()
defer sshClient.Close()
if err != nil {
    panic(err)
}

var stdOut, stdErr bytes.Buffer
//设置输出内容
sshClient.StdOut(&stdOut)
sshClient.StdErr(&stdErr)
//执行cmd
err = sshClient.DoCmd("ls -ll")
if err != nil {
    panic(err)
}
fmt.Println("stdOut:", stdOut.String())

fmt.Println("stdErr:", stdErr.String())

  • mysqldump备份指定表
dumper := devOps.NewDumper()
dumper.Host = "172.16.0.225"
dumper.User = "root"
dumper.Password = "root"
dumper.MysqlDumpPath = "mysqldump"
dumper.Database = "xxxxdatabas"
dumper.SavePath = fmt.Sprintf("/data/%d", time.Now().UnixNano())
dumper.TableNameList = []string{"a", "company"}
dumper.Do()
  • docker swarm http api
os.Setenv("DOCKER_HOST", "http://172.16.0.228:2375")
os.Setenv("DOCKER_API_VERSION", "1.39")
swarmCli, err := devOps.NewSwarmCli()
if err != nil{
    t.Error(err)
}
//创建一个network
res, err := swarmCli.CreateSwarmNetwork("test123123")
if err != nil{
    t.Error(err)
}

Documentation

Index

Constants

View Source
const DockerffmpegCutJPEGCmd = "docker run -v {{.Mp4FileDir}}:/temp/ jrottenberg/ffmpeg " +
	"-ss {{.CutTime}} " +
	"-i /temp/{{.FileName}} " +
	"-r 1 " +
	"-vframes 1 " +
	"-y /temp/{{.OutPutDir}}/{{.OnlyName}}.jpeg"
View Source
const DockerffmpegToM3U8Cmd = "docker run -v {{.Mp4FileDir}}:/temp/ jrottenberg/ffmpeg " +
	"-i /temp/{{.FileName}} " +
	"-f segment -segment_time 10 -segment_format mpegts " +
	"-segment_list /temp/{{.OutPutDir}}/{{.OnlyName}}.m3u8 " +
	"-c copy -bsf:v h264_mp4toannexb -map 0 /temp/{{.OutPutDir}}/{{.OnlyName}}-%08d.ts"
View Source
const (
	ReplicasAny = uint64(1)
)

Variables

This section is empty.

Functions

func NewDumper

func NewDumper() *dumper

func NewSSHClient

func NewSSHClient() *sshClient

func NewScpInfo

func NewScpInfo() *scpInfo

func NewSwarmCli

func NewSwarmCli() (*swarmCli, error)

Types

type DockerFFmpegMp4ToM3u8

type DockerFFmpegMp4ToM3u8 struct {
	// contains filtered or unexported fields
}

func (*DockerFFmpegMp4ToM3u8) DockerMp4CutJpeg

func (f *DockerFFmpegMp4ToM3u8) DockerMp4CutJpeg(mp4FilePath string, outputDir string, ssTime string) error

* 使用docker 进行mp4文件截图 @param string mp4FilePath mp4文件地址 @param string outputDir 相对mp4文件地址的目录 @param string ssTime 时间格式, 例如00:01:22

func (*DockerFFmpegMp4ToM3u8) DockerMp4ToM3u8

func (f *DockerFFmpegMp4ToM3u8) DockerMp4ToM3u8(mp4FilePath string, outputDir string) error

* 使用docker 进行mp4文件转换m3u8 @param string mp4FilePath mp4文件地址 @param string outputDir 相对mp4文件地址的目录

type GeneralService

type GeneralService struct {
	ID                      string
	ServiceSpec             swarm.ServiceSpec
	Option                  types.ServiceCreateOptions
	NetworkAttachmentConfig []swarm.NetworkAttachmentConfig
	PortConfig              []swarm.PortConfig
	MountList               []mount.Mount
	AnnotationsName         string   //service name
	ContainerSpecImageName  string   //使用image
	Replicas                uint64   //重启方式
	EnvList                 []string //环境变量
}

func (*GeneralService) GetEnv

func (service *GeneralService) GetEnv() []string

func (*GeneralService) GetOption

func (service *GeneralService) GetOption() types.ServiceCreateOptions

func (*GeneralService) GetReplicas

func (service *GeneralService) GetReplicas() *uint64

func (*GeneralService) GetServiceSpec

func (service *GeneralService) GetServiceSpec() swarm.ServiceSpec

func (*GeneralService) GetUpdateConfig

func (service *GeneralService) GetUpdateConfig() *swarm.UpdateConfig

* 服务更新方式

func (*GeneralService) Image

func (service *GeneralService) Image() string

* 容器名称

func (*GeneralService) Init

func (service *GeneralService) Init()

func (*GeneralService) SetAnnotationsName

func (service *GeneralService) SetAnnotationsName(annotationsName string)

* 设置服务名称

func (*GeneralService) SetContainerSpecImage

func (service *GeneralService) SetContainerSpecImage(containerSpecImage string)

* 设置镜像名称

func (*GeneralService) SetEnv

func (service *GeneralService) SetEnv(key, value string)

* 设置环境变量

func (*GeneralService) SetID

func (service *GeneralService) SetID(id string)

func (*GeneralService) SetMount

func (service *GeneralService) SetMount(mountType mount.Type, target, source string)

* 设置mount

func (*GeneralService) SetNetwork

func (service *GeneralService) SetNetwork(target string)

* 设置网络

func (*GeneralService) SetPortConfig

func (service *GeneralService) SetPortConfig(protocol swarm.PortConfigProtocol, targetPort, publishedPort uint32)

* 设置端口配置

func (*GeneralService) SetReplicas

func (service *GeneralService) SetReplicas(replicas uint64)

type JenkinsConn

type JenkinsConn struct {
	// contains filtered or unexported fields
}

func CreateJenkinsConn

func CreateJenkinsConn(jenkinsUrl, jenkinsAccount, jenkinsPassword string) (jenkinsConn *JenkinsConn, err error)

连接jenkins

func (*JenkinsConn) BuildJobWithGitParam

func (jenkinsConn *JenkinsConn) BuildJobWithGitParam(jobName, paramName, paramValue string) error

build job

type SwarmService

type SwarmService interface {
	Init()
	GetOption() types.ServiceCreateOptions
	GetServiceSpec() swarm.ServiceSpec
	SetNetwork(target string)
	SetID(id string)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL