Skip to content

Commit

Permalink
Merge pull request #958 from ostelco/feature/improved-esim-batch-mana…
Browse files Browse the repository at this point in the history
…gement

Feature/improved esim batch management
  • Loading branch information
la3lma authored Dec 18, 2019
2 parents 28e3b8a + 2deb3e8 commit b072ada
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 39 deletions.
94 changes: 58 additions & 36 deletions build-all.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,52 +87,74 @@ 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.")
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 {
log.Printf(" ... will keep environment up after acceptance tests have run.")
if *stayUp {
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 !*doGo {
log.Printf(" ... Not building/testing GO code")
} else {
log.Printf(" ... Building and testing go code.")
goscript.AssertThatScriptCommandsAreAvailable("go", "~/go/bin/staticcheck")

goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp")
goscript.AssertSuccesfulRun("go build ./...")
goscript.AssertSuccesfulRun("go test ./...")
goscript.AssertSuccesfulRun("~/go/bin/staticcheck ./...")
}

if !*doJvm {
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.
//

projectProfile := parseServiceAccountFile("prime-service-account.json")
goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp")

gcpProjectId := projectProfile.ProjectId

os.Setenv("GCP_PROJECT_ID", gcpProjectId)
projectProfile := parseServiceAccountFile("prime-service-account.json")

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")
gcpProjectId := projectProfile.ProjectId

buildUsingGradlew(cleanPtr)
os.Setenv("GCP_PROJECT_ID", gcpProjectId)

runIntegrationTestsViaDocker(stayUpPtr)
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")

log.Printf("Build and integration tests succeeded\n")
buildUsingGradlew(*clean)

runIntegrationTestsViaDocker(*stayUp)

log.Printf("Build and integration tests succeeded\n")
}
}

type GcpProjectProfile struct {
Expand Down Expand Up @@ -169,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 interfer with
// 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)
Expand All @@ -190,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")
Expand Down
2 changes: 1 addition & 1 deletion github.com/ostelco-core/goscript/goscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions sim-administration/sim-batch-management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,16 @@ 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 [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.

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.
3 changes: 1 addition & 2 deletions sim-administration/sim-batch-management/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b072ada

Please sign in to comment.