app.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package stack
  2. import (
  3. "fmt"
  4. "github.com/mitchellh/mapstructure"
  5. "github.com/porter-dev/porter/cli/cmd/deploy"
  6. "github.com/porter-dev/porter/internal/integrations/preview"
  7. "github.com/porter-dev/porter/internal/templater/utils"
  8. "github.com/porter-dev/switchboard/pkg/types"
  9. )
  10. func (a *App) GetType() string {
  11. return *a.Type
  12. }
  13. func (a *App) GetDefaultValues() map[string]interface{} {
  14. var defaultValues map[string]interface{}
  15. if *a.Type == "web" {
  16. defaultValues = map[string]interface{}{
  17. "ingress": map[string]interface{}{
  18. "enabled": false,
  19. },
  20. "container": map[string]interface{}{
  21. "command": *a.Run,
  22. "env": map[string]interface{}{},
  23. },
  24. }
  25. } else {
  26. defaultValues = map[string]interface{}{
  27. "container": map[string]interface{}{
  28. "command": *a.Run,
  29. "env": map[string]interface{}{},
  30. },
  31. }
  32. }
  33. return defaultValues
  34. }
  35. func (a *App) getV1Resource(name string, b *Build, env map[string]string) (*types.Resource, error) {
  36. config := &preview.ApplicationConfig{}
  37. if a.Config == nil {
  38. a.Config = make(map[string]interface{})
  39. }
  40. config.Build.Method = "registry"
  41. config.Build.Image = fmt.Sprintf("{ .%s.image }", b.GetName())
  42. config.Build.Env = CopyEnv(env)
  43. defaultValues := a.GetDefaultValues()
  44. containerDefaultValues, err := deploy.GetNestedMap(defaultValues, "container", "env")
  45. if err != nil {
  46. return nil, err
  47. }
  48. containerDefaultValues["normal"] = CopyEnv(env)
  49. config.Values = utils.CoalesceValues(defaultValues, a.Config)
  50. rawConfig := make(map[string]any)
  51. err = mapstructure.Decode(config, &rawConfig)
  52. if err != nil {
  53. return nil, err
  54. }
  55. return &types.Resource{
  56. Name: name,
  57. DependsOn: []string{"get-env", b.GetName()},
  58. Source: map[string]any{
  59. "name": a.GetType(),
  60. },
  61. Config: rawConfig,
  62. Driver: "",
  63. }, nil
  64. }