This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
/
build-packages.go
133 lines (113 loc) · 4.13 KB
/
build-packages.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package cmd
import (
"crypto/sha1"
"encoding/hex"
"os"
"path/filepath"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// buildPackagesCmd represents the packages command
var buildPackagesCmd = &cobra.Command{
Use: "packages",
Short: "Builds BOSH packages in a Docker container.",
Long: `
This command will compile all required packages in the BOSH releases referenced by
your role manifest. The command will create a compilation container named
` + "`<repository>-cbase-<FISSILE_VERSION>-<RELEASE_NAME>-<RELEASE_VERSION>-pkg-<PACKAGE_NAME>`" + `
for each package (e.g. ` + "`fissile-cbase-1.0.0-cf-217-pkg-nats`" + `).
All containers are removed, whether compilation is successful or not. However, if
the compilation is interrupted during compilation (e.g. sending SIGINT), containers
will most likely be left behind.
Compiled packages are stored in ` + "`<work-dir>/compilation`" + `. Fissile uses the
package's fingerprint as part of the directory structure. This means that if the
same package (with the same version) is used by multiple releases, it will only be
compiled once.
`,
RunE: func(cmd *cobra.Command, args []string) error {
flagBuildPackagesRoles := buildPackagesViper.GetString("roles")
flagBuildPackagesOnlyReleases := buildPackagesViper.GetString("only-releases")
flagBuildPackagesWithoutDocker := buildPackagesViper.GetBool("without-docker")
flagBuildPackagesDockerNetworkMode := buildPackagesViper.GetString("docker-network-mode")
flagBuildPackagesStemcell := buildPackagesViper.GetString("stemcell")
flagBuildCompilationCacheConfig := buildPackagesViper.GetString("compilation-cache-config")
flagBuildPackagesStreamPackages := buildPackagesViper.GetBool("stream-packages")
err := fissile.GraphBegin(buildViper.GetString("output-graph"))
if err != nil {
return err
}
err = fissile.LoadManifest()
if err != nil {
return err
}
hasher := sha1.New()
if _, err := hasher.Write([]byte(flagBuildPackagesStemcell)); err != nil {
return err
}
compilationDir := filepath.Join(fissile.CompilationDir(), hex.EncodeToString(hasher.Sum(nil)))
return fissile.Compile(
flagBuildPackagesStemcell,
compilationDir,
fissile.Options.RoleManifest,
fissile.Options.Metrics,
strings.FieldsFunc(flagBuildPackagesRoles, func(r rune) bool { return r == ',' }),
strings.FieldsFunc(flagBuildPackagesOnlyReleases, func(r rune) bool { return r == ',' }),
fissile.Options.Workers,
flagBuildPackagesDockerNetworkMode,
flagBuildPackagesWithoutDocker,
fissile.Options.Verbose,
flagBuildCompilationCacheConfig,
flagBuildPackagesStreamPackages,
)
},
}
var buildPackagesViper = viper.New()
func init() {
initViper(buildPackagesViper)
buildCmd.AddCommand(buildPackagesCmd)
// viper is busted w/ string slice, https://github.com/spf13/viper/issues/200
buildPackagesCmd.PersistentFlags().StringP(
"roles",
"",
"",
"Build only packages for the given instance group names; comma separated.",
)
buildPackagesCmd.PersistentFlags().StringP(
"only-releases",
"",
"",
"Build only packages for the given release names; comma separated.",
)
buildPackagesCmd.PersistentFlags().BoolP(
"without-docker",
"",
false,
"Build without docker; this may adversely affect your system. Only supported on Linux, and requires CAP_SYS_ADMIN.",
)
buildPackagesCmd.PersistentFlags().StringP(
"docker-network-mode",
"",
"",
"Specify network mode to be used when building with docker. e.g. \"--docker-network-mode host\" is equivalent to \"docker run --network=host\"",
)
buildPackagesCmd.PersistentFlags().StringP(
"stemcell",
"s",
"",
"The source stemcell",
)
buildPackagesCmd.PersistentFlags().StringP(
"compilation-cache-config",
"",
filepath.Join(os.Getenv("HOME"), ".fissile", "package-cache.yaml"),
"Points to a file containing configuration for a compiled package cache or contains the configuration as valid yaml",
)
buildPackagesCmd.PersistentFlags().BoolP(
"stream-packages",
"",
false,
"If true, fissile will stream packages to the docker daemon for compilation, instead of mounting volumes",
)
buildPackagesViper.BindPFlags(buildPackagesCmd.PersistentFlags())
}