mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
246 lines
6.8 KiB
Go
246 lines
6.8 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
_ "embed"
|
|
"os"
|
|
"path"
|
|
"time"
|
|
|
|
"github.com/hanzozt/fablab"
|
|
"github.com/hanzozt/fablab/kernel/lib/actions"
|
|
"github.com/hanzozt/fablab/kernel/lib/actions/component"
|
|
"github.com/hanzozt/fablab/kernel/lib/actions/host"
|
|
"github.com/hanzozt/fablab/kernel/lib/actions/semaphore"
|
|
"github.com/hanzozt/fablab/kernel/lib/binding"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/0_infrastructure/aws_ssh_key"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/0_infrastructure/semaphore"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/0_infrastructure/terraform"
|
|
distribution "github.com/hanzozt/fablab/kernel/lib/runlevel/3_distribution"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/3_distribution/rsync"
|
|
awsSshKeyDispose "github.com/hanzozt/fablab/kernel/lib/runlevel/6_disposal/aws_ssh_key"
|
|
"github.com/hanzozt/fablab/kernel/lib/runlevel/6_disposal/terraform"
|
|
"github.com/hanzozt/fablab/kernel/model"
|
|
"github.com/hanzozt/fablab/kernel/model/aws"
|
|
"github.com/hanzozt/fablab/resources"
|
|
"github.com/hanzozt/zt/zttest/models/test_resources"
|
|
"github.com/hanzozt/zt/zttest/ztlab"
|
|
"github.com/hanzozt/zt/zttest/ztlab/actions/edge"
|
|
"github.com/hanzozt/zt/zttest/ztlab/models"
|
|
)
|
|
|
|
const (
|
|
targetZitiVersion = ""
|
|
)
|
|
|
|
//go:embed configs
|
|
var configResource embed.FS
|
|
|
|
var m = &model.Model{
|
|
Id: "private-ctrl-test",
|
|
Scope: model.Scope{
|
|
Defaults: model.Variables{
|
|
"ha": true,
|
|
"environment": "private-ctrl-test",
|
|
"credentials": model.Variables{
|
|
"aws": model.Variables{
|
|
"managed_key": true,
|
|
},
|
|
"ssh": model.Variables{
|
|
"username": "ubuntu",
|
|
},
|
|
"edge": model.Variables{
|
|
"username": "admin",
|
|
"password": "admin",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
StructureFactories: []model.Factory{
|
|
model.FactoryFunc(func(m *model.Model) error {
|
|
return m.ForEachHost("*", 1, func(host *model.Host) error {
|
|
host.InstanceType = "t3.medium" // need larger cpu for all the tls handshaking with 200 hosts
|
|
return nil
|
|
})
|
|
}),
|
|
},
|
|
Resources: model.Resources{
|
|
resources.Configs: resources.SubFolder(configResource, "configs"),
|
|
resources.Binaries: os.DirFS(path.Join(os.Getenv("GOPATH"), "bin")),
|
|
resources.Terraform: test_resources.TerraformResources(),
|
|
},
|
|
AWS: aws.Model{
|
|
SecurityGroups: aws.SecurityGroups{
|
|
"private": {
|
|
Rules: []*aws.NetworkRule{
|
|
{
|
|
Direction: aws.Ingress,
|
|
Port: 1280, // web api
|
|
Protocol: "tcp",
|
|
},
|
|
{
|
|
Direction: aws.Ingress,
|
|
Port: 6262, // router/peer connections
|
|
Protocol: "tcp",
|
|
CidrBlocks: []string{"var.vpc_cidr", "66.66.118.13/32"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Regions: model.Regions{
|
|
"us-east-1": {
|
|
Region: "us-east-1",
|
|
Site: "us-east-1a",
|
|
Hosts: model.Hosts{
|
|
"ctrl1": {
|
|
Components: model.Components{
|
|
"ctrl1": {
|
|
AWS: aws.Component{
|
|
SecurityGroup: "private",
|
|
},
|
|
Scope: model.Scope{Tags: model.Tags{"ctrl", "private"}},
|
|
Type: &ztlab.ControllerType{
|
|
Version: targetZitiVersion,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"ctrl2": {
|
|
Components: model.Components{
|
|
"ctrl2": {
|
|
AWS: aws.Component{
|
|
SecurityGroup: "private",
|
|
},
|
|
Scope: model.Scope{Tags: model.Tags{"ctrl", "private"}},
|
|
Type: &ztlab.ControllerType{
|
|
Version: targetZitiVersion,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"router-east-1": {
|
|
Scope: model.Scope{Tags: model.Tags{"router"}},
|
|
Components: model.Components{
|
|
"router-east-1": {
|
|
Scope: model.Scope{Tags: model.Tags{"router"}},
|
|
Type: &ztlab.RouterType{
|
|
Version: targetZitiVersion,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"us-west-2": {
|
|
Region: "eu-west-2",
|
|
Site: "eu-west-2a",
|
|
Hosts: model.Hosts{
|
|
"ctrl3": {
|
|
Components: model.Components{
|
|
"ctrl3": {
|
|
Scope: model.Scope{Tags: model.Tags{"ctrl"}},
|
|
Type: &ztlab.ControllerType{
|
|
Version: targetZitiVersion,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"router-west-1": {
|
|
Scope: model.Scope{Tags: model.Tags{"router"}},
|
|
Components: model.Components{
|
|
"router-west-1": {
|
|
Scope: model.Scope{Tags: model.Tags{"router"}},
|
|
Type: &ztlab.RouterType{
|
|
Version: targetZitiVersion,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
Actions: model.ActionBinders{
|
|
"initHA": model.ActionBinder(func(m *model.Model) model.Action {
|
|
workflow := actions.Workflow()
|
|
workflow.AddAction(component.StartInParallel(".ctrl", 10))
|
|
workflow.AddAction(semaphore.Sleep(2 * time.Second))
|
|
workflow.AddAction(edge.RaftJoin("ctrl1", ".ctrl"))
|
|
workflow.AddAction(semaphore.Sleep(5 * time.Second))
|
|
return workflow
|
|
}),
|
|
"bootstrap": model.ActionBinder(func(m *model.Model) model.Action {
|
|
workflow := actions.Workflow()
|
|
|
|
workflow.AddAction(component.StopInParallel("*", 10000))
|
|
workflow.AddAction(host.GroupExec("component.ctrl", 100, "rm -f logs/* ctrl.db"))
|
|
workflow.AddAction(host.GroupExec("component.ctrl", 5, "rm -rf ./fablab/ctrldata"))
|
|
|
|
workflow.AddAction(component.Start("#ctrl1"))
|
|
workflow.AddAction(semaphore.Sleep(2 * time.Second))
|
|
workflow.AddAction(edge.InitRaftController("#ctrl1"))
|
|
|
|
workflow.AddAction(edge.ControllerAvailable("#ctrl1", 30*time.Second))
|
|
|
|
workflow.AddAction(edge.Login("#ctrl1"))
|
|
|
|
workflow.AddAction(edge.InitEdgeRouters(models.RouterTag, 25))
|
|
workflow.AddAction(model.RunAction("initHA"))
|
|
|
|
workflow.AddAction(component.StartInParallel(".router", 10))
|
|
workflow.AddAction(semaphore.Sleep(2 * time.Second))
|
|
|
|
return workflow
|
|
}),
|
|
"stop": model.Bind(component.StopInParallelHostExclusive("*", 10000)),
|
|
"clean": model.Bind(actions.Workflow(
|
|
component.StopInParallelHostExclusive("*", 10000),
|
|
host.GroupExec("*", 100, "rm -f logs/*"),
|
|
)),
|
|
"login": model.Bind(edge.Login("#ctrl1")),
|
|
"login2": model.Bind(edge.Login("#ctrl2")),
|
|
"login3": model.Bind(edge.Login("#ctrl3")),
|
|
"restart": model.ActionBinder(func(run *model.Model) model.Action {
|
|
workflow := actions.Workflow()
|
|
workflow.AddAction(component.StopInParallel("*", 10000))
|
|
workflow.AddAction(host.GroupExec("*", 100, "rm -f logs/*"))
|
|
workflow.AddAction(component.Start(".ctrl"))
|
|
workflow.AddAction(semaphore.Sleep(2 * time.Second))
|
|
workflow.AddAction(component.StartInParallel(".router", 10))
|
|
workflow.AddAction(semaphore.Sleep(2 * time.Second))
|
|
return workflow
|
|
}),
|
|
},
|
|
|
|
Infrastructure: model.Stages{
|
|
aws_ssh_key.Express(),
|
|
&terraform_0.Terraform{
|
|
Retries: 3,
|
|
ReadyCheck: &semaphore_0.ReadyStage{
|
|
MaxWait: 90 * time.Second,
|
|
},
|
|
},
|
|
},
|
|
|
|
Distribution: model.Stages{
|
|
distribution.DistributeSshKey("*"),
|
|
rsync.RsyncStaged(),
|
|
},
|
|
|
|
Disposal: model.Stages{
|
|
terraform.Dispose(),
|
|
awsSshKeyDispose.Dispose(),
|
|
},
|
|
}
|
|
|
|
func main() {
|
|
m.AddActivationActions("bootstrap")
|
|
|
|
model.AddBootstrapExtension(binding.AwsCredentialsLoader)
|
|
model.AddBootstrapExtension(aws_ssh_key.KeyManager)
|
|
|
|
fablab.InitModel(m)
|
|
fablab.Run()
|
|
}
|