arty

package module
v0.0.0-...-e63a34c Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

README

arty

介绍

arty 是采用go语言解析配置文件的形式 自动生成geth的配置文件,并创建相应目录 通过docker go语言的sdk 管理docker的创建,运行管理等操作

下载说明

go get gitee.com/countpoison/arty.git

使用说明
package main

import (
	"gitee.com/countpoison/arty.git"
)

func main() {
	//完全自动执行,遇到错误会退出
	p, err := arty.Init()
	if err != nil {
		fmt.Println(err)
	}
	_, err = p.AutoExec()
	if err != nil {
		fmt.Println(err)
	}

}
配置文件字段含义说明

见wiki

镜像仓库地址

镜像名称 hub.c.163.com/lurktion/arty 版本号 wandering

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addmount

func Addmount(mountlist map[string]string) []mount.Mount

添加mountlist,返回符合ContainerConfig使用的结构

func Addport

func Addport(portlist []string) (nat.PortMap, nat.PortSet)

添加portlist

func ErrorOut

func ErrorOut(err error)

错误检查 直接退出

Types

type BootNoodConfig

type BootNoodConfig struct {
	Id      string
	Start   bool
	Status  string
	Port    string
	State   string
	IP      string
	Created int64
	Genesis Genesis
}

bootnode 配置结构

type Config

type Config struct {
	ChainId             int    `json:"chainId,omitempty"`
	HomesteadBlock      int    `json:"homesteadBlock,omitempty"`
	Eip150Block         int    `json:"eip150Block,omitempty"`
	Eip150Hash          string `json:"eip150Hash,omitempty"`
	Eip155Block         int    `json:"eip155Block,omitempty"`
	Eip158Block         int    `json:"eip158Block,omitempty"`
	ByzantiumBlock      int    `json:"byzantiumBlock,omitempty"`
	ConstantinopleBlock int    `json:"constantinopleBlock,omitempty"`
	Ethash              Ethash `json:"ethash,omitempty"`
}

type DockerInitConfig

type DockerInitConfig struct {
	Ctx                context.Context
	Cli                *client.Client
	Url                string
	Tag                string
	DOCKER_API_VERSION string
}

docker需要的数据初始化

type Ethash

type Ethash struct {
	Ethash string `json:"ethash,omitempty"`
}

type Genesis

type Genesis struct {
	Config     Config            `json:"config,omitempty"`
	Nonce      string            `json:"nonce,omitempty"`
	Timestamp  string            `json:"timestamp,omitempty"`
	ExtraData  string            `json:"extraData,omitempty"`
	GasLimit   string            `json:"gasLimit,omitempty"`
	Difficulty string            `json:"difficulty,omitempty"`
	MixHash    string            `json:"mixHash,omitempty"`
	Coinbase   string            `json:"coinbase,omitempty"`
	Alloc      map[string]string `json:"alloc"`
	Number     string            `json:"number,omitempty"`
	GasUsed    string            `json:"gasUsed,omitempty"`
	ParentHash string            `json:"parentHash,omitempty"`
}

genesis.json的结构体

type GlobalConf

type GlobalConf struct {
	Global           GlobalSet
	BootNood         BootNoodConfig
	Nodes            map[string]*NodesConfig
	DockerInitConfig DockerInitConfig
}

整体数据的结构体

func Init

func Init() (*GlobalConf, error)

func (*GlobalConf) AddNodeConfig

func (p *GlobalConf) AddNodeConfig(conf map[string]string) (*GlobalConf, error)

新增node节点,写入conf.ini

func (*GlobalConf) ArtyCreateDocker

func (p *GlobalConf) ArtyCreateDocker() (*GlobalConf, error)

func (*GlobalConf) AutoExec

func (p *GlobalConf) AutoExec() (*GlobalConf, error)

func (*GlobalConf) CheckConfigFile

func (p *GlobalConf) CheckConfigFile() (*GlobalConf, error)

检查配置文件是否符合标准,并且检查创建关键目录

func (*GlobalConf) CheckDockerInit

func (p *GlobalConf) CheckDockerInit() (*GlobalConf, error)

检查docker是否执行了初始化

func (*GlobalConf) CheckImage

func (p *GlobalConf) CheckImage(imagename string) bool

检查配置文件中的镜像是否存在

func (*GlobalConf) ContainerConfig

func (p *GlobalConf) ContainerConfig(postlist []string, mountlist map[string]string) (*container.Config, *container.HostConfig)

生成Container的配置文件,config和hostconfig

func (*GlobalConf) CreateBootNodeDocker

func (p *GlobalConf) CreateBootNodeDocker() (*GlobalConf, error)

生成bootnode的docker容器配置

func (*GlobalConf) CreateGenesisJson

func (p *GlobalConf) CreateGenesisJson() error

生成genesis.json文件

func (*GlobalConf) CreateNodeDocker

func (p *GlobalConf) CreateNodeDocker(node string) (*GlobalConf, error)

生成node的docker容器配置

func (*GlobalConf) DFileContentsVal

func (p *GlobalConf) DFileContentsVal() *GlobalConf

启动则加载默认配置文件

func (*GlobalConf) DeleteNodeConfig

func (p *GlobalConf) DeleteNodeConfig(nodename string) bool

删除node节点,写入conf.ini

func (*GlobalConf) DeletedockerAll

func (p *GlobalConf) DeletedockerAll(containername string) bool

删除容器全部相关信息

func (*GlobalConf) DockerInit

func (p *GlobalConf) DockerInit() (*GlobalConf, error)

docker 环境初始化

func (*GlobalConf) DockerStart

func (p *GlobalConf) DockerStart() (*GlobalConf, error)

启动全部docker,根据全局配置文件

func (*GlobalConf) EditBootStrapNodes

func (p *GlobalConf) EditBootStrapNodes(node string) (*GlobalConf, error)

修改bootstrapNodes信息 广播地址

func (*GlobalConf) Exec

func (p *GlobalConf) Exec() (*GlobalConf, error)

func (*GlobalConf) GetAddNodeNum

func (p *GlobalConf) GetAddNodeNum() string

获取新增的node名称

func (*GlobalConf) GetLocalIp

func (p *GlobalConf) GetLocalIp() string

获取本机IP

func (*GlobalConf) ListContainer

func (p *GlobalConf) ListContainer(all bool) (*GlobalConf, error)

列出配置文件中所有docker容器

func (*GlobalConf) ListImages

func (p *GlobalConf) ListImages() ([]map[string]string, error)

列出所有镜像

func (*GlobalConf) LoadConfigFile

func (p *GlobalConf) LoadConfigFile() (*GlobalConf, error)

global conf.ini文件是否存在,不存在则创建默认配置文件

func (*GlobalConf) NameToID

func (p *GlobalConf) NameToID(containername string) (string, string)

容器名称转id

func (*GlobalConf) NodeRegrep

func (p *GlobalConf) NodeRegrep(nodedirs []string) (*GlobalConf, error)

过滤conf.ini 里面所有Section,匹配符合规则的node标签写法

func (*GlobalConf) Node_conf

func (p *GlobalConf) Node_conf(node string) (*NodesConfig, error)

配置node自己的conf.ini文件的方法

func (*GlobalConf) PathExistsDir

func (p *GlobalConf) PathExistsDir(path string) error

检查目录是否存在,不存在则创建

func (*GlobalConf) PathExistsFile

func (p *GlobalConf) PathExistsFile(path string) bool

检查文件是否存在

func (*GlobalConf) PullImage

func (p *GlobalConf) PullImage(imagename string) bool

下载配置文件中的镜像

func (*GlobalConf) RebuildDocker

func (p *GlobalConf) RebuildDocker(containername string, all bool) (*GlobalConf, error)

重建容器,强制关闭和删除,保留数据(确认是否保留数据)

func (*GlobalConf) RemoveDocker

func (p *GlobalConf) RemoveDocker(containername string, all bool) bool

删除一个容器,强制关闭(请确认是否删除数据目录)

func (*GlobalConf) SetGlobalconfig

func (p *GlobalConf) SetGlobalconfig(edit map[string]string) (*GlobalConf, error)

修改全局配置 只允许启动前修改,可支持的修改参数为:bootNodeStart,bootNodePort,bootNodeIP,coinBase,NetworkId,imageUrl,imageTag,DOCKER_API_VERSION,BootstrapNodes

func (*GlobalConf) StartContainerSingle

func (p *GlobalConf) StartContainerSingle(ID string) (*GlobalConf, error)

启动单个docker

func (*GlobalConf) StopDocker

func (p *GlobalConf) StopDocker(containername string) bool

停止一个容器

type GlobalSet

type GlobalSet struct {
	WorkDir            string
	BaseDir            string
	BootNodeDir        string
	NodesDir           string
	BaseConfigFile     string
	BaseConfigFileByte *goconfig.ConfigFile
	LocalIP            string
	NetworkId          string
	CoinBase           string
	DCFileContents     []byte
	NCFileContents     []byte
}

全局配置结构

type NodesConfig

type NodesConfig struct {
	Id            string
	Start         bool
	State         string
	Created       int64
	Status        string
	Cmdstr        string
	Port          string
	Etherbase     string
	NodeIniConfig *goconfig.ConfigFile
}

node节点配置结构

Jump to

Keyboard shortcuts

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