Vendoring improved
* update dagger init with package manager downloading stdlib Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * split mod get and update functions Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * write to package checksum to dagger.sum when installing/updating Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * encure checksums are valid when compiling input Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * remove references to github.com/tjovicic in docs 1010 and 1011 Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * refactor mod get command Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * update logic of moving dir when installing packages Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix linting errors Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * revert changes to 1010 docs Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * updating error log line in mod/get Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix ci tests when using vendoring Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * update alpha.dagger.io version to v0.1 Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix mod repo test Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * return error if package already installed Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * remove already installed packages when installing Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix issue when vendoring stdlib Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * update mod command with filelock while installing Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix linting errors Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> * fix path of mod lock file Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> Co-authored-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com> Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.dagger.io/dagger/mod"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.dagger.io/dagger/keychain"
|
||||
"go.dagger.io/dagger/stdlib"
|
||||
@@ -49,6 +51,7 @@ func Init(ctx context.Context, dir string) (*Project, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := os.Mkdir(path.Join(daggerRoot, envDir), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -342,35 +345,35 @@ func (w *Project) cleanPackageName(ctx context.Context, pkg string) (string, err
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func cueModInit(ctx context.Context, p string) error {
|
||||
func cueModInit(ctx context.Context, parentDir string) error {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
mod := path.Join(p, "cue.mod")
|
||||
if err := os.Mkdir(mod, 0755); err != nil {
|
||||
modDir := path.Join(parentDir, "cue.mod")
|
||||
if err := os.Mkdir(modDir, 0755); err != nil {
|
||||
if !errors.Is(err, os.ErrExist) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
modFile := path.Join(mod, "module.cue")
|
||||
modFile := path.Join(modDir, "module.cue")
|
||||
if _, err := os.Stat(modFile); err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
|
||||
lg.Debug().Str("mod", p).Msg("initializing cue.mod")
|
||||
lg.Debug().Str("mod", parentDir).Msg("initializing cue.mod")
|
||||
|
||||
if err := os.WriteFile(modFile, []byte("module: \"\"\n"), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Mkdir(path.Join(mod, "usr"), 0755); err != nil {
|
||||
if err := os.Mkdir(path.Join(modDir, "usr"), 0755); err != nil {
|
||||
if !errors.Is(err, os.ErrExist) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := os.Mkdir(path.Join(mod, "pkg"), 0755); err != nil {
|
||||
if err := os.Mkdir(path.Join(modDir, "pkg"), 0755); err != nil {
|
||||
if !errors.Is(err, os.ErrExist) {
|
||||
return err
|
||||
}
|
||||
@@ -379,23 +382,23 @@ func cueModInit(ctx context.Context, p string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func vendorUniverse(ctx context.Context, p string) error {
|
||||
func vendorUniverse(ctx context.Context, workspace string) error {
|
||||
// ensure cue module is initialized
|
||||
if err := cueModInit(ctx, p); err != nil {
|
||||
if err := cueModInit(ctx, workspace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add universe to `.gitignore`
|
||||
if err := os.WriteFile(
|
||||
path.Join(p, "cue.mod", "pkg", ".gitignore"),
|
||||
path.Join(workspace, "cue.mod", "pkg", ".gitignore"),
|
||||
[]byte(fmt.Sprintf("# dagger universe\n%s\n", stdlib.PackageName)),
|
||||
0600,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Ctx(ctx).Debug().Str("mod", p).Msg("vendoring universe")
|
||||
if err := stdlib.Vendor(ctx, p); err != nil {
|
||||
log.Ctx(ctx).Debug().Str("mod", workspace).Msg("vendoring universe")
|
||||
if err := mod.InstallStdlib(workspace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -35,8 +35,8 @@ type State struct {
|
||||
func (s *State) CompilePlan(ctx context.Context) (*compiler.Value, error) {
|
||||
w := s.Project
|
||||
// FIXME: backward compatibility
|
||||
if mod := s.Plan.Module; mod != "" {
|
||||
w = path.Join(w, mod)
|
||||
if planModule := s.Plan.Module; planModule != "" {
|
||||
w = path.Join(w, planModule)
|
||||
}
|
||||
|
||||
// FIXME: universe vendoring
|
||||
@@ -51,7 +51,7 @@ func (s *State) CompilePlan(ctx context.Context) (*compiler.Value, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
var args []string
|
||||
if pkg := s.Plan.Package; pkg != "" {
|
||||
args = append(args, pkg)
|
||||
}
|
||||
@@ -81,21 +81,6 @@ func (s *State) CompileInputs() (*compiler.Value, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// VendorUniverse vendors the latest (built-in) version of the universe into the
|
||||
// environment's `cue.mod`.
|
||||
// FIXME: This has nothing to do in `State` and should be tied to a `Project`.
|
||||
// However, since environments could point to different modules before, we have
|
||||
// to handle vendoring on a per environment basis.
|
||||
func (s *State) VendorUniverse(ctx context.Context) error {
|
||||
w := s.Project
|
||||
// FIXME: backward compatibility
|
||||
if mod := s.Plan.Module; mod != "" {
|
||||
w = path.Join(w, mod)
|
||||
}
|
||||
|
||||
return vendorUniverse(ctx, w)
|
||||
}
|
||||
|
||||
type Plan struct {
|
||||
Module string `yaml:"module,omitempty"`
|
||||
Package string `yaml:"package,omitempty"`
|
||||
|
1
state/state_test.go
Normal file
1
state/state_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package state
|
Reference in New Issue
Block a user