cicd

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

import "github.com/acoronadoc/cicd"

Golang library for AMAZING CI/CD pipelines

What is CI/CD

CI/CD stands for Continuous Integration and Continuous Delivery. It's a set of practices in software development that aims to automate the process of building, testing, and deploying code changes. With CI/CD, developers can frequently integrate code changes into a shared repository, and those changes are automatically built, tested, and deployed to different environments. This approach helps to improve software quality, reduce the risk of errors, and accelerate time to market.

Features

  • Lightweight, flexible and fast.
  • Create pipelines.
  • Connect Git repositories(Check commits and clone) using username/password or certificates.
  • Execute Local or SSH/SFTP commands.
  • Check for remote commands availability.
  • Check for remote servers resources(RAM and disk) availability.

Road Map

  • More remote "actions": Remote execution, CPU availability, ...
  • More operations with repositories.
  • Log exports.
  • A User console in order to manage scripts, logs and servers.
  • Native support for Git.

Installation

Simple install the package to your $GOPATH with the go tool from shell:

go get -u github.com/acoronadoc/cicd

Samples

Get last commit from a Git repository:

/* From public repository */
commitId, ecode := GitLastCommit("https://github.com/acoronadoc/chatbot-sample.git", "main")

/* With private key */
commitId, ecode := GitLastCommitSSH("ssh://git@localhost:2221/srv/git/tmpgit", "main", "./keys/id_ed25599")

Execute remote command via SSH:

/* With user / pass credentials */
config := CreateUserPasswordSSHConfig("devops", "123456")

stdout, stderr, ecode := ExecSSH("192.168.15.33", config, "echo 'hola'")

/* With user / SSH key credentials */
config := CreateSSHKeysSSHConfig("devops", "./keys/id_ed25599")

stdout, stderr, ecode := ExecSSH("192.168.15.33", config, "echo 'hola'")

Send/receive file via SFTP:

/* Send file with user / pass credentials */
config := CreateUserPasswordSSHConfig("devops", "123456")

ecode := SFTPCopyLocalToRemote("192.168.15.33", config, "./test.txt", "/tmp/test.txt")

/* Receive file width user / SSH key credentials */
config := CreateSSHKeysSSHConfig("devops", "./keys/id_ed25599")

ecode := SFTPCopyRemoteToLocal("192.168.15.33", config, "/tmp/test.txt", "./test.txt")

Check for server resources and available commands:

config := CreateSSHKeysSSHConfig("devops", "./keys/id_ed25599")

ecode, r := CheckServerSSH(SSHHost, config, []CheckSSHServer{
		{Name: "RAM", Operation: CheckRAM},
		{Name: "Disk", Operation: CheckDisk},
		{Name: "ls-cmd", Operation: CheckCommandExist, Params: []string{"ls"}},
		{Name: "kubectl-cmd", Operation: CheckCommandExist, Params: []string{"kubectl"}},
	})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckServerSSH

func CheckServerSSH(host string, config *ssh.ClientConfig, checks []CheckSSHServer) (int, map[string]CheckSSHResult)

func CreateSSHKeysSSHConfig

func CreateSSHKeysSSHConfig(username string, pubkeyfile string) *ssh.ClientConfig

func CreateUserPasswordSSHConfig

func CreateUserPasswordSSHConfig(username string, password string) *ssh.ClientConfig

func ExecSSH

func ExecSSH(host string, config *ssh.ClientConfig, command string) (string, string, int)

func ExecuteCommand

func ExecuteCommand(command string, args []string, env []string) (string, string, int)

func GitClone

func GitClone(url string, branch string, folder string) int

func GitCloneSSH

func GitCloneSSH(url string, branch string, folder string, idrsa string) int

func GitLastCommit

func GitLastCommit(url string, branch string) (string, int)

func GitLastCommitSSH

func GitLastCommitSSH(url string, branch string, idrsa string) (string, int)

func SFTPCopyLocalToRemote

func SFTPCopyLocalToRemote(host string, config *ssh.ClientConfig, src string, to string) int

func SFTPCopyRemoteToLocal

func SFTPCopyRemoteToLocal(host string, config *ssh.ClientConfig, src string, to string) int

func StartPipe

func StartPipe(bucle bool, pipe ...*RepoPipe)

Types

type CheckSSHResult

type CheckSSHResult struct {
	Err    bool
	Result bool
	Values map[string]string
}

type CheckSSHServer

type CheckSSHServer struct {
	Name      string
	Operation Operation
	Params    []string
}

type Operation

type Operation int
const (
	CheckRAM Operation = iota
	CheckDisk
	CheckCommandExist
)

type RepoPipe

type RepoPipe struct {
	Action func(*map[string]interface{})
}

func PipeWaitForCommit

func PipeWaitForCommit(repoURL string, branch string, key string, sleepTime int) *RepoPipe

func PipeWaitForCommitMulti

func PipeWaitForCommitMulti(repoURL []string, branch []string, key string, sleepTime int) *RepoPipe

Jump to

Keyboard shortcuts

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