Skip to content

Commit

Permalink
Add env group to render.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Aug 7, 2024
1 parent cc84619 commit f125841
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 26 deletions.
20 changes: 10 additions & 10 deletions backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
// Config structure holds all the configuration values
type Config struct {
// System Settings
Port int `env:"PORT" envDefault:"1323"`
GoEnv string `env:"GO_ENV" envDefault:"dev"`
Port int `env:"PORT,notEmpty" envDefault:"1323"`
GoEnv string `env:"GO_ENV,notEmpty" envDefault:"dev"`

// GraphQL related configurations
GQLComplexity int `env:"GQL_COMPLEXITY" envDefault:"10"`
GQLComplexity int `env:"GQL_COMPLEXITY,notEmpty" envDefault:"10"`

// PostgreSQL configuration
PGHost string `env:"PG_HOST" envDefault:"localhost"`
PGUser string `env:"PG_USER" envDefault:"testuser"`
PGPassword string `env:"PG_PASSWORD" envDefault:"testpassword"`
PGDBName string `env:"PG_DBNAME" envDefault:"flamingodb"`
PGPort string `env:"PG_PORT" envDefault:"5432"`
PGSSLMode string `env:"PG_SSLMODE" envDefault:"allow"`
// PostgresSQL configuration
PGHost string `env:"PG_HOST,notEmpty" envDefault:"localhost"`
PGUser string `env:"PG_USER,notEmpty" envDefault:"testuser"`
PGPassword string `env:"PG_PASSWORD,notEmpty" envDefault:"testpassword"`
PGDBName string `env:"PG_DBNAME,notEmpty" envDefault:"flamingodb"`
PGPort string `env:"PG_PORT,notEmpty" envDefault:"5432"`
PGSSLMode string `env:"PG_SSLMODE,notEmpty" envDefault:"allow"`
}

// Cfg is the package-level variable that holds the parsed configuration
Expand Down
66 changes: 66 additions & 0 deletions backend/pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package config_test

import (
"os"
"testing"

"backend/pkg/config"
"github.com/caarlos0/env/v11"
"github.com/stretchr/testify/assert"
)

func TestConfigDefaults(t *testing.T) {
// Explicitly set environment variables
os.Setenv("PORT", "")
os.Setenv("GO_ENV", "")
os.Setenv("GQL_COMPLEXITY", "")
os.Setenv("PG_HOST", "")
os.Setenv("PG_USER", "")
os.Setenv("PG_PASSWORD", "")
os.Setenv("PG_DBNAME", "")
os.Setenv("PG_PORT", "")
os.Setenv("PG_SSLMODE", "")

// Parse environment variables
err := env.Parse(&config.Cfg)
assert.NoError(t, err, "Config should parse without error")

// Verify default values
assert.Equal(t, 1323, config.Cfg.Port, "Default Port should be 1323")
assert.Equal(t, "dev", config.Cfg.GoEnv, "Default GoEnv should be 'dev'")
assert.Equal(t, 10, config.Cfg.GQLComplexity, "Default GQLComplexity should be 10")
assert.Equal(t, "localhost", config.Cfg.PGHost, "Default PGHost should be 'localhost'")
assert.Equal(t, "testuser", config.Cfg.PGUser, "Default PGUser should be 'testuser'")
assert.Equal(t, "testpassword", config.Cfg.PGPassword, "Default PGPassword should be 'testpassword'")
assert.Equal(t, "flamingodb", config.Cfg.PGDBName, "Default PGDBName should be 'flamingodb'")
assert.Equal(t, "5432", config.Cfg.PGPort, "Default PGPort should be '5432'")
assert.Equal(t, "allow", config.Cfg.PGSSLMode, "Default PGSSLMode should be 'allow'")
}

func TestConfigCustomValues(t *testing.T) {
// Set environment variables to custom values
os.Setenv("PORT", "8080")
os.Setenv("GO_ENV", "production")
os.Setenv("GQL_COMPLEXITY", "20")
os.Setenv("PG_HOST", "customhost")
os.Setenv("PG_USER", "customuser")
os.Setenv("PG_PASSWORD", "custompassword")
os.Setenv("PG_DBNAME", "customdb")
os.Setenv("PG_PORT", "6543")
os.Setenv("PG_SSLMODE", "require")

// Parse environment variables
err := env.Parse(&config.Cfg)
assert.NoError(t, err, "Config should parse without error")

// Verify custom values
assert.Equal(t, 8080, config.Cfg.Port, "Port should be 8080")
assert.Equal(t, "production", config.Cfg.GoEnv, "GoEnv should be 'production'")
assert.Equal(t, 20, config.Cfg.GQLComplexity, "GQLComplexity should be 20")
assert.Equal(t, "customhost", config.Cfg.PGHost, "PGHost should be 'customhost'")
assert.Equal(t, "customuser", config.Cfg.PGUser, "PGUser should be 'customuser'")
assert.Equal(t, "custompassword", config.Cfg.PGPassword, "PGPassword should be 'custompassword'")
assert.Equal(t, "customdb", config.Cfg.PGDBName, "PGDBName should be 'customdb'")
assert.Equal(t, "6543", config.Cfg.PGPort, "PGPort should be '6543'")
assert.Equal(t, "require", config.Cfg.PGSSLMode, "PGSSLMode should be 'require'")
}
1 change: 1 addition & 0 deletions frontend/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.13.1
5 changes: 4 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
"typescript": "^5.2.2",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"engines": {
"node": ">=20.13.1"
}
}
}
20 changes: 5 additions & 15 deletions render.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: "1"

services:
- type: web
Expand All @@ -11,20 +11,8 @@ services:
startCommand: ./main
healthCheckPath: /health
envVars:
- key: GQL_COMPLEXITY
sync: false
- key: PG_HOST
sync: false
- key: PG_USER
sync: false
- key: PG_PASSWORD
sync: false
- key: PG_DBNAME
sync: false
- key: PG_PORT
sync: false
- key: PG_SSLMODE
sync: false
- fromGroup: flamingo-armond


- type: web
name: flamingo-frontend
Expand All @@ -33,6 +21,8 @@ services:
rootDir: frontend
buildCommand: npm install -g pnpm && pnpm install && pnpm run build
staticPublishPath: frontend/build
envVars:
- fromGroup: flamingo-armond
buildFilter:
paths:
- src/**/*.tsx
Expand Down

0 comments on commit f125841

Please sign in to comment.