From 54db8b67a7cbd423bdf2e88deb80507e6392b099 Mon Sep 17 00:00:00 2001 From: Alok G Singh Date: Thu, 22 Apr 2021 12:00:42 +0530 Subject: [PATCH] Fixing manifest paths --- .goreleaser.yml | 2 -- Makefile | 12 +++++++----- confgen/templates.go | 13 +++++++++---- devenv/terraform.go | 18 +++++++++++++++--- devenv/terraform/variables.tf | 11 ++++++++--- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 9c6d4e01..d4fa1d3e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,8 +11,6 @@ builds: - -X github.com/TykTechnologies/gromit/util.commit={{.Commit}} - -X github.com/TykTechnologies/gromit/util.buildDate={{.Date}} mod_timestamp: '{{ .CommitTimestamp }}' - hooks: - pre: go generate ./confgen ./devenv archives: - replacements: diff --git a/Makefile b/Makefile index a920685f..0f644e2e 100644 --- a/Makefile +++ b/Makefile @@ -23,17 +23,19 @@ test: go test -coverprofile cp.out ./... # dlv test ./cmd # sow: clean - docker build -t $(@) . && docker run --rm --name $(@) \ - -e GROMIT_TABLENAME=DeveloperEnvironments \ - -e GROMIT_REPOS=tyk,tyk-analytics,tyk-pump \ + docker run --rm --name $(@) \ + -e GROMIT_TABLENAME=GromitTest \ + -e GROMIT_REPOS=tyk,tyk-analytics,tyk-pump,tyk-identity-broker,raava \ -e AWS_ACCESS_KEY_ID=$(aws_id) \ -e AWS_SECRET_ACCESS_KEY=$(aws_key) \ -e AWS_REGION=eu-central-1 \ -e TF_API_TOKEN=$(tf_api) \ -e GROMIT_DOMAIN=dev.tyk.technology \ - -e GROMIT_ZONEID=Z06422931MJIQS870BBM7 \ + -e GROMIT_ZONEID=Z0326653CS8RP88TOKKI \ + -e GROMIT_BASE=base-devenv-euc1-test \ + -e GROMIT_INFRA=infra-devenv-euc1-test \ --mount type=bind,src=$(PWD)/$(CONF_VOL),target=/config \ - $(@) -l trace /config + tykio/gromit:latest -l trace sow /config licenser: clean docker build -t $(@) . && docker run --rm --name $(@) \ diff --git a/confgen/templates.go b/confgen/templates.go index 60adfa3e..56ef24f8 100644 --- a/confgen/templates.go +++ b/confgen/templates.go @@ -34,20 +34,25 @@ func makeConfigTree(fs embed.FS, src string, dest string, tVars templateVars) er makeConfigTree(fs, srcPath, destPath, tVars) } else { // e is a file - data, err := ioutil.ReadFile(srcPath) + i, err := fs.Open(srcPath) + if err != nil { + return err + } + data, err := ioutil.ReadAll(i) if err != nil { log.Error().Err(err).Str("srcPath", srcPath).Msgf("could not read from embedded file") return err } tempStr := string(data) t := template.Must(template.New(e.Name()).Parse(tempStr)) - f, err := os.Create(destPath) + + o, err := os.Create(destPath) if err != nil { log.Error().Err(err).Msgf("could not create: %s", destPath) return err } - defer f.Close() - err = t.Execute(f, tVars) + defer o.Close() + err = t.Execute(o, tVars) if err != nil { return err } diff --git a/devenv/terraform.go b/devenv/terraform.go index 280f02a4..ce2b98a9 100644 --- a/devenv/terraform.go +++ b/devenv/terraform.go @@ -98,7 +98,15 @@ func (d *DevEnv) Reap(confPath string) error { // See master.tfvars for a sample inputfile in hcl format func (d *DevEnv) makeInputVarfile(tfDir string) error { varFile := fmt.Sprintf("%s.tfvars.json", d.Name) - varsJSON, err := json.Marshal(d.versions) + inputMap := make(map[string]string) + for k, v := range d.versions { + inputMap[k] = v + } + inputMap["base"] = os.Getenv("GROMIT_BASE") + inputMap["infra"] = os.Getenv("GROMIT_INFRA") + inputMap["name"] = d.Name + + varsJSON, err := json.Marshal(inputMap) if err != nil { return err } @@ -137,7 +145,11 @@ func copyEmbedDir(fs embed.FS, src string, dest string) error { copyEmbedDir(fs, srcPath, destPath) } else { // e is a file - data, err := ioutil.ReadFile(srcPath) + f, err := fs.Open(srcPath) + if err != nil { + return err + } + data, err := ioutil.ReadAll(f) if err != nil { return err } @@ -157,7 +169,7 @@ func deployManifest(fs embed.FS, destPrefix string) (string, error) { return "", err } - err = copyEmbedDir(fs, ".", tmpDir) + err = copyEmbedDir(fs, "terraform", tmpDir) if err != nil { log.Fatal().Err(err).Str("dest", tmpDir).Msg("could not restore embedded manifests") } diff --git a/devenv/terraform/variables.tf b/devenv/terraform/variables.tf index 9505c985..ddcfa5b4 100644 --- a/devenv/terraform/variables.tf +++ b/devenv/terraform/variables.tf @@ -1,39 +1,44 @@ variable "base" { description = "State to use for base resources" - type = string + type = string } variable "infra" { description = "State to use for infra resources" - type = string + type = string } variable "name" { description = "The DNS record will be name-{gw,db,etc}" - type = string + type = string } variable "tyk" { description = "Image tag for the tyk service" type = string + default = "master" } variable "tyk-analytics" { description = "Image tag for the tyk-analytics service" type = string + default = "master" } variable "tyk-pump" { description = "Image tag for the tyk-pump service" type = string + default = "master" } variable "raava" { description = "Image tag for the raava service" type = string + default = "master" } variable "tyk-identity-broker" { description = "Image tag for the tib service" type = string + default = "master" }