mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-04 11:42:39 -07:00
fix: converted from select to waitGroups.
This commit is contained in:
parent
e61e6d2994
commit
f7cba2689c
8 changed files with 75 additions and 31 deletions
48
.drone.yml
48
.drone.yml
|
@ -24,9 +24,13 @@ steps:
|
|||
- title: "Begin Build: ${DRONE_REPO}"
|
||||
text: "Build ${DRONE_BUILD_NUMBER}(${DRONE_COMMIT_LINK})"
|
||||
alert_type: "info"
|
||||
when:
|
||||
ref:
|
||||
include:
|
||||
- refs/tags/**
|
||||
|
||||
- name: Validate code base and dependencies
|
||||
image: dragonheim/golang:1.17.0
|
||||
image: dragonheim/golang:1.17.1
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
|
@ -53,7 +57,6 @@ steps:
|
|||
- trivy fs --skip-update --exit-code 1 --severity CRITICAL,HIGH .
|
||||
|
||||
# Build new container image.
|
||||
# - docker buildx build --push --platform linux/amd64 --progress plain --build-arg SEMVER="${DRONE_SEMVER}" -t "${DRONE_REPO}:latest" -t "${DRONE_REPO}:${DRONE_SEMVER}" -f docker/Dockerfile .
|
||||
- docker buildx build --platform linux/amd64 --progress plain --build-arg SEMVER="dev" -t "${DRONE_REPO}:dev" -f assets/docker/Dockerfile .
|
||||
|
||||
# Perform image security check of lower level vulnerabilities. This will not break the build, we just want this information, just in case.
|
||||
|
@ -62,17 +65,44 @@ steps:
|
|||
# Perform image security check of higher level vulnerabilities. This can break the build.
|
||||
- trivy image --skip-update --exit-code 1 --severity CRITICAL "${DRONE_REPO}:dev"
|
||||
|
||||
- name: Create Test Environment
|
||||
image: dragonheim/terraform:latest
|
||||
# - name: Create Test Environment
|
||||
# image: dragonheim/terraform:latest
|
||||
# volumes:
|
||||
# - name: dockersock
|
||||
# path: /var/run/docker.sock
|
||||
# environment:
|
||||
# TRIVY_QUIET: true
|
||||
# commands:
|
||||
# - cd assets/tfenv
|
||||
# - terraform init
|
||||
# - terraform plan
|
||||
|
||||
- name: Test application
|
||||
image: "${DRONE_REPO}:dev"
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
environment:
|
||||
TRIVY_QUIET: true
|
||||
commands:
|
||||
- cd assets/tfenv
|
||||
- terraform init
|
||||
- terraform plan
|
||||
- echo "running"
|
||||
|
||||
- name: Build and push container
|
||||
image: dragonheim/golang:1.17.1
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
when:
|
||||
ref:
|
||||
include:
|
||||
- refs/tags/**
|
||||
commands:
|
||||
# Build new container image.
|
||||
- docker buildx build --platform linux/amd64 --progress plain --build-arg SEMVER="${DRONE_SEMVER}" -t "${DRONE_REPO}:latest" -f docker/Dockerfile .
|
||||
|
||||
# Perform image security check of higher level vulnerabilities. This can break the build.
|
||||
- trivy image --skip-update --exit-code 1 --severity CRITICAL "${DRONE_REPO}:latest"
|
||||
|
||||
# Push new build
|
||||
- docker buildx build --push --platform linux/amd64 --progress plain --build-arg SEMVER="${DRONE_SEMVER}" -t "${DRONE_REPO}:latest" -t "${DRONE_REPO}:${DRONE_SEMVER}" -f docker/Dockerfile .
|
||||
|
||||
- name: Notify Datadog That We Have Completed
|
||||
image: masci/drone-datadog
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# No impact in our project
|
||||
CVE-2020-29652
|
||||
CVE-2020-9283
|
||||
# CVE-2020-29652
|
||||
# CVE-2020-9283
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
gs "git.dragonheim.net/dragonheim/gagent/internal/gstructs"
|
||||
|
@ -16,12 +17,14 @@ import (
|
|||
hclsimple "github.com/hashicorp/hcl/v2/hclsimple"
|
||||
hclwrite "github.com/hashicorp/hcl/v2/hclwrite"
|
||||
logutils "github.com/hashicorp/logutils"
|
||||
uuid "github.com/nu7hatch/gouuid"
|
||||
|
||||
uuid "github.com/jakehl/goid"
|
||||
cty "github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
var (
|
||||
semVER = "0.0.2"
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
var exitCodes = struct {
|
||||
|
@ -57,7 +60,8 @@ func main() {
|
|||
* This is used throughout the G'Agent system to uniquely identify this node.
|
||||
* It can be overridden in the configuration file by setting uuid
|
||||
*/
|
||||
identity, _ := uuid.NewV5(uuid.NamespaceURL, []byte("gagent"+config.Name))
|
||||
// identity, _ := uuid.NewV5(uuid.NamespaceURL, []byte("gagent"+config.Name))
|
||||
identity := uuid.NewV4UUID()
|
||||
config.UUID = identity.String()
|
||||
|
||||
/*
|
||||
|
@ -181,7 +185,8 @@ func main() {
|
|||
os.Exit(exitCodes.m["AGENT_LOAD_FAILED"])
|
||||
}
|
||||
for key := range config.Routers {
|
||||
go gc.Main(config, key, string(agent))
|
||||
wg.Add(1)
|
||||
go gc.Main(&wg, config, key, string(agent))
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
|
||||
|
@ -200,8 +205,9 @@ func main() {
|
|||
os.Exit(exitCodes.m["NO_WORKERS_DEFINED"])
|
||||
}
|
||||
|
||||
go gr.Main(config)
|
||||
select {}
|
||||
wg.Add(1)
|
||||
go gr.Main(&wg, config)
|
||||
// select {}
|
||||
|
||||
case "worker":
|
||||
/*
|
||||
|
@ -218,11 +224,12 @@ func main() {
|
|||
}
|
||||
|
||||
for key := range config.Routers {
|
||||
go gw.Main(config, key)
|
||||
time.Sleep(10 * time.Second)
|
||||
wg.Add(1)
|
||||
go gw.Main(&wg, config, key)
|
||||
// time.Sleep(10 * time.Second)
|
||||
}
|
||||
|
||||
select {}
|
||||
// select {}
|
||||
|
||||
case "setup":
|
||||
log.Printf("[INFO] Running in setup mode\n")
|
||||
|
@ -247,5 +254,6 @@ func main() {
|
|||
os.Exit(exitCodes.m["INVALID_MODE"])
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
os.Exit(exitCodes.m["SUCCESS"])
|
||||
}
|
||||
|
|
6
go.mod
6
go.mod
|
@ -5,11 +5,11 @@ go 1.16
|
|||
require (
|
||||
github.com/agext/levenshtein v1.2.3 // indirect
|
||||
github.com/aviddiviner/docopt-go v0.0.0-20170807220726-d8a1d67efc6a
|
||||
github.com/hashicorp/hcl/v2 v2.10.0
|
||||
github.com/hashicorp/hcl/v2 v2.10.1
|
||||
github.com/hashicorp/logutils v1.0.0
|
||||
github.com/jakehl/goid v1.1.0
|
||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
||||
github.com/pebbe/zmq4 v1.2.6
|
||||
github.com/pebbe/zmq4 v1.2.7
|
||||
github.com/zclconf/go-cty v1.8.3
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
)
|
||||
|
|
12
go.sum
12
go.sum
|
@ -17,10 +17,12 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
|
|||
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/hashicorp/hcl/v2 v2.10.0 h1:1S1UnuhDGlv3gRFV4+0EdwB+znNP5HmcGbIqwnSCByg=
|
||||
github.com/hashicorp/hcl/v2 v2.10.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
|
||||
github.com/hashicorp/hcl/v2 v2.10.1 h1:h4Xx4fsrRE26ohAk/1iGF/JBqRQbyUqu5Lvj60U54ys=
|
||||
github.com/hashicorp/hcl/v2 v2.10.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
|
||||
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
|
||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||
github.com/jakehl/goid v1.1.0 h1:c08GO8z16wWJtfQhyiD8BQRFkpf1oDxaPmA+uYAG+50=
|
||||
github.com/jakehl/goid v1.1.0/go.mod h1:V6bQh+tr2Oay5WHL0jmTTJWrABYIO+cs4/P6e1prV1o=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
|
@ -31,10 +33,8 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LE
|
|||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
|
||||
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
|
||||
github.com/pebbe/zmq4 v1.2.6 h1:zcTAfa/jYi2RxjTFIdLfnVrmxbAd9nSr02+CDMn8swg=
|
||||
github.com/pebbe/zmq4 v1.2.6/go.mod h1:nqnPueOapVhE2wItZ0uOErngczsJdLOGkebMxaO8r48=
|
||||
github.com/pebbe/zmq4 v1.2.7 h1:6EaX83hdFSRUEhgzSW1E/SPoTS3JeYZgYkBvwdcrA9A=
|
||||
github.com/pebbe/zmq4 v1.2.7/go.mod h1:nqnPueOapVhE2wItZ0uOErngczsJdLOGkebMxaO8r48=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
|
|
|
@ -12,7 +12,8 @@ import (
|
|||
)
|
||||
|
||||
// Main is the initiation function for a Client
|
||||
func Main(config gs.GagentConfig, rid int, agent string) {
|
||||
func Main(wg *sync.WaitGroup, config gs.GagentConfig, rid int, agent string) {
|
||||
defer wg.Done()
|
||||
log.Printf("[INFO] Starting client\n")
|
||||
|
||||
// Generate connect string for this router.
|
||||
|
@ -51,4 +52,5 @@ func Main(config gs.GagentConfig, rid int, agent string) {
|
|||
// }
|
||||
// mu.Unlock()
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package router
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
gs "git.dragonheim.net/dragonheim/gagent/internal/gstructs"
|
||||
|
||||
|
@ -15,7 +16,8 @@ const (
|
|||
)
|
||||
|
||||
// Main is the initiation function for a Router
|
||||
func Main(config gs.GagentConfig) {
|
||||
func Main(wg *sync.WaitGroup, config gs.GagentConfig) {
|
||||
defer wg.Done()
|
||||
log.Printf("[INFO] Starting router\n")
|
||||
|
||||
clientSock, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
|
|
|
@ -3,6 +3,7 @@ package worker
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
gs "git.dragonheim.net/dragonheim/gagent/internal/gstructs"
|
||||
|
||||
|
@ -11,7 +12,8 @@ import (
|
|||
)
|
||||
|
||||
// Main is the initiation function for a Worker
|
||||
func Main(config gs.GagentConfig, rid int) {
|
||||
func Main(wg *sync.WaitGroup, config gs.GagentConfig, rid int) {
|
||||
defer wg.Done()
|
||||
log.Printf("[INFO] Starting worker\n")
|
||||
|
||||
// Generate connect string for this router.
|
||||
|
|
Loading…
Add table
Reference in a new issue