changed workspace to project

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones
2021-09-23 12:02:57 -06:00
parent 541c8c078f
commit 7061ac816e
20 changed files with 112 additions and 112 deletions

View File

@@ -108,10 +108,10 @@ func (dir dirInput) Compile(_ string, state *State) (*compiler.Value, error) {
p := dir.Path
if !filepath.IsAbs(p) {
p = filepath.Clean(path.Join(state.Workspace, dir.Path))
p = filepath.Clean(path.Join(state.Project, dir.Path))
}
if !strings.HasPrefix(p, state.Workspace) {
return nil, fmt.Errorf("%q is outside the workspace", dir.Path)
if !strings.HasPrefix(p, state.Project) {
return nil, fmt.Errorf("%q is outside the project", dir.Path)
}
llb := fmt.Sprintf(

View File

@@ -32,11 +32,11 @@ const (
computedFile = "computed.json"
)
type Workspace struct {
type Project struct {
Path string
}
func Init(ctx context.Context, dir string) (*Workspace, error) {
func Init(ctx context.Context, dir string) (*Project, error) {
root, err := filepath.Abs(dir)
if err != nil {
return nil, err
@@ -57,12 +57,12 @@ func Init(ctx context.Context, dir string) (*Workspace, error) {
return nil, err
}
return &Workspace{
return &Project{
Path: root,
}, nil
}
func Open(ctx context.Context, dir string) (*Workspace, error) {
func Open(ctx context.Context, dir string) (*Project, error) {
_, err := os.Stat(path.Join(dir, daggerDir))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
@@ -76,12 +76,12 @@ func Open(ctx context.Context, dir string) (*Workspace, error) {
return nil, err
}
return &Workspace{
return &Project{
Path: root,
}, nil
}
func Current(ctx context.Context) (*Workspace, error) {
func Current(ctx context.Context) (*Project, error) {
current, err := os.Getwd()
if err != nil {
return nil, err
@@ -103,11 +103,11 @@ func Current(ctx context.Context) (*Workspace, error) {
return nil, ErrNotInit
}
func (w *Workspace) envPath(name string) string {
func (w *Project) envPath(name string) string {
return path.Join(w.Path, daggerDir, envDir, name)
}
func (w *Workspace) List(ctx context.Context) ([]*State, error) {
func (w *Project) List(ctx context.Context) ([]*State, error) {
var (
environments = []*State{}
err error
@@ -139,7 +139,7 @@ func (w *Workspace) List(ctx context.Context) ([]*State, error) {
return environments, nil
}
func (w *Workspace) Get(ctx context.Context, name string) (*State, error) {
func (w *Project) Get(ctx context.Context, name string) (*State, error) {
envPath, err := filepath.Abs(w.envPath(name))
if err != nil {
return nil, err
@@ -179,7 +179,7 @@ func (w *Workspace) Get(ctx context.Context, name string) (*State, error) {
st.Plan.Module = planRelPath
}
}
st.Workspace = w.Path
st.Project = w.Path
computed, err := os.ReadFile(path.Join(envPath, stateDir, computedFile))
if err == nil {
@@ -189,7 +189,7 @@ func (w *Workspace) Get(ctx context.Context, name string) (*State, error) {
return &st, nil
}
func (w *Workspace) Save(ctx context.Context, st *State) error {
func (w *Project) Save(ctx context.Context, st *State) error {
data, err := yaml.Marshal(st)
if err != nil {
return err
@@ -234,7 +234,7 @@ func (w *Workspace) Save(ctx context.Context, st *State) error {
return nil
}
func (w *Workspace) Create(ctx context.Context, name string, plan Plan) (*State, error) {
func (w *Project) Create(ctx context.Context, name string, plan Plan) (*State, error) {
if _, err := w.Get(ctx, name); err == nil {
return nil, ErrExist
}
@@ -257,8 +257,8 @@ func (w *Workspace) Create(ctx context.Context, name string, plan Plan) (*State,
manifestPath := path.Join(envPath, manifestFile)
st := &State{
Path: envPath,
Workspace: w.Path,
Path: envPath,
Project: w.Path,
Plan: Plan{
Package: pkg,
},
@@ -293,7 +293,7 @@ func (w *Workspace) Create(ctx context.Context, name string, plan Plan) (*State,
return st, nil
}
func (w *Workspace) cleanPackageName(ctx context.Context, pkg string) (string, error) {
func (w *Project) cleanPackageName(ctx context.Context, pkg string) (string, error) {
lg := log.
Ctx(ctx).
With().
@@ -325,7 +325,7 @@ func (w *Workspace) cleanPackageName(ctx context.Context, pkg string) (string, e
}
if !strings.HasPrefix(p, w.Path) {
lg.Fatal().Err(err).Msg("package is outside the workspace")
lg.Fatal().Err(err).Msg("package is outside the project")
return "", err
}

View File

@@ -12,7 +12,7 @@ import (
"gopkg.in/yaml.v3"
)
func TestWorkspace(t *testing.T) {
func TestProject(t *testing.T) {
ctx := context.TODO()
keychain.EnsureDefaultKey(ctx)
@@ -25,39 +25,39 @@ func TestWorkspace(t *testing.T) {
require.ErrorIs(t, ErrNotInit, err)
// Init
workspace, err := Init(ctx, root)
project, err := Init(ctx, root)
require.NoError(t, err)
require.Equal(t, root, workspace.Path)
require.Equal(t, root, project.Path)
// Create
st, err := workspace.Create(ctx, "test", Plan{
st, err := project.Create(ctx, "test", Plan{
Module: ".",
})
require.NoError(t, err)
require.Equal(t, "test", st.Name)
// Open
workspace, err = Open(ctx, root)
project, err = Open(ctx, root)
require.NoError(t, err)
require.Equal(t, root, workspace.Path)
require.Equal(t, root, project.Path)
// List
envs, err := workspace.List(ctx)
envs, err := project.List(ctx)
require.NoError(t, err)
require.Len(t, envs, 1)
require.Equal(t, "test", envs[0].Name)
// Get
env, err := workspace.Get(ctx, "test")
env, err := project.Get(ctx, "test")
require.NoError(t, err)
require.Equal(t, "test", env.Name)
// Save
require.NoError(t, env.SetInput("foo", TextInput("bar")))
require.NoError(t, workspace.Save(ctx, env))
workspace, err = Open(ctx, root)
require.NoError(t, project.Save(ctx, env))
project, err = Open(ctx, root)
require.NoError(t, err)
env, err = workspace.Get(ctx, "test")
env, err = project.Get(ctx, "test")
require.NoError(t, err)
require.Contains(t, env.Inputs, "foo")
}
@@ -77,28 +77,28 @@ func TestEncryption(t *testing.T) {
root, err := os.MkdirTemp(os.TempDir(), "dagger-*")
require.NoError(t, err)
workspace, err := Init(ctx, root)
project, err := Init(ctx, root)
require.NoError(t, err)
_, err = workspace.Create(ctx, "test", Plan{
_, err = project.Create(ctx, "test", Plan{
Module: ".",
})
require.NoError(t, err)
// Set a plaintext input, make sure it is not encrypted
st, err := workspace.Get(ctx, "test")
st, err := project.Get(ctx, "test")
require.NoError(t, err)
require.NoError(t, st.SetInput("plain", TextInput("plain")))
require.NoError(t, workspace.Save(ctx, st))
require.NoError(t, project.Save(ctx, st))
o := readManifest(st)
require.Contains(t, o.Inputs, "plain")
require.Equal(t, "plain", string(*o.Inputs["plain"].Text))
// Set a secret input, make sure it's encrypted
st, err = workspace.Get(ctx, "test")
st, err = project.Get(ctx, "test")
require.NoError(t, err)
require.NoError(t, st.SetInput("secret", SecretInput("secret")))
require.NoError(t, workspace.Save(ctx, st))
require.NoError(t, project.Save(ctx, st))
o = readManifest(st)
require.Contains(t, o.Inputs, "secret")
secretValue := string(*o.Inputs["secret"].Secret)
@@ -106,10 +106,10 @@ func TestEncryption(t *testing.T) {
require.True(t, strings.HasPrefix(secretValue, "ENC["))
// Change another input, make sure our secret didn't change
st, err = workspace.Get(ctx, "test")
st, err = project.Get(ctx, "test")
require.NoError(t, err)
require.NoError(t, st.SetInput("plain", TextInput("different")))
require.NoError(t, workspace.Save(ctx, st))
require.NoError(t, project.Save(ctx, st))
o = readManifest(st)
require.Contains(t, o.Inputs, "plain")
require.Equal(t, "different", string(*o.Inputs["plain"].Text))

View File

@@ -13,8 +13,8 @@ type State struct {
// State path
Path string `yaml:"-"`
// Workspace path
Workspace string `yaml:"-"`
// Project path
Project string `yaml:"-"`
// Plan
Plan Plan `yaml:"plan,omitempty"`
@@ -33,7 +33,7 @@ type State struct {
// Cue module containing the environment plan
func (s *State) CompilePlan(ctx context.Context) (*compiler.Value, error) {
w := s.Workspace
w := s.Project
// FIXME: backward compatibility
if mod := s.Plan.Module; mod != "" {
w = path.Join(w, mod)
@@ -44,7 +44,7 @@ func (s *State) CompilePlan(ctx context.Context) (*compiler.Value, error) {
// However:
// 1) As of right now, there's no way to update universe through the
// CLI, so we are lazily updating on `dagger up` using the embedded `universe`
// 2) For backward compatibility: if the workspace was `dagger
// 2) For backward compatibility: if the project was `dagger
// init`-ed before we added support for vendoring universe, it might not
// contain a `cue.mod`.
if err := vendorUniverse(ctx, w); err != nil {
@@ -83,11 +83,11 @@ func (s *State) CompileInputs() (*compiler.Value, error) {
// 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 `Workspace`.
// 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.Workspace
w := s.Project
// FIXME: backward compatibility
if mod := s.Plan.Module; mod != "" {
w = path.Join(w, mod)