|
|
|
@ -7,9 +7,8 @@ import (
|
|
|
|
|
|
|
|
|
|
"git.wegmueller.it/opencloud/opencloud/sysacct" |
|
|
|
|
"git.wegmueller.it/opencloud/opencloud/zfs" |
|
|
|
|
"github.com/hashicorp/hcl2/gohcl" |
|
|
|
|
"github.com/hashicorp/hcl2/hcl" |
|
|
|
|
"github.com/hashicorp/hcl2/hclparse" |
|
|
|
|
hcl2 "github.com/hashicorp/hcl/v2" |
|
|
|
|
"github.com/hashicorp/hcl/v2/hclsimple" |
|
|
|
|
"github.com/ztrue/tracerr" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -25,7 +24,7 @@ const (
|
|
|
|
|
type ImageConfig struct { |
|
|
|
|
Maintainer *MaintainerInformation `hcl:"maintainer"` |
|
|
|
|
Images []Image `hcl:"image,block"` |
|
|
|
|
Body hcl.Body `hcl:",remain"` |
|
|
|
|
Body hcl2.Body `hcl:",remain"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *ImageConfig) PostDecode() { |
|
|
|
@ -74,35 +73,48 @@ func (c *ImageConfig) PostDecode() {
|
|
|
|
|
img.OSFlavour = runtime.GOOS |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if img.RunAsUser == "" { |
|
|
|
|
img.RunAsUser = "process" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if img.RunAsGroup == "" { |
|
|
|
|
img.RunAsGroup = "process" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if img.Milestone == "" { |
|
|
|
|
img.Milestone = "svc:/milestone/multi-user" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c.Images[idx] = img |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Image struct { |
|
|
|
|
Name string `hcl:"name,label"` |
|
|
|
|
BaseImage string `hcl:"base"` |
|
|
|
|
OSFlavour string `hcl:"os,optional"` |
|
|
|
|
Users []sysacct.User `hcl:"user,block"` |
|
|
|
|
Groups []sysacct.Group `hcl:"group,block"` |
|
|
|
|
Sources []SourceDescription `hcl:"source,block"` |
|
|
|
|
CopyOperations []CopyOperation `hcl:"copy,block"` |
|
|
|
|
Actions []Action `hcl:"action,block"` |
|
|
|
|
Maintainer *MaintainerInformation `hcl:"maintainer,optional"` |
|
|
|
|
Services []ServiceDescription `hcl:"service,block"` //TODO implement
|
|
|
|
|
Command *Command `hcl:"cmd,optional"` |
|
|
|
|
ExposedPorts []string `hcl:"expose,optional"` |
|
|
|
|
Environment map[string]string `hcl:"env,optional"` |
|
|
|
|
EntryPoint []string `hcl:"entrypoint,optional"` |
|
|
|
|
Volumes []VolumeConfig `hcl:"volume,block"` |
|
|
|
|
Hosts []HostEntry `hcl:"host,block"` |
|
|
|
|
Labels map[string]string `hcl:"labels,optional"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Command struct { |
|
|
|
|
Args []string `hcl:"cmd"` //Binary and arguments to run
|
|
|
|
|
User *sysacct.User `hcl:"user,optional"` //User to run the command as
|
|
|
|
|
WorkingDir string `hcl:"workdir,optional"` //Directory to chdir into before starting the process defaults to /
|
|
|
|
|
Milestone string `hcl:"milestone,optional"` //The milestone after which the process should start defaults to svc:/milestone/multi-user must be an fmri
|
|
|
|
|
Name string `hcl:"name,label"` |
|
|
|
|
BaseImage string `hcl:"base"` |
|
|
|
|
OSFlavour string `hcl:"os,optional"` |
|
|
|
|
Users []sysacct.User `hcl:"user,block"` |
|
|
|
|
Groups []sysacct.Group `hcl:"group,block"` |
|
|
|
|
Sources []SourceDescription `hcl:"source,block"` |
|
|
|
|
CopyOperations []CopyOperation `hcl:"copy,block"` |
|
|
|
|
Actions []Action `hcl:"action,block"` |
|
|
|
|
Maintainer *MaintainerInformation `hcl:"maintainer"` |
|
|
|
|
Services []ServiceDescription `hcl:"service,block"` //TODO implement
|
|
|
|
|
Command []string `hcl:"cmd,optional"` |
|
|
|
|
WorkingDirectory string `hcl:"workdir,optional"` |
|
|
|
|
Milestone string `hcl:"milestone,optional"` |
|
|
|
|
RunAsUser string `hcl:"runas,optional"` |
|
|
|
|
RunAsGroup string `hcl:"runas_user,optional"` |
|
|
|
|
RunAsUID uint32 `hcl:"runas_uid,optional"` |
|
|
|
|
RunAsGID uint32 `hcl:"runas_gid,optional"` |
|
|
|
|
RunAsAdditionalGroups []string `hcl:"runas_additional_groups,optional"` |
|
|
|
|
RunAsAdditionalGIDs []uint32 `hcl:"runas_additional_gids,optional"` |
|
|
|
|
ExposedPorts []string `hcl:"expose,optional"` |
|
|
|
|
Environment map[string]string `hcl:"env,optional"` |
|
|
|
|
EntryPoint []string `hcl:"entrypoint,optional"` |
|
|
|
|
Volumes []VolumeConfig `hcl:"volume,block"` |
|
|
|
|
Hosts []HostEntry `hcl:"host,block"` |
|
|
|
|
Labels map[string]string `hcl:"labels,optional"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type ServiceDescription struct { |
|
|
|
@ -159,19 +171,11 @@ type SourceDescription struct {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ReadConfigFile(path string) (*ImageConfig, error) { |
|
|
|
|
parser := hclparse.NewParser() |
|
|
|
|
f, diags := parser.ParseHCLFile(path) |
|
|
|
|
if diags != nil && diags.HasErrors() { |
|
|
|
|
return nil, tracerr.Wrap(diags) |
|
|
|
|
} |
|
|
|
|
return ReadConfig(f) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ReadConfig(blob *hcl.File) (*ImageConfig, error) { |
|
|
|
|
var img ImageConfig |
|
|
|
|
if diags := gohcl.DecodeBody(blob.Body, nil, &img); diags != nil && diags.HasErrors() { |
|
|
|
|
return nil, tracerr.Wrap(diags) |
|
|
|
|
if err := hclsimple.DecodeFile(path, nil, &img); err != nil { |
|
|
|
|
return nil, tracerr.Wrap(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
img.PostDecode() |
|
|
|
|
return &img, nil |
|
|
|
|
} |
|
|
|
|