Skip to content

Commit

Permalink
Use mounted directories and remove node modules instead of using `Dir…
Browse files Browse the repository at this point in the history
…ectory` (#350)
  • Loading branch information
kminehart authored Aug 14, 2024
1 parent 2feefe9 commit fb62b43
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
8 changes: 2 additions & 6 deletions artifacts/package_targz.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,10 @@ func (t *Tarball) BuildFile(ctx context.Context, b *dagger.Container, opts *pipe
targz.NewMappedDir("packaging/docker", grafanaDir.Directory("packaging/docker")),
targz.NewMappedDir("packaging/wrappers", grafanaDir.Directory("packaging/wrappers")),
targz.NewMappedDir("bin", backendDir),
targz.NewMappedDir("public", frontendDir, dagger.ContainerWithDirectoryOpts{
Exclude: []string{"node_modules", "*/node_modules", "**/*/node_modules"},
}),
targz.NewMappedDir("public", frontendDir),
targz.NewMappedDir("npm-artifacts", npmDir),
targz.NewMappedDir("storybook", storybookDir),
targz.NewMappedDir("plugins-bundled", pluginsDir, dagger.ContainerWithDirectoryOpts{
Exclude: []string{"node_modules", "*/node_modules", "**/*/node_modules"},
}),
targz.NewMappedDir("plugins-bundled", pluginsDir),
}

root := fmt.Sprintf("grafana-%s", version)
Expand Down
2 changes: 2 additions & 0 deletions frontend/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
func Build(builder *dagger.Container) *dagger.Directory {
public := builder.
WithExec([]string{"yarn", "run", "build"}).
WithExec([]string{"/bin/sh", "-c", "find /src/public -type d -name node_modules -print0 | xargs -0 rm -rf"}).
Directory("/src/public")

return public
Expand All @@ -16,6 +17,7 @@ func BuildPlugins(builder *dagger.Container) *dagger.Directory {
public := builder.
WithExec([]string{"yarn", "install", "--immutable"}).
WithExec([]string{"yarn", "run", "plugins:build-bundled"}).
WithExec([]string{"/bin/sh", "-c", "find /src/plugins-bundled -type d -name node_modules -print0 | xargs -0 rm -rf"}).
Directory("/src/plugins-bundled")

return public
Expand Down
7 changes: 3 additions & 4 deletions targz/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import (
"dagger.io/dagger"
)

func NewMappedDir(path string, directory *dagger.Directory, opts ...dagger.ContainerWithDirectoryOpts) MappedDirectory {
return MappedDirectory{path: path, directory: directory, opts: opts}
func NewMappedDir(path string, directory *dagger.Directory) MappedDirectory {
return MappedDirectory{path: path, directory: directory}
}

type MappedDirectory struct {
path string
directory *dagger.Directory
opts []dagger.ContainerWithDirectoryOpts
}

type MappedFile struct {
Expand Down Expand Up @@ -52,7 +51,7 @@ func Build(packager *dagger.Container, opts *Opts) *dagger.File {

for _, v := range opts.Directories {
path := path.Join(root, v.path)
packager = packager.WithDirectory(path, v.directory, v.opts...)
packager = packager.WithMountedDirectory(path, v.directory)
paths = append(paths, path)
}

Expand Down

0 comments on commit fb62b43

Please sign in to comment.