Skip to content

Commit

Permalink
Embed package files to make builder go-installable (#163)
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 authored Feb 21, 2024
1 parent 9317bab commit 47e12e2
Show file tree
Hide file tree
Showing 164 changed files with 107 additions and 3,583 deletions.
87 changes: 87 additions & 0 deletions embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"embed"
"io/fs"
"path/filepath"

"dagger.io/dagger"
)

var (
//go:embed hack/cross
hackCrossFS embed.FS

//go:embed packages
packagesFS embed.FS
)

func packageDir(client *dagger.Client, name string) *dagger.Directory {
root := client.Directory()

dir, err := fs.Sub(packagesFS, filepath.Join("packages", name))
if err != nil {
panic(err)
}

err = fs.WalkDir(dir, ".", func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
info, err := entry.Info()
if err != nil {
return err
}

if entry.IsDir() {
root = root.WithNewDirectory(path, dagger.DirectoryWithNewDirectoryOpts{Permissions: int(info.Mode().Perm())})
return nil
}

dt, err := fs.ReadFile(dir, path)
if err != nil {
return err
}
root = root.WithNewFile(path, string(dt), dagger.DirectoryWithNewFileOpts{Permissions: int(info.Mode().Perm())})
return nil
})
if err != nil {
panic(err)
}
return root
}

func hackCrossDir(client *dagger.Client) *dagger.Directory {
root := client.Directory()

dir, err := fs.Sub(hackCrossFS, "hack/cross")
if err != nil {
panic(err)
}

err = fs.WalkDir(dir, ".", func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
info, err := entry.Info()
if err != nil {
return err
}

if entry.IsDir() {
root = root.WithNewDirectory(path, dagger.DirectoryWithNewDirectoryOpts{Permissions: int(info.Mode().Perm())})
return nil
}

dt, err := fs.ReadFile(dir, path)
if err != nil {
return err
}
root = root.WithNewFile(path, string(dt), dagger.DirectoryWithNewFileOpts{Permissions: int(info.Mode().Perm())})
return nil
})
if err != nil {
panic(err)
}
return root
}
2 changes: 1 addition & 1 deletion make.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ func do(ctx context.Context, client *dagger.Client, cfg *archive.Spec) (*dagger.
if err != nil {
return nil, err
}
out := target.Make(cfg)
out := target.Make(cfg, packageDir(client, cfg.Pkg), hackCrossDir(client))
return out, nil
}
54 changes: 0 additions & 54 deletions moby-engine/hack/README.md

This file was deleted.

21 changes: 0 additions & 21 deletions moby-engine/hack/buildkit-ref

This file was deleted.

4 changes: 0 additions & 4 deletions moby-engine/hack/cross/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions moby-engine/hack/cross/binfmt.sh

This file was deleted.

71 changes: 0 additions & 71 deletions moby-engine/hack/cross/c/cc.sh

This file was deleted.

36 changes: 0 additions & 36 deletions moby-engine/hack/cross/deb/target.sh

This file was deleted.

Loading

0 comments on commit 47e12e2

Please sign in to comment.