summaryrefslogtreecommitdiff
path: root/config/lives.go
blob: 665a73460b2ee6815f6beb1c16add5d4c20398a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package config

import (
	"phabricator.wikimedia.org/source/blubber/build"
)

// LocalLibPrefix declares the shared directory into which application level
// dependencies will be installed.
//
const LocalLibPrefix = "/opt/lib"

// LivesConfig holds configuration fields related to the livesship of
// installed dependencies and application files.
//
type LivesConfig struct {
	In         string `yaml:"in" validate:"omitempty,abspath"` // application directory
	UserConfig `yaml:",inline"`
}

// Merge takes another LivesConfig and overwrites this struct's fields.
//
func (lives *LivesConfig) Merge(lives2 LivesConfig) {
	if lives2.In != "" {
		lives.In = lives2.In
	}

	lives.UserConfig.Merge(lives2.UserConfig)
}

// InstructionsForPhase injects build instructions related to creation of the
// application lives.
//
// PhasePrivileged
//
// Creates LocalLibPrefix directory and application lives's user home
// directory, creates the lives user and its group, and sets up directory
// permissions.
//
func (lives LivesConfig) InstructionsForPhase(phase build.Phase) []build.Instruction {
	switch phase {
	case build.PhasePrivileged:
		return []build.Instruction{build.RunAll{
			append(
				build.CreateUser(lives.As, lives.UID, lives.GID),
				build.CreateDirectory(lives.In),
				build.Chown(lives.UID, lives.GID, lives.In),
				build.CreateDirectory(LocalLibPrefix),
				build.Chown(lives.UID, lives.GID, LocalLibPrefix),
			),
		}}
	case build.PhasePrivilegeDropped:
		return []build.Instruction{
			build.WorkingDirectory{lives.In},
		}
	}

	return []build.Instruction{}
}