Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Artifacts struct {
ConfigFiles map[string]ArtifactConfig `yaml:"configFiles,omitempty" json:"configFiles,omitempty"`
// Docs is a list of doc files included in the package
Docs map[string]ArtifactConfig `yaml:"docs,omitempty" json:"docs,omitempty"`
// InfoFiles is a list of info files included in the package
InfoFiles map[string]ArtifactConfig `yaml:"infoFiles,omitempty" json:"infoFiles,omitempty"`
// Licenses is a list of doc files included in the package
Licenses map[string]ArtifactConfig `yaml:"licenses,omitempty" json:"licenses,omitempty"`
// Systemd is the list of systemd units and dropin files for the package
Expand Down Expand Up @@ -123,15 +125,16 @@ func (a *Artifacts) IsEmpty() bool {
if len(a.ConfigFiles) > 0 {
return false
}

if a.Systemd != nil &&
(len(a.Systemd.Units) > 0 || len(a.Systemd.Dropins) > 0) {
return false
}

if len(a.Docs) > 0 {
return false
}
if len(a.InfoFiles) > 0 {
return false
}
if len(a.Licenses) > 0 {
return false
}
Expand Down
7 changes: 7 additions & 0 deletions docs/spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@
"type": "object",
"description": "Docs is a list of doc files included in the package"
},
"infoFiles": {
"additionalProperties": {
"$ref": "#/$defs/ArtifactConfig"
},
"type": "object",
"description": "InfoFiles is a list of info files included in the package"
},
"licenses": {
"additionalProperties": {
"$ref": "#/$defs/ArtifactConfig"
Expand Down
9 changes: 9 additions & 0 deletions frontend/deb/debroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,15 @@ func createInstallScripts(worker llb.State, spec *dalec.Spec, dir string) []llb.
}
}

if len(spec.Artifacts.InfoFiles) > 0 {
sorted := dalec.SortMapKeys(spec.Artifacts.InfoFiles)
for _, key := range sorted {
cfg := spec.Artifacts.InfoFiles[key]
resolved := cfg.ResolveName(key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that in some cases (e.g. docs, licenses) we do this check:

if resolved != key || cfg.SubPath != ""

Can you help me understand the reason for that check and why it's not needed here?

writeInstall(key, filepath.Join("/usr/share/info", cfg.SubPath), resolved)
}
}

if len(spec.Artifacts.Libexec) > 0 {
sorted := dalec.SortMapKeys(spec.Artifacts.Libexec)
for _, key := range sorted {
Expand Down
17 changes: 17 additions & 0 deletions frontend/rpm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,14 @@ func (w *specWrapper) Install() fmt.Stringer {
}
}

if w.Spec.Artifacts.InfoFiles != nil {
infoFileKeys := dalec.SortMapKeys(w.Spec.Artifacts.InfoFiles)
for _, k := range infoFileKeys {
f := w.Spec.Artifacts.InfoFiles[k]
copyArtifact(`%{buildroot}/%{_infodir}`, k, &f)
}
}

if w.Spec.Artifacts.Libexec != nil {
libexecFileKeys := dalec.SortMapKeys(w.Spec.Artifacts.Libexec)
for _, k := range libexecFileKeys {
Expand Down Expand Up @@ -607,6 +615,15 @@ func (w *specWrapper) Files() fmt.Stringer {
}
}

if w.Spec.Artifacts.InfoFiles != nil {
infoFileKeys := dalec.SortMapKeys(w.Spec.Artifacts.InfoFiles)
for _, k := range infoFileKeys {
f := w.Spec.Artifacts.DataDirs[k]
fullPath := filepath.Join(`%{_infodir}`, f.SubPath, f.ResolveName(k))
fmt.Fprintln(b, fullPath)
}
}

if w.Spec.Artifacts.Libexec != nil {
dataKeys := dalec.SortMapKeys(w.Spec.Artifacts.Libexec)
for _, k := range dataKeys {
Expand Down
98 changes: 98 additions & 0 deletions test/azlinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,104 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot
})
})

t.Run("test info file installation", func(t *testing.T) {
t.Parallel()
spec := &dalec.Spec{
Name: "infofiles-test",
Version: "0.0.1",
Revision: "1",
License: "MIT",
Website: "https://github.com/azure/dalec",
Vendor: "Dalec",
Packager: "Dalec",
Description: "Should install specified info files",
Sources: map[string]dalec.Source{
"no_name_no_subpath": {
Inline: &dalec.SourceInline{
File: &dalec.SourceInlineFile{
Contents: "#!/usr/bin/env bash\necho hello world",
Permissions: 0o755,
},
},
},
"name_only": {
Inline: &dalec.SourceInline{
File: &dalec.SourceInlineFile{
Contents: "#!/usr/bin/env bash\necho hello world",
Permissions: 0o755,
},
},
},
"name_and_subpath": {
Inline: &dalec.SourceInline{
File: &dalec.SourceInlineFile{
Contents: "#!/usr/bin/env bash\necho hello world",
Permissions: 0o755,
},
},
},
"subpath_only": {
Inline: &dalec.SourceInline{
File: &dalec.SourceInlineFile{
Contents: "#!/usr/bin/env bash\necho hello world",
Permissions: 0o755,
},
},
},
"nested_subpath": {
Inline: &dalec.SourceInline{
File: &dalec.SourceInlineFile{
Contents: "#!/usr/bin/env bash\necho hello world",
Permissions: 0o755,
},
},
},
},
Artifacts: dalec.Artifacts{
InfoFiles: map[string]dalec.ArtifactConfig{
"no_name_no_subpath": {},
"name_only": {
Name: "this_is_the_name_only",
},
"subpath_only": {
SubPath: "custom",
},
"name_and_subpath": {
SubPath: "subpath",
Name: "custom_name",
},
"nested_subpath": {
SubPath: "info-test/abcdefg",
},
},
},
}

testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
res := solveT(ctx, t, client, req)
ref, err := res.SingleRef()
if err != nil {
t.Fatal(err)
}
if err := validatePathAndPermissions(ctx, ref, "/usr/share/info/no_name_no_subpath", 0o755); err != nil {
t.Fatal(err)
}
if err := validatePathAndPermissions(ctx, ref, "/usr/share/info/this_is_the_name_only", 0o755); err != nil {
t.Fatal(err)
}
if err := validatePathAndPermissions(ctx, ref, "/usr/share/info/subpath/custom_name", 0o755); err != nil {
t.Fatal(err)
}
if err := validatePathAndPermissions(ctx, ref, "/usr/share/info/custom/subpath_only", 0o755); err != nil {
t.Fatal(err)
}
if err := validatePathAndPermissions(ctx, ref, "/usr/share/info/info-test/abcdefg/nested_subpath", 0o755); err != nil {
t.Fatal(err)
}
})
})

t.Run("test config files handled", func(t *testing.T) {
t.Parallel()
spec := &dalec.Spec{
Expand Down
Loading