Skip to content

Commit

Permalink
Switch to use ArtifactConfig and update comments
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Rickard <jrickard@microsoft.com>
  • Loading branch information
jeremyrickard authored and cpuguy83 committed May 14, 2024
1 parent 945bc9e commit 1df475d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 42 deletions.
24 changes: 3 additions & 21 deletions docs/spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,6 @@
"type": "object",
"description": "ArtifactConfig is the configuration for a given artifact type."
},
"ArtifactConfigFileConfig": {
"properties": {
"subpath": {
"type": "string",
"description": "Subpath is the subpath to use in the package for the artifact type.\n\nAs an example, binaries are typically placed in /usr/bin when installed.\nIf you want to nest them in a subdirectory, you can specify it here."
},
"name": {
"type": "string",
"description": "Name is file or dir name to use for the artifact in the package.\nIf empty, the file or dir name from the produced artifact will be used."
},
"replace": {
"type": "boolean"
}
},
"additionalProperties": false,
"type": "object",
"description": "ArtifactConfigFileConfig is the configuration give for Artifact Config Files."
},
"ArtifactDirConfig": {
"properties": {
"mode": {
Expand Down Expand Up @@ -89,14 +71,14 @@
},
"createDirectories": {
"$ref": "#/$defs/CreateArtifactDirectories",
"description": "Directories is a list of various directories that should be created by the RPM."
"description": "Directories is a list of various directories that should be created by the package."
},
"configFiles": {
"additionalProperties": {
"$ref": "#/$defs/ArtifactConfigFileConfig"
"$ref": "#/$defs/ArtifactConfig"
},
"type": "object",
"description": "ConfigFiles is a list of files that should be marked as config files in the RPM."
"description": "ConfigFiles is a list of files that should be marked as config files in the package."
}
},
"additionalProperties": false,
Expand Down
8 changes: 2 additions & 6 deletions frontend/rpm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (w *specWrapper) Install() fmt.Stringer {
configKeys := dalec.SortMapKeys(w.Spec.Artifacts.ConfigFiles)
for _, c := range configKeys {
cfg := w.Spec.Artifacts.ConfigFiles[c]
copyArtifact(`%{buildroot}/%{_sysconfdir}`, c, cfg.ArtifactConfig)
copyArtifact(`%{buildroot}/%{_sysconfdir}`, c, cfg)
}
return b
}
Expand Down Expand Up @@ -394,12 +394,8 @@ func (w *specWrapper) Files() fmt.Stringer {
configKeys := dalec.SortMapKeys(w.Spec.Artifacts.ConfigFiles)
for _, c := range configKeys {
cfg := w.Spec.Artifacts.ConfigFiles[c]
directive := `%config%`
if !cfg.ReplaceOnUpdate {
directive = `%config(noreplace)`
}
fullPath := filepath.Join(`%{_sysconfdir}`, cfg.SubPath, filepath.Base(c))
fullDirective := strings.Join([]string{directive, fullPath}, " ")
fullDirective := strings.Join([]string{`%config(noreplace)`, fullPath}, " ")
fmt.Fprintln(b, fullDirective)
}

Expand Down
13 changes: 3 additions & 10 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ type Artifacts struct {
Binaries map[string]ArtifactConfig `yaml:"binaries,omitempty" json:"binaries,omitempty"`
// Manpages is the list of manpages to include in the package.
Manpages map[string]ArtifactConfig `yaml:"manpages,omitempty" json:"manpages,omitempty"`
// Directories is a list of various directories that should be created by the RPM.
// Directories is a list of various directories that should be created by the package.
Directories *CreateArtifactDirectories `yaml:"createDirectories,omitempty" json:"createDirectories,omitempty"`
// ConfigFiles is a list of files that should be marked as config files in the RPM.
ConfigFiles map[string]ArtifactConfigFileConfig `yaml:"configFiles,omitempty" json:"configFiles,omitempty"`
// ConfigFiles is a list of files that should be marked as config files in the package.
ConfigFiles map[string]ArtifactConfig `yaml:"configFiles,omitempty" json:"configFiles,omitempty"`
// TODO: other types of artifacts (systtemd units, libexec, etc)
}

Expand Down Expand Up @@ -163,13 +163,6 @@ type ArtifactConfig struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
}

// ArtifactConfigFileConfig is the configuration give for Artifact Config Files.
// This is used to customize the settings for a config entry in the resulting artifact.
type ArtifactConfigFileConfig struct {
ArtifactConfig
ReplaceOnUpdate bool `yaml:"replace,omitempty" json:"replace,omitempty"`
}

// IsEmpty is used to determine if there are any artifacts to include in the package.
func (a *Artifacts) IsEmpty() bool {
if len(a.Binaries) > 0 {
Expand Down
7 changes: 2 additions & 5 deletions test/mariner2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,10 @@ echo "$BAR" > bar.txt
},
Build: dalec.ArtifactBuild{},
Artifacts: dalec.Artifacts{
ConfigFiles: map[string]dalec.ArtifactConfigFileConfig{
ConfigFiles: map[string]dalec.ArtifactConfig{
"src1": {},
"src2": {
ArtifactConfig: dalec.ArtifactConfig{
SubPath: "sysconfig",
},
ReplaceOnUpdate: false,
SubPath: "sysconfig",
},
},
},
Expand Down

0 comments on commit 1df475d

Please sign in to comment.