summaryrefslogtreecommitdiff
path: root/config/apt.go
blob: 34a0d4ac91b08ac485775820eb56639dcf574c0f (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
package config

import (
	"gerrit.wikimedia.org/r/blubber/build"
)

// AptConfig represents configuration pertaining to package installation from
// existing APT sources.
//
type AptConfig struct {
	Packages []string `yaml:"packages" validate:"dive,debianpackage"`
}

// Merge takes another AptConfig and combines the packages declared within
// with the packages of this AptConfig.
//
func (apt *AptConfig) Merge(apt2 AptConfig) {
	apt.Packages = append(apt.Packages, apt2.Packages...)
}

// InstructionsForPhase injects build instructions that will install the
// declared packages during the privileged phase.
//
// PhasePrivileged
//
// Updates the APT cache, installs configured packages, and cleans up.
//
func (apt AptConfig) InstructionsForPhase(phase build.Phase) []build.Instruction {
	if len(apt.Packages) > 0 {
		switch phase {
		case build.PhasePrivileged:
			return []build.Instruction{
				build.Env{map[string]string{
					"DEBIAN_FRONTEND": "noninteractive",
				}},
				build.RunAll{[]build.Run{
					{"apt-get update", []string{}},
					{"apt-get install -y", apt.Packages},
					{"rm -rf /var/lib/apt/lists/*", []string{}},
				}},
			}
		}
	}

	return []build.Instruction{}
}