You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

  1. package config
  2. import (
  3. "gerrit.wikimedia.org/r/blubber/build"
  4. )
  5. // CommonConfig holds the configuration fields common to both the root config
  6. // and each configured variant.
  7. //
  8. type CommonConfig struct {
  9. Base string `json:"base" validate:"omitempty,baseimage"` // name/path to base image
  10. Apt AptConfig `json:"apt"` // APT related
  11. Node NodeConfig `json:"node"` // Node related
  12. Python PythonConfig `json:"python"` // Python related
  13. Builder BuilderConfig `json:"builder"` // Builder related
  14. Lives LivesConfig `json:"lives"` // application owner/dir
  15. Runs RunsConfig `json:"runs"` // runtime environment
  16. EntryPoint []string `json:"entrypoint"` // entry-point executable
  17. }
  18. // Merge takes another CommonConfig and merges its fields this one's.
  19. //
  20. func (cc *CommonConfig) Merge(cc2 CommonConfig) {
  21. if cc2.Base != "" {
  22. cc.Base = cc2.Base
  23. }
  24. cc.Apt.Merge(cc2.Apt)
  25. cc.Node.Merge(cc2.Node)
  26. cc.Python.Merge(cc2.Python)
  27. cc.Builder.Merge(cc2.Builder)
  28. cc.Lives.Merge(cc2.Lives)
  29. cc.Runs.Merge(cc2.Runs)
  30. if cc2.EntryPoint != nil {
  31. cc.EntryPoint = cc2.EntryPoint
  32. }
  33. }
  34. // PhaseCompileableConfig returns all fields that implement
  35. // build.PhaseCompileable in the order that their instructions should be
  36. // injected.
  37. //
  38. func (cc *CommonConfig) PhaseCompileableConfig() []build.PhaseCompileable {
  39. return []build.PhaseCompileable{cc.Apt, cc.Node, cc.Python, cc.Builder, cc.Lives, cc.Runs}
  40. }
  41. // InstructionsForPhase injects instructions into the given build phase for
  42. // each member field that supports it.
  43. //
  44. func (cc *CommonConfig) InstructionsForPhase(phase build.Phase) []build.Instruction {
  45. instructions := []build.Instruction{}
  46. for _, phaseCompileable := range cc.PhaseCompileableConfig() {
  47. instructions = append(instructions, phaseCompileable.InstructionsForPhase(phase)...)
  48. }
  49. return instructions
  50. }