From e72746dc8ec6111af33767c73d1a56d5d9bc520f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Fri, 22 Nov 2019 10:23:32 +0100 Subject: [PATCH 1/9] Minor changes (todos and trivial refactoring) --- sim-administration/sim-batch-management/README.md | 6 ++++++ sim-administration/sim-batch-management/store/store.go | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sim-administration/sim-batch-management/README.md b/sim-administration/sim-batch-management/README.md index 0335ff988..4c83e757f 100644 --- a/sim-administration/sim-batch-management/README.md +++ b/sim-administration/sim-batch-management/README.md @@ -111,3 +111,9 @@ that justifies adding these checks). 10. Declare prime instances (should make sense to have both prod and dev defined with different constraints on them). + +11. Read througn https://github.com/alecthomas/kingpin/blob/master/parsers.go and + amend the command line reader to read existing files, proper DNS etc. + as appropriate. + +12. Refactor the main program. It's way to big now. diff --git a/sim-administration/sim-batch-management/store/store.go b/sim-administration/sim-batch-management/store/store.go index 1f9981269..1c2344d34 100644 --- a/sim-administration/sim-batch-management/store/store.go +++ b/sim-administration/sim-batch-management/store/store.go @@ -257,9 +257,8 @@ func (sdb SimBatchDB) GetProfileVendorByID(id int64) (*model.ProfileVendor, erro if len(result) == 0 { return nil, nil - } else { - return &result[0], nil } + return &result[0], nil } // GetProfileVendorByName find a profile vendor in the database by looking it up by name. From ac24f59558d7e8fdf2e6b574190d82903758b689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Fri, 22 Nov 2019 10:25:33 +0100 Subject: [PATCH 2/9] More todos --- sim-administration/sim-batch-management/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sim-administration/sim-batch-management/README.md b/sim-administration/sim-batch-management/README.md index 4c83e757f..4f713a41c 100644 --- a/sim-administration/sim-batch-management/README.md +++ b/sim-administration/sim-batch-management/README.md @@ -117,3 +117,11 @@ that justifies adding these checks). as appropriate. 12. Refactor the main program. It's way to big now. + +13. Rewrite the top-evel build-all.go to also compile go-code (which it + paradoxically doesn't do now). + +14. Make goland less confused with respect to imports than it is now. + +15. Fix all suggestions by goland. + From 7c34ff5807beedff46302dd81aa2cb5d134850b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Fri, 22 Nov 2019 15:42:28 +0100 Subject: [PATCH 3/9] Refactoring in preparation of adding building of go code. --- build-all.go | 75 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/build-all.go b/build-all.go index 684f3dbcb..08ebf5687 100755 --- a/build-all.go +++ b/build-all.go @@ -87,8 +87,11 @@ func generateDummyStripeEndpointSecretIfNotSet() { func main() { - cleanPtr := flag.Bool("clean", false, "If set, run a './gradlew clean' before building and testing.") - stayUpPtr := flag.Bool("stay-up", false, "If set, keep test environment up after running tests.") + cleanPtr := flag.Bool("clean", false, "If set, run a './gradlew clean' and 'go clean' before building and testing.") + stayUpPtr := flag.Bool("stay-up", false, "If set, keep test environment up in docker after running tests.") + doJvmPtr := flag.Bool("build-jvm-components", true, "If set, then compile and test JVM based components.") + doGoPtr := flag.Bool("build-golang-components", true, "If set, then compile and test GO based components.") + flag.Parse() log.Printf("About to get started\n") @@ -97,42 +100,56 @@ func main() { } if *stayUpPtr { - log.Printf(" ... will keep environment up after acceptance tests have run.") + log.Printf(" ... will keep environment up after acceptance tests have run (if any).") } - // - // Ensure that all preconditions for building and testing are met, if not - // fail and terminate execution. - // + log.Printf("Starting building.") + + + if !*doGoPtr { + log.Printf(" ... Not building/testing GO code") + } else { + log.Printf(" ... Building of GO code not implemented yet.") + } + + if !*doJvmPtr { + log.Printf(" ... Not building/testing JVM based code.") + + } else { + // + // Ensure that all preconditions for building and testing are met, if not + // fail and terminate execution. + // + + goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp") - goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp") + projectProfile := parseServiceAccountFile("prime-service-account.json") - projectProfile := parseServiceAccountFile("prime-service-account.json") + gcpProjectId := projectProfile.ProjectId - gcpProjectId := projectProfile.ProjectId - - os.Setenv("GCP_PROJECT_ID", gcpProjectId) + os.Setenv("GCP_PROJECT_ID", gcpProjectId) - goscript.AssertThatEnvironmentVariableaAreSet("STRIPE_API_KEY", "GCP_PROJECT_ID") - goscript.AssertDockerIsRunning() - generateDummyStripeEndpointSecretIfNotSet() - distributeServiceAccountConfigs( - "prime-service-account.json", - "c54b903790340dd9365fa59fce3ad8e2", - "acceptance-tests/config", - "dataflow-pipelines/config", - "ocsgw/config", - "auth-server/config prime/config") - generateEspEndpointCertificates( - "certs/ocs.dev.ostelco.org/nginx.crt", - "ocsgw/cert/metrics.crt", - "ocs.dev.ostelco.org") + goscript.AssertThatEnvironmentVariableaAreSet("STRIPE_API_KEY", "GCP_PROJECT_ID") + goscript.AssertDockerIsRunning() + generateDummyStripeEndpointSecretIfNotSet() + distributeServiceAccountConfigs( + "prime-service-account.json", + "c54b903790340dd9365fa59fce3ad8e2", + "acceptance-tests/config", + "dataflow-pipelines/config", + "ocsgw/config", + "auth-server/config prime/config") + generateEspEndpointCertificates( + "certs/ocs.dev.ostelco.org/nginx.crt", + "ocsgw/cert/metrics.crt", + "ocs.dev.ostelco.org") - buildUsingGradlew(cleanPtr) + buildUsingGradlew(cleanPtr) - runIntegrationTestsViaDocker(stayUpPtr) + runIntegrationTestsViaDocker(stayUpPtr) - log.Printf("Build and integration tests succeeded\n") + log.Printf("Build and integration tests succeeded\n") + } } type GcpProjectProfile struct { From bbbd2d70192fc2508a49404499cddf4859b5680d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Fri, 22 Nov 2019 15:51:22 +0100 Subject: [PATCH 4/9] Modify top-level build-all script to also compile/test go code --- build-all.go | 8 ++++++-- github.com/ostelco-core/goscript/goscript.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build-all.go b/build-all.go index 08ebf5687..607937718 100755 --- a/build-all.go +++ b/build-all.go @@ -109,19 +109,23 @@ func main() { if !*doGoPtr { log.Printf(" ... Not building/testing GO code") } else { - log.Printf(" ... Building of GO code not implemented yet.") + log.Printf(" ... Building and testing go code.") + goscript.AssertSuccesfulRun("go build ./...") + goscript.AssertSuccesfulRun("go test ./...") + goscript.AssertSuccesfulRun("~/go/bin/staticcheck ./...") } if !*doJvmPtr { log.Printf(" ... Not building/testing JVM based code.") } else { + log.Printf(" ... Building/testing JVM based code.") // // Ensure that all preconditions for building and testing are met, if not // fail and terminate execution. // - goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp") + goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp", "go") projectProfile := parseServiceAccountFile("prime-service-account.json") diff --git a/github.com/ostelco-core/goscript/goscript.go b/github.com/ostelco-core/goscript/goscript.go index c0ec2fc1d..f22369089 100644 --- a/github.com/ostelco-core/goscript/goscript.go +++ b/github.com/ostelco-core/goscript/goscript.go @@ -260,7 +260,7 @@ func checkIfDockerIsRunning() bool { out, err := exec.Command("bash", "-c", cmd).Output() ostring := string(out) - if "Docker not running" == ostring && err == nil { + if ostring == "Docker not running" && err == nil { return false } From 9fe2358cdb6a20baef95f2378a0724f25465d7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Fri, 22 Nov 2019 15:52:56 +0100 Subject: [PATCH 5/9] Make dependency checking for running the build script dependent of the architecture being compiled. --- build-all.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build-all.go b/build-all.go index 607937718..81ec31f86 100755 --- a/build-all.go +++ b/build-all.go @@ -110,6 +110,8 @@ func main() { log.Printf(" ... Not building/testing GO code") } else { log.Printf(" ... Building and testing go code.") + goscript.AssertThatScriptCommandsAreAvailable("go", "~/go/bin/staticcheck") + goscript.AssertSuccesfulRun("go build ./...") goscript.AssertSuccesfulRun("go test ./...") goscript.AssertSuccesfulRun("~/go/bin/staticcheck ./...") @@ -125,7 +127,7 @@ func main() { // fail and terminate execution. // - goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp", "go") + goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp") projectProfile := parseServiceAccountFile("prime-service-account.json") From 06a4ea44fb7b7866552684c8997b486876837574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Fri, 22 Nov 2019 19:08:18 +0100 Subject: [PATCH 6/9] Whitespace --- build-all.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-all.go b/build-all.go index 81ec31f86..e5cfe7faa 100755 --- a/build-all.go +++ b/build-all.go @@ -194,7 +194,7 @@ func parseServiceAccountFile(filename string) (GcpProjectProfile) { func runIntegrationTestsViaDocker(stayUpPtr *bool) { - // First take down any lingering docker jobs that may interfer with + // First take down any lingering docker jobs that may interfere with // the current run. goscript.AssertSuccesfulRun("docker-compose down") From daaae6e19b1f599e937e89d001e1520020df911d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Mon, 25 Nov 2019 09:38:32 +0100 Subject: [PATCH 7/9] Adding a proper link --- sim-administration/sim-batch-management/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sim-administration/sim-batch-management/README.md b/sim-administration/sim-batch-management/README.md index 4f713a41c..4f913354b 100644 --- a/sim-administration/sim-batch-management/README.md +++ b/sim-administration/sim-batch-management/README.md @@ -112,7 +112,7 @@ that justifies adding these checks). 10. Declare prime instances (should make sense to have both prod and dev defined with different constraints on them). -11. Read througn https://github.com/alecthomas/kingpin/blob/master/parsers.go and +11. Read through (https://github.com/alecthomas/kingpin/blob/master/parsers.go)[parser options in kingpin] and amend the command line reader to read existing files, proper DNS etc. as appropriate. @@ -124,4 +124,3 @@ that justifies adding these checks). 14. Make goland less confused with respect to imports than it is now. 15. Fix all suggestions by goland. - From 07d2bfdea2ca06567940457065422a65e53fa66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Mon, 25 Nov 2019 13:57:59 +0100 Subject: [PATCH 8/9] Twiddle parens --- sim-administration/sim-batch-management/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sim-administration/sim-batch-management/README.md b/sim-administration/sim-batch-management/README.md index 4f913354b..f6a86bc16 100644 --- a/sim-administration/sim-batch-management/README.md +++ b/sim-administration/sim-batch-management/README.md @@ -112,7 +112,7 @@ that justifies adding these checks). 10. Declare prime instances (should make sense to have both prod and dev defined with different constraints on them). -11. Read through (https://github.com/alecthomas/kingpin/blob/master/parsers.go)[parser options in kingpin] and +11. Read through [parser options in kingpin](https://github.com/alecthomas/kingpin/blob/master/parsers.go) and amend the command line reader to read existing files, proper DNS etc. as appropriate. From 835729ebe9f496a48869a1afe8f06855e66e9f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Remseth?= Date: Fri, 13 Dec 2019 14:03:11 +0100 Subject: [PATCH 9/9] Fixing code according to review comments --- build-all.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/build-all.go b/build-all.go index e5cfe7faa..1bf3b7d2e 100755 --- a/build-all.go +++ b/build-all.go @@ -87,26 +87,26 @@ func generateDummyStripeEndpointSecretIfNotSet() { func main() { - cleanPtr := flag.Bool("clean", false, "If set, run a './gradlew clean' and 'go clean' before building and testing.") - stayUpPtr := flag.Bool("stay-up", false, "If set, keep test environment up in docker after running tests.") - doJvmPtr := flag.Bool("build-jvm-components", true, "If set, then compile and test JVM based components.") - doGoPtr := flag.Bool("build-golang-components", true, "If set, then compile and test GO based components.") + clean := flag.Bool("clean", false, "If set, run a './gradlew clean' and 'go clean' before building and testing.") + stayUp := flag.Bool("stay-up", false, "If set, keep test environment up in docker after running tests.") + doJvm := flag.Bool("build-jvm-components", true, "If set, then compile and test JVM based components.") + doGo := flag.Bool("build-golang-components", true, "If set, then compile and test GO based components.") flag.Parse() log.Printf("About to get started\n") - if *cleanPtr { + if *clean { log.Printf(" ... will clean.") } - if *stayUpPtr { + if *stayUp { log.Printf(" ... will keep environment up after acceptance tests have run (if any).") } log.Printf("Starting building.") - if !*doGoPtr { + if !*doGo { log.Printf(" ... Not building/testing GO code") } else { log.Printf(" ... Building and testing go code.") @@ -117,9 +117,8 @@ func main() { goscript.AssertSuccesfulRun("~/go/bin/staticcheck ./...") } - if !*doJvmPtr { + if !*doJvm { log.Printf(" ... Not building/testing JVM based code.") - } else { log.Printf(" ... Building/testing JVM based code.") // @@ -150,9 +149,9 @@ func main() { "ocsgw/cert/metrics.crt", "ocs.dev.ostelco.org") - buildUsingGradlew(cleanPtr) + buildUsingGradlew(*clean) - runIntegrationTestsViaDocker(stayUpPtr) + runIntegrationTestsViaDocker(*stayUp) log.Printf("Build and integration tests succeeded\n") } @@ -192,13 +191,13 @@ func parseServiceAccountFile(filename string) (GcpProjectProfile) { return profile } -func runIntegrationTestsViaDocker(stayUpPtr *bool) { +func runIntegrationTestsViaDocker(stayUpPtr bool) { // First take down any lingering docker jobs that may interfere with // the current run. goscript.AssertSuccesfulRun("docker-compose down") - if *stayUpPtr { + if stayUpPtr { // If ctrl-c is pushed during stay-up, then take the whole thing down using docker-compose down c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) @@ -213,12 +212,12 @@ func runIntegrationTestsViaDocker(stayUpPtr *bool) { } } -func buildUsingGradlew(cleanPtr *bool) { +func buildUsingGradlew(clean bool) { // // All preconditions are now satisfied, now run the actual build/test commands // and terminate the build process if any of them fails. // - if *cleanPtr { + if clean { goscript.AssertSuccesfulRun("./gradlew build") } goscript.AssertSuccesfulRun("./gradlew build")