fix: rewrite the sql args and variables codebase to use expression values

This commit is contained in:
Vikram Rangnekar
2020-05-26 19:41:28 -04:00
parent f63e270c73
commit 2241364d00
35 changed files with 397 additions and 555 deletions

View File

@ -298,9 +298,9 @@ func ExtractErrorLine(source string, position int) (ErrorLineExtract, error) {
func getMigrationVars() map[string]interface{} {
return map[string]interface{}{
"app_name": strings.Title(conf.AppName),
"app_name_slug": strings.ToLower(strings.Replace(conf.AppName, " ", "_", -1)),
"env": strings.ToLower(os.Getenv("GO_ENV")),
"AppName": strings.Title(conf.AppName),
"AppNameSlug": strings.ToLower(strings.Replace(conf.AppName, " ", "_", -1)),
"Env": strings.ToLower(os.Getenv("GO_ENV")),
}
}

View File

@ -2,8 +2,7 @@ package serv
import (
"bytes"
"fmt"
"io"
"html/template"
"io/ioutil"
"os"
"path"
@ -11,7 +10,6 @@ import (
rice "github.com/GeertJohan/go.rice"
"github.com/spf13/cobra"
"github.com/valyala/fasttemplate"
)
func cmdNew(cmd *cobra.Command, args []string) {
@ -21,8 +19,8 @@ func cmdNew(cmd *cobra.Command, args []string) {
}
tmpl := newTempl(map[string]string{
"app_name": strings.Title(strings.Join(args, " ")),
"app_name_slug": strings.ToLower(strings.Join(args, "_")),
"AppName": strings.Title(strings.Join(args, " ")),
"AppNameSlug": strings.ToLower(strings.Join(args, "_")),
})
// Create app folder and add relevant files
@ -121,19 +119,16 @@ func newTempl(data map[string]string) *Templ {
func (t *Templ) get(name string) ([]byte, error) {
v := t.MustString(name)
b := bytes.Buffer{}
tmpl := fasttemplate.New(v, "{%", "%}")
_, err := tmpl.ExecuteFunc(&b, func(w io.Writer, tag string) (int, error) {
if val, ok := t.data[strings.TrimSpace(tag)]; ok {
return w.Write([]byte(val))
}
return 0, fmt.Errorf("unknown template variable '%s'", tag)
})
tmpl, err := template.New(name).Parse(v)
if err != nil {
return nil, err
}
if err := tmpl.Execute(&b, t.data); err != nil {
return nil, err
}
return b.Bytes(), nil
}

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@ steps:
[
"build",
"--tag",
"gcr.io/$PROJECT_ID/{% app_name_slug %}:latest",
"gcr.io/$PROJECT_ID/{{- .AppNameSlug -}}:latest",
"--build-arg",
"GO_ENV=production",
".",
@ -13,7 +13,7 @@ steps:
# Push new image to Google Container Registry
- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/{% app_name_slug %}:latest"]
args: ["push", "gcr.io/$PROJECT_ID/{{- .AppNameSlug -}}:latest"]
# Deploy image to Cloud Run
- name: "gcr.io/cloud-builders/gcloud"
@ -23,15 +23,15 @@ steps:
"deploy",
"data",
"--image",
"gcr.io/$PROJECT_ID/{% app_name_slug %}:latest",
"gcr.io/$PROJECT_ID/{{- .AppNameSlug -}}:latest",
"--add-cloudsql-instances",
"$PROJECT_ID:$REGION:{% app_name_slug %}_production",
"$PROJECT_ID:$REGION:{{- .AppNameSlug -}}_production",
"--region",
"$REGION",
"--platform",
"managed",
"--update-env-vars",
"GO_ENV=production,SG_DATABASE_HOST=/cloudsql/$PROJECT_ID:$REGION:{% app_name_slug %}_production,SECRETS_FILE=prod.secrets.yml",
"GO_ENV=production,SG_DATABASE_HOST=/cloudsql/$PROJECT_ID:$REGION:{{- .AppNameSlug -}}_production,SECRETS_FILE=prod.secrets.yml",
"--port",
"8080",
"--service-account",

View File

@ -1,4 +1,4 @@
app_name: "{% app_name %} Development"
app_name: "{{- .AppName }} Development"
host_port: 0.0.0.0:8080
web_ui: true
@ -82,7 +82,7 @@ cors_debug: false
auth:
# Can be 'rails', 'jwt' or 'header'
type: rails
cookie: _{% app_name_slug %}_session
cookie: _{{- .AppNameSlug -}}_session
# Comment this out if you want to disable setting
# the user_id via a header for testing.
@ -134,7 +134,7 @@ database:
type: postgres
host: db
port: 5432
dbname: {% app_name_slug %}_development
dbname: {{- .AppNameSlug -}}_development
user: postgres
password: postgres

View File

@ -9,48 +9,10 @@ services:
ports:
- "5432:5432"
# Yugabyte DB
# yb-master:
# image: yugabytedb/yugabyte:latest
# container_name: yb-master-n1
# command: [ "/home/yugabyte/bin/yb-master",
# "--fs_data_dirs=/mnt/disk0,/mnt/disk1",
# "--master_addresses=yb-master-n1:7100",
# "--replication_factor=1",
# "--enable_ysql=true"]
# ports:
# - "7000:7000"
# environment:
# SERVICE_7000_NAME: yb-master
# db:
# image: yugabytedb/yugabyte:latest
# container_name: yb-tserver-n1
# command: [ "/home/yugabyte/bin/yb-tserver",
# "--fs_data_dirs=/mnt/disk0,/mnt/disk1",
# "--start_pgsql_proxy",
# "--tserver_master_addrs=yb-master-n1:7100"]
# ports:
# - "9042:9042"
# - "6379:6379"
# - "5433:5433"
# - "9000:9000"
# environment:
# SERVICE_5433_NAME: ysql
# SERVICE_9042_NAME: ycql
# SERVICE_6379_NAME: yedis
# SERVICE_9000_NAME: yb-tserver
# depends_on:
# - yb-master
{% app_name_slug %}_api:
{{ .AppNameSlug -}}_api:
image: dosco/super-graph:latest
environment:
GO_ENV: "development"
# Uncomment below for Yugabyte DB
# SG_DATABASE_PORT: 5433
# SG_DATABASE_USER: yugabyte
# SG_DATABASE_PASSWORD: yugabyte
volumes:
- ./config:/config
ports:

View File

@ -2,7 +2,7 @@
# so I only need to overwrite some values
inherits: dev
app_name: "{% app_name %} Production"
app_name: "{{- .AppName }} Production"
host_port: 0.0.0.0:8080
web_ui: false
@ -82,7 +82,7 @@ database:
type: postgres
host: db
port: 5432
dbname: {% app_name_slug %}_production
dbname: {{- .AppNameSlug -}}_production
user: postgres
password: postgres
#pool_size: 10