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.

58 lines
1.5 KiB

  1. package config
  2. import (
  3. "gerrit.wikimedia.org/r/blubber/build"
  4. )
  5. // LocalLibPrefix declares the shared directory into which application level
  6. // dependencies will be installed.
  7. //
  8. const LocalLibPrefix = "/opt/lib"
  9. // LivesConfig holds configuration fields related to the livesship of
  10. // installed dependencies and application files.
  11. //
  12. type LivesConfig struct {
  13. In string `json:"in" validate:"omitempty,abspath"` // application directory
  14. UserConfig `json:",inline"`
  15. }
  16. // Merge takes another LivesConfig and overwrites this struct's fields.
  17. //
  18. func (lives *LivesConfig) Merge(lives2 LivesConfig) {
  19. if lives2.In != "" {
  20. lives.In = lives2.In
  21. }
  22. lives.UserConfig.Merge(lives2.UserConfig)
  23. }
  24. // InstructionsForPhase injects build instructions related to creation of the
  25. // application lives.
  26. //
  27. // PhasePrivileged
  28. //
  29. // Creates LocalLibPrefix directory and application lives's user home
  30. // directory, creates the lives user and its group, and sets up directory
  31. // permissions.
  32. //
  33. func (lives LivesConfig) InstructionsForPhase(phase build.Phase) []build.Instruction {
  34. switch phase {
  35. case build.PhasePrivileged:
  36. return []build.Instruction{build.RunAll{
  37. append(
  38. build.CreateUser(lives.As, lives.UID, lives.GID),
  39. build.CreateDirectory(lives.In),
  40. build.Chown(lives.UID, lives.GID, lives.In),
  41. build.CreateDirectory(LocalLibPrefix),
  42. build.Chown(lives.UID, lives.GID, LocalLibPrefix),
  43. ),
  44. }}
  45. case build.PhasePrivilegeDropped:
  46. return []build.Instruction{
  47. build.WorkingDirectory{lives.In},
  48. }
  49. }
  50. return []build.Instruction{}
  51. }