Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symlink and libs artifact types #377

Merged
merged 3 commits into from
Sep 30, 2024
Merged
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
27 changes: 27 additions & 0 deletions artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@ type Artifacts struct {
Licenses map[string]ArtifactConfig `yaml:"licenses,omitempty" json:"licenses,omitempty"`
// Systemd is the list of systemd units and dropin files for the package
Systemd *SystemdConfiguration `yaml:"systemd,omitempty" json:"systemd,omitempty"`

// Libs is the list of library files to be installed.
// On linux this would typically be installed to /usr/lib/<package name>
Libs map[string]ArtifactConfig `yaml:"libs,omitempty" json:"libraries,omitempty"`

// Links is the list of symlinks to be installed with the package
// Links should only be used if the *package* should contain the link.
// For making a container compatible with another image, use [PostInstall] in
// the [ImageConfig].
Links []ArtifactSymlinkConfig `yaml:"links,omitempty" json:"links,omitempty"`

// TODO: other types of artifacts (libexec, etc)
}

type ArtifactSymlinkConfig struct {
// Source is the path that is being linked to
// Example:
// If you want a symlink in /usr/bin/foo that is linking to /usr/bin/foo/foo
// then the `Source` is `/usr/bin/foo/foo`
Source string `yaml:"source,omitempty" json:"source,omitempty"`
// Dest is the path where the symlink will be installed
Dest string `yaml:"dest,omitempty" json:"dest,omitempty"`
}

// CreateArtifactDirectories describes various directories that should be created on install.
// CreateArtifactDirectories represents different directory paths that are common to RPM systems.
type CreateArtifactDirectories struct {
Expand Down Expand Up @@ -108,5 +129,11 @@ func (a *Artifacts) IsEmpty() bool {
if len(a.Licenses) > 0 {
return false
}
if len(a.Libs) > 0 {
return false
}
if len(a.Links) > 0 {
return false
}
return true
}
28 changes: 28 additions & 0 deletions docs/spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@
"type": "object",
"description": "ArtifactDirConfig contains information about the directory to be created"
},
"ArtifactSymlinkConfig": {
"properties": {
"source": {
"type": "string",
"description": "Source is the path that is being linked to\nExample:\n If you want a symlink in /usr/bin/foo that is linking to /usr/bin/foo/foo\n then the `Source` is `/usr/bin/foo/foo`"
},
"dest": {
"type": "string",
"description": "Dest is the path where the symlink will be installed"
}
},
"additionalProperties": false,
"type": "object"
},
"Artifacts": {
"properties": {
"binaries": {
Expand Down Expand Up @@ -104,6 +118,20 @@
"systemd": {
"$ref": "#/$defs/SystemdConfiguration",
"description": "Systemd is the list of systemd units and dropin files for the package"
},
"libraries": {
"additionalProperties": {
"$ref": "#/$defs/ArtifactConfig"
},
"type": "object",
"description": "Libs is the list of library files to be installed.\nOn linux this would typically be installed to /usr/lib/\u003cpackage name\u003e"
},
"links": {
"items": {
"$ref": "#/$defs/ArtifactSymlinkConfig"
},
"type": "array",
"description": "Links is the list of symlinks to be installed with the package\nLinks should only be used if the *package* should contain the link.\nFor making a container compatible with another image, use [PostInstall] in\nthe [ImageConfig]."
}
},
"additionalProperties": false,
Expand Down
21 changes: 21 additions & 0 deletions frontend/deb/debroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ func Debroot(sOpt dalec.SourceOpts, spec *dalec.Spec, worker, in llb.State, targ
states = append(states, pls...)
}

if len(spec.Artifacts.Links) > 0 {
buf := bytes.NewBuffer(nil)
for _, l := range spec.Artifacts.Links {
src := strings.TrimPrefix(l.Source, "/")
dst := strings.TrimPrefix(l.Dest, "/")
fmt.Fprintln(buf, src, dst)
}

states = append(states, dalecDir.File(llb.Mkfile(filepath.Join(dir, spec.Name+".links"), 0o644, buf.Bytes()), opts...))
}

return dalec.MergeAtPath(in, states, "/"), nil
}

Expand Down Expand Up @@ -431,6 +442,16 @@ func createInstallScripts(worker llb.State, spec *dalec.Spec, dir string) []llb.
}
}

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

writeInstall(key, filepath.Join("/usr/lib", spec.Name, cfg.SubPath), resolved)
}
}

if installBuf.Len() > 0 {
states = append(states, base.File(llb.Mkfile(filepath.Join(dir, spec.Name+".install"), 0o700, installBuf.Bytes())))
}
Expand Down
26 changes: 24 additions & 2 deletions frontend/rpm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,18 @@ func (w *specWrapper) Install() fmt.Stringer {
copyArtifact(root, l, &cfg)
}

libs := dalec.SortMapKeys(w.Spec.Artifacts.Libs)
for _, l := range libs {
cfg := w.Spec.Artifacts.Libs[l]
root := filepath.Join(`%{buildroot}/%{_libdir}`, w.Name)
copyArtifact(root, l, &cfg)
}

for _, l := range w.Spec.Artifacts.Links {
fmt.Fprintln(b, "mkdir -p", filepath.Dir(filepath.Join("%{buildroot}", l.Dest)))
fmt.Fprintln(b, "ln -sf", l.Source, "%{buildroot}/"+l.Dest)
}

b.WriteString("\n")
return b
}
Expand Down Expand Up @@ -632,15 +644,14 @@ func (w *specWrapper) Files() fmt.Stringer {
fmt.Fprintln(b, file)
}
}

}

docKeys := dalec.SortMapKeys(w.Spec.Artifacts.Docs)
for _, d := range docKeys {
cfg := w.Spec.Artifacts.Docs[d]
path := filepath.Join(`%{_docdir}`, w.Name, cfg.SubPath, cfg.ResolveName(d))
fullDirective := strings.Join([]string{`%doc`, path}, " ")
fmt.Fprintln(b, fullDirective)

}

licenseKeys := dalec.SortMapKeys(w.Spec.Artifacts.Licenses)
Expand All @@ -651,6 +662,17 @@ func (w *specWrapper) Files() fmt.Stringer {
fmt.Fprintln(b, fullDirective)
}

libKeys := dalec.SortMapKeys(w.Spec.Artifacts.Libs)
for _, l := range libKeys {
cfg := w.Spec.Artifacts.Libs[l]
path := filepath.Join(`%{_libdir}`, w.Name, cfg.SubPath, cfg.ResolveName(l))
fmt.Fprintln(b, path)
}

for _, l := range w.Spec.Artifacts.Links {
fmt.Fprintln(b, l.Dest)
}

b.WriteString("\n")
return b
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ require (

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.11.5 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 h1:59MxjQVfjXsBpLy+dbd2/ELV5ofnUkUZBvWSC85sheA=
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0/go.mod h1:OahwfttHWG6eJ0clwcfBAHoDI6X/LV/15hx/wlMZSrU=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Microsoft/hcsshim v0.11.5 h1:haEcLNpj9Ka1gd3B3tAEs9CpE0c+1IhoL59w/exYU38=
Expand Down
Loading