Permit definition of environment vars on image file
Signed-off-by: Daniele Rondina <geaaru@sabayonlinux.org>
This commit is contained in:
parent
28e594456d
commit
d1e8bdc2d7
@ -197,7 +197,7 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// Setup the mounts and chroot into the rootfs
|
||||
exitChroot, err := shared.SetupChroot(c.sourceDir)
|
||||
exitChroot, err := shared.SetupChroot(c.sourceDir, c.definition.Environment)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to setup chroot: %s", err)
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ func (c *cmdLXC) run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
exitChroot, err := shared.SetupChroot(c.global.sourceDir)
|
||||
exitChroot, err := shared.SetupChroot(c.global.sourceDir,
|
||||
c.global.definition.Environment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -85,7 +85,8 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
exitChroot, err := shared.SetupChroot(c.global.sourceDir)
|
||||
exitChroot, err := shared.SetupChroot(c.global.sourceDir,
|
||||
c.global.definition.Environment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ func killChrootProcesses(rootfs string) error {
|
||||
}
|
||||
|
||||
// SetupChroot sets up mount and files, a reverter and then chroots for you
|
||||
func SetupChroot(rootfs string) (func() error, error) {
|
||||
func SetupChroot(rootfs string, envs DefinitionEnv) (func() error, error) {
|
||||
// Mount the rootfs
|
||||
err := syscall.Mount(rootfs, rootfs, "", syscall.MS_BIND, "")
|
||||
if err != nil {
|
||||
@ -199,23 +199,44 @@ func SetupChroot(rootfs string) (func() error, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
env := Environment{
|
||||
"PATH": EnvVariable{
|
||||
Value: "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin",
|
||||
Set: true,
|
||||
},
|
||||
"SHELL": EnvVariable{
|
||||
Value: "/bin/sh",
|
||||
Set: true,
|
||||
},
|
||||
"TERM": EnvVariable{
|
||||
Value: "xterm",
|
||||
Set: true,
|
||||
},
|
||||
"DEBIAN_FRONTEND": EnvVariable{
|
||||
Value: "noninteractive",
|
||||
Set: true,
|
||||
},
|
||||
var env Environment
|
||||
|
||||
if envs.ClearDefaults {
|
||||
env = Environment{}
|
||||
} else {
|
||||
env = Environment{
|
||||
"PATH": EnvVariable{
|
||||
Value: "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin",
|
||||
Set: true,
|
||||
},
|
||||
"SHELL": EnvVariable{
|
||||
Value: "/bin/sh",
|
||||
Set: true,
|
||||
},
|
||||
"TERM": EnvVariable{
|
||||
Value: "xterm",
|
||||
Set: true,
|
||||
},
|
||||
"DEBIAN_FRONTEND": EnvVariable{
|
||||
Value: "noninteractive",
|
||||
Set: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if envs.EnvVariables != nil && len(envs.EnvVariables) > 0 {
|
||||
for _, e := range envs.EnvVariables {
|
||||
entry, ok := env[e.Key]
|
||||
if ok {
|
||||
entry.Value = e.Value
|
||||
entry.Set = true
|
||||
} else {
|
||||
env[e.Key] = EnvVariable{
|
||||
Value: e.Value,
|
||||
Set: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set environment variables
|
||||
|
@ -110,15 +110,28 @@ type DefinitionMappings struct {
|
||||
ArchitectureMap string `yaml:"architecture_map,omitempty"`
|
||||
}
|
||||
|
||||
// DefinitionEnvVars defines custom environment variables.
|
||||
type DefinitionEnvVars struct {
|
||||
Key string `yaml:"key"`
|
||||
Value string `yaml:"value"`
|
||||
}
|
||||
|
||||
// DefinitionEnv represents the config part of the environment section.
|
||||
type DefinitionEnv struct {
|
||||
ClearDefaults bool `yaml:"clear_defaults,omitempty"`
|
||||
EnvVariables []DefinitionEnvVars `yaml:"variables,omitempty"`
|
||||
}
|
||||
|
||||
// A Definition a definition.
|
||||
type Definition struct {
|
||||
Image DefinitionImage `yaml:"image"`
|
||||
Source DefinitionSource `yaml:"source"`
|
||||
Targets DefinitionTarget `yaml:"targets,omitempty"`
|
||||
Files []DefinitionFile `yaml:"files,omitempty"`
|
||||
Packages DefinitionPackages `yaml:"packages,omitempty"`
|
||||
Actions []DefinitionAction `yaml:"actions,omitempty"`
|
||||
Mappings DefinitionMappings `yaml:"mappings,omitempty"`
|
||||
Image DefinitionImage `yaml:"image"`
|
||||
Source DefinitionSource `yaml:"source"`
|
||||
Targets DefinitionTarget `yaml:"targets,omitempty"`
|
||||
Files []DefinitionFile `yaml:"files,omitempty"`
|
||||
Packages DefinitionPackages `yaml:"packages,omitempty"`
|
||||
Actions []DefinitionAction `yaml:"actions,omitempty"`
|
||||
Mappings DefinitionMappings `yaml:"mappings,omitempty"`
|
||||
Environment DefinitionEnv `yaml:"environment,omitempty"`
|
||||
}
|
||||
|
||||
// SetValue writes the provided value to a field represented by the yaml tag 'key'.
|
||||
|
@ -96,7 +96,7 @@ func (s *AlpineLinuxHTTP) Run(definition shared.Definition, rootfsDir string) er
|
||||
// Handle edge builds
|
||||
if definition.Image.Release == "edge" {
|
||||
// Upgrade to edge
|
||||
exitChroot, err := shared.SetupChroot(rootfsDir)
|
||||
exitChroot, err := shared.SetupChroot(rootfsDir, definition.Environment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user