Skip to content

Commit

Permalink
wip: create helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jul 2, 2024
1 parent e81d832 commit fcd0309
Show file tree
Hide file tree
Showing 22 changed files with 576 additions and 318 deletions.
8 changes: 4 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ archives:

dockers:
- image_templates: [
"ghcr.io/zeiss/{{ .ProjectName }}-accounts:{{ .Version }}-amd64"
"ghcr.io/zeiss/{{ .ProjectName }}/accounts:{{ .Version }}-amd64"
]
dockerfile: Dockerfile.accounts
use: buildx
Expand All @@ -69,7 +69,7 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0
- image_templates: [
"ghcr.io/zeiss/{{ .ProjectName }}-accounts:{{ .Version }}-arm64"
"ghcr.io/zeiss/{{ .ProjectName }}/accounts:{{ .Version }}-arm64"
]
dockerfile: Dockerfile.accounts
use: buildx
Expand All @@ -87,7 +87,7 @@ dockers:
- --label=org.opencontainers.image.licenses=Apache-2.0

- image_templates: [
"ghcr.io/zeiss/{{ .ProjectName }}-web:{{ .Version }}-amd64"
"ghcr.io/zeiss/{{ .ProjectName }}/web:{{ .Version }}-amd64"
]
dockerfile: Dockerfile.web
use: buildx
Expand All @@ -104,7 +104,7 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0
- image_templates: [
"ghcr.io/zeiss/{{ .ProjectName }}-web:{{ .Version }}-arm64"
"ghcr.io/zeiss/{{ .ProjectName }}/web:{{ .Version }}-arm64"
]
dockerfile: Dockerfile.web
use: buildx
Expand Down
50 changes: 50 additions & 0 deletions cmd/accounts/cmd/cfg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cmd

import (
"os"
)

var cfg = New()

// DB ...
type DB struct {
Addr string
Database string
Password string
Port int
Username string
Prefix string
}

// Flags contains the command line flags.
type Flags struct {
Addr string `envconfig:"TYPHOON_ACCOUNTS_ADDR" default:":8084"`
DatabaseURI string `envconfig:"TYPHOON_ACCOUNTS_DATABASE_URI" default:""`
DatabaseTablePrefix string `envconfig:"TYPHOON_ACCOUNTS_DATABASE_TABLE_PREFIX" default:"typhoon_"`
}

// NewFlags ...
func NewFlags() *Flags {
return &Flags{
Addr: ":8084",
DatabaseURI: "host=host.docker.internal user=example password=example dbname=example port=5432 sslmode=disable",
DatabaseTablePrefix: "typhoon_",
}
}

// New ...
func New() *Config {
return &Config{
Flags: NewFlags(),
}
}

// Config ...
type Config struct {
Flags *Flags
}

// Cwd returns the current working directory.
func (c *Config) Cwd() (string, error) {
return os.Getwd()
}
33 changes: 33 additions & 0 deletions cmd/accounts/cmd/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
seed "github.com/zeiss/gorm-seed"
"github.com/zeiss/typhoon/internal/accounts/adapters/database"

"github.com/spf13/cobra"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)

var Migrate = &cobra.Command{
Use: "migrate",
Short: "Migrate the database",
RunE: func(cmd *cobra.Command, args []string) error {
conn, err := gorm.Open(postgres.Open(cfg.Flags.DatabaseURI), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: cfg.Flags.DatabaseTablePrefix,
},
})
if err != nil {
return err
}

store, err := seed.NewDatabase(conn, database.NewReadTx(), database.NewWriteTx())
if err != nil {
return err
}

return store.Migrate(cmd.Context())
},
}
18 changes: 7 additions & 11 deletions cmd/accounts/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/zeiss/typhoon/internal/accounts/adapters/database"
"github.com/zeiss/typhoon/internal/accounts/adapters/handlers"
"github.com/zeiss/typhoon/internal/accounts/config"
"github.com/zeiss/typhoon/internal/accounts/controllers"
"github.com/zeiss/typhoon/internal/utils"
openapi "github.com/zeiss/typhoon/pkg/apis/accounts"
Expand All @@ -24,19 +23,16 @@ import (
)

func init() {
Root.PersistentFlags().StringVar(&config.Cfg.Flags.Addr, "addr", config.Cfg.Flags.Addr, "addr")
Root.PersistentFlags().StringVar(&config.Cfg.Flags.DB.Addr, "db-addr", config.Cfg.Flags.DB.Addr, "Database address")
Root.PersistentFlags().StringVar(&config.Cfg.Flags.DB.Database, "db-database", config.Cfg.Flags.DB.Database, "Database name")
Root.PersistentFlags().StringVar(&config.Cfg.Flags.DB.Username, "db-username", config.Cfg.Flags.DB.Username, "Database user")
Root.PersistentFlags().StringVar(&config.Cfg.Flags.DB.Password, "db-password", config.Cfg.Flags.DB.Password, "Database password")
Root.PersistentFlags().IntVar(&config.Cfg.Flags.DB.Port, "db-port", config.Cfg.Flags.DB.Port, "Database port")
Root.PersistentFlags().StringVar(&cfg.Flags.Addr, "addr", cfg.Flags.Addr, "addr")
Root.PersistentFlags().StringVar(&cfg.Flags.DatabaseURI, "db-uri", cfg.Flags.DatabaseURI, "Database URI")
Root.PersistentFlags().StringVar(&cfg.Flags.DatabaseTablePrefix, "db-table-prefix", cfg.Flags.DatabaseTablePrefix, "Database table prefix")

Root.SilenceUsage = true
}

var Root = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
srv := NewAccountsSrv(config.Cfg)
srv := NewAccountsSrv(cfg)

s, _ := server.WithContext(cmd.Context())
s.Listen(srv, false)
Expand All @@ -49,18 +45,18 @@ var _ server.Listener = (*AccountsSrv)(nil)

// AccountsSrv is the server that implements the Noop interface.
type AccountsSrv struct {
cfg *config.Config
cfg *Config
}

// NewAccountsSrv returns a new instance of NoopSrv.
func NewAccountsSrv(cfg *config.Config) *AccountsSrv {
func NewAccountsSrv(cfg *Config) *AccountsSrv {
return &AccountsSrv{cfg}
}

// Start starts the server.
func (s *AccountsSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.RunFunc) func() error {
return func() error {
conn, err := gorm.Open(postgres.Open(s.cfg.DSN()), &gorm.Config{
conn, err := gorm.Open(postgres.Open(s.cfg.Flags.DatabaseURI), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: "typhoon_",
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/api/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
)

var Migrate = &cobra.Command{
Use: "migrate",
Short: "Migrate the database",
RunE: func(cmd *cobra.Command, args []string) error {
conn, err := gorm.Open(postgres.Open(cfg.DSN()), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
Expand Down
172 changes: 0 additions & 172 deletions cmd/examples/main.go

This file was deleted.

7 changes: 2 additions & 5 deletions cmd/web/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.R
return err
}

gorm, err := adapter.New(conn)
if err != nil {
return err
}
ga := adapter.New(conn)

gothConfig := goth.Config{
Adapter: gorm,
Adapter: ga,
Secret: goth.GenerateKey(),
CookieHTTPOnly: true,
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/getkin/kin-openapi v0.125.0
github.com/go-playground/validator/v10 v10.22.0
github.com/gofiber/fiber/v2 v2.52.4
github.com/gofiber/fiber/v2 v2.52.5
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/mock v1.7.0-rc.1
github.com/golangci/golangci-lint v1.59.1
Expand All @@ -36,7 +36,7 @@ require (
github.com/wamuir/go-xslt v0.1.5
github.com/xdg-go/scram v1.0.2
github.com/zeiss/fiber-authz v1.0.31
github.com/zeiss/fiber-goth v1.2.5-0.20240627074038-6bbb515b112f
github.com/zeiss/fiber-goth v1.2.5
github.com/zeiss/fiber-htmx v1.3.18-0.20240628131553-334787f154e5
github.com/zeiss/gorm-seed v0.1.2
github.com/zeiss/snow-go v0.0.0-20240312201415-88f059622cff
Expand Down
Loading

0 comments on commit fcd0309

Please sign in to comment.