2
0

shared.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package deploy
  2. import (
  3. "context"
  4. "fmt"
  5. api "github.com/porter-dev/porter/api/client"
  6. "github.com/porter-dev/porter/api/types"
  7. )
  8. // SharedOpts are common options for build, create, and deploy agents
  9. type SharedOpts struct {
  10. ProjectID uint
  11. ClusterID uint
  12. Namespace string
  13. LocalPath string
  14. LocalDockerfile string
  15. OverrideTag string
  16. Method DeployBuildType
  17. AdditionalEnv map[string]string
  18. EnvGroups []types.EnvGroupMeta
  19. UseCache bool
  20. }
  21. func coalesceEnvGroups(
  22. ctx context.Context,
  23. client api.Client,
  24. projectID, clusterID uint,
  25. namespace string,
  26. envGroups []types.EnvGroupMeta,
  27. config map[string]interface{},
  28. ) error {
  29. for _, group := range envGroups {
  30. if group.Name == "" {
  31. return fmt.Errorf("env group name cannot be empty")
  32. }
  33. envGroup, err := client.GetEnvGroup(
  34. ctx,
  35. projectID,
  36. clusterID,
  37. namespace,
  38. &types.GetEnvGroupRequest{
  39. Name: group.Name,
  40. Version: group.Version,
  41. },
  42. )
  43. if err != nil {
  44. return err
  45. }
  46. envConfig, err := GetNestedMap(config, "container", "env", "normal")
  47. if err != nil || envConfig == nil {
  48. envConfig = make(map[string]interface{})
  49. }
  50. for k, v := range envGroup.Variables {
  51. envConfig[k] = v
  52. }
  53. containerMap, _ := config["container"].(map[string]interface{})
  54. envMap, _ := containerMap["env"].(map[string]interface{})
  55. envMap["normal"] = envConfig
  56. }
  57. return nil
  58. }