Debian Codegraph @

case_studies/micromanage/lib/mmlib/v0.1.2/cmd/apt.libsonnet

raw
1 local pip = import 'pip.libsonnet';
2
3 {
4 local libos = self,
5
6 // A mixin on top of an image or instance that allows high level installation of apt packages.
7 Mixin:: {
8 aptSourcesListDir:: '/etc/apt/sources.list.d',
9
10 aptKeyUrls:: [],
11 // { foo: "..." } will add a foo.list containing the given content.
12 aptRepoLines:: {},
13 // { foo: "..." } will add a foo.list fetched from the given URL.
14 aptRepoUrls:: {},
15
16 // Add the packages you want to install here.
17 aptPackages:: [],
18
19 local repoLineCommands = [
20 'echo "%s" > %s/%s.list' % [self.aptRepoLines[k], self.aptSourcesListDir, k]
21 for k in std.objectFields(self.aptRepoLines)
22 ],
23 local repoUrlCommands = [
24 'curl -o %s/%s.list %s' % [self.aptSourcesListDir, k, self.aptRepoUrls[k]]
25 for k in std.objectFields(self.aptRepoUrls)
26 ],
27 local keyCommands = ['curl --silent %s | apt-key add -' % [url] for url in self.aptKeyUrls],
28
29 local env = 'DEBIAN_FRONTEND=noninteractive',
30 local opts = '-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold',
31
32 local updateCommands = ['apt-get -qq -y update'],
33 local installCommands = [
34 '%s apt-get -qq -y %s install %s' % [env, opts, std.join(' ', self.aptPackages)],
35 ],
36
37 cmds+: repoLineCommands + repoUrlCommands + keyCommands
38 + updateCommands + installCommands,
39 },
40
41 // TODO: This would work better as an AptPipGlue mixin instead of extending Mixin.
42 // Similar to `Mixin` above but also installs pip if you have any pip packages.
43 PipMixin:: pip.Mixin {
44 aptPackages+: if std.length(self.pipPackages) == 0 then [] else ['python-pip'],
45 },
46 }