Skip to content

Commit

Permalink
Move pods directory from .spice/pods to ./spicepods (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekim committed Sep 3, 2021
1 parent ef5aaba commit cd24200
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ jobs:
export SPICE_DEEPRL_ALGORITHM="${{ matrix.algorithm }}"
./spice version --context ${{ matrix.context }}
./spice add test/Trader@0.2.0
./spice train .spice/pods/trader.yaml --context ${{ matrix.context }}
./spice train spicepods/trader.yaml --context ${{ matrix.context }}
end-to-end:
name: end-to-end test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cmd/spice/data
cmd/spiced/spiced
cmd/spiced/.spice
cmd/spiced/data
spicepods

# Debug binaries
__debug_bin
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ In the original terminal instance, add the LogPruner sample pod:
spice add quickstarts/logpruner
```

The Spice CLI will download the LogPruner sample pod manifest and add it to your project at `.spice/pods/logpruner.yaml`.
The Spice CLI will download the LogPruner sample pod manifest and add it to your project at `spicepods/logpruner.yaml`.

The Spice.ai runtime will then automatically detect the manifest and start your first training run!

Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func testInit(root *cobra.Command) func(*testing.T) {
return func(t *testing.T) {
_, err := executeCommand(root, "init", "foo")
assert.NoError(t, err)
_, err = os.Stat(".spice/pods/foo.yaml")
_, err = os.Stat("spicepods/foo.yaml")
assert.NoError(t, err)

_, err = pods.LoadPodFromManifest(".spice/pods/foo.yaml")
_, err = pods.LoadPodFromManifest("spicepods/foo.yaml")
assert.NoError(t, err)
}
}
Expand All @@ -80,7 +80,7 @@ func testActionAddCmd(root *cobra.Command) func(*testing.T) {
_, err := executeCommand(root, "action", "add", "jump")
assert.NoError(t, err)

pod, err := pods.LoadPodFromManifest(".spice/pods/foo.yaml")
pod, err := pods.LoadPodFromManifest("spicepods/foo.yaml")
assert.NoError(t, err)

assert.Contains(t, pod.Actions(), "jump")
Expand All @@ -93,7 +93,7 @@ func testRewardsAddCmd(root *cobra.Command) func(*testing.T) {
_, err := executeCommand(root, "reward", "add")
assert.NoError(t, err)

pod, err := pods.LoadPodFromManifest(".spice/pods/foo.yaml")
pod, err := pods.LoadPodFromManifest("spicepods/foo.yaml")
assert.NoError(t, err)

assert.Contains(t, pod.Rewards(), "jump")
Expand Down
13 changes: 7 additions & 6 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package constants

const (
DotSpice = ".spice"
SpiceConfigBaseName = "spice.config"
SpiceRuntimeFilename = "spiced"
SpicePodFileExtension = ".spicepod"
PythonCmd = "python3"
SpiceEnvVarPrefix = "SPICE_"
DotSpice = ".spice"
SpiceConfigBaseName = "spice.config"
SpicePodsDirectoryName = "spicepods"
SpiceRuntimeFilename = "spiced"
SpicePodFileExtension = ".spicepod"
PythonCmd = "python3"
SpiceEnvVarPrefix = "SPICE_"
)
2 changes: 1 addition & 1 deletion pkg/context/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (

func NewDockerContext() *DockerContext {
spiceBinDir := path.Join(dockerSpiceRuntimePath, "bin")
podsDir := path.Join(dockerAppPath, constants.DotSpice, "pods")
podsDir := path.Join(dockerAppPath, constants.SpicePodsDirectoryName)

return &DockerContext{
spiceBinDir: spiceBinDir,
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/metal/metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *MetalContext) Init() error {
return err
}
c.appDir = cwd
c.podsDir = filepath.Join(c.appDir, constants.DotSpice, "pods")
c.podsDir = filepath.Join(c.appDir, constants.SpicePodsDirectoryName)

return nil
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/registry/local_file.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package registry

import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/spiceai/spiceai/pkg/context"
"github.com/spiceai/spiceai/pkg/util"
)

type LocalFileRegistry struct{}
Expand All @@ -16,6 +19,17 @@ func (r *LocalFileRegistry) GetPod(podPath string) (string, error) {
return "", fmt.Errorf("pod not found at %s: %w", podPath, err)
}

podsDir := context.CurrentContext().PodsDir()
if _, err = os.Stat(podsDir); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return "", fmt.Errorf("error fetching pod %s: %w", podPath, err)
}
_, err = util.MkDirAllInheritPerm(podsDir)
if err != nil {
return "", fmt.Errorf("error fetching pod %s: %w", podPath, err)
}
}

podManifestFileName := filepath.Base(podPath)

podManifestPath := filepath.Join(context.CurrentContext().PodsDir(), podManifestFileName)
Expand Down
5 changes: 4 additions & 1 deletion pkg/registry/registry_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package registry_test

import (
"os"
"testing"

"github.com/spiceai/spiceai/pkg/constants"
"github.com/spiceai/spiceai/pkg/pods"
"github.com/spiceai/spiceai/pkg/registry"
"github.com/spiceai/spiceai/pkg/testutils"
Expand All @@ -21,8 +23,9 @@ func testGetPod() func(*testing.T) {
r := registry.GetRegistry(manifestPath)
_, err := r.GetPod(manifestPath)
assert.NoError(t, err)
defer os.RemoveAll(constants.SpicePodsDirectoryName)

pod, err := pods.LoadPodFromManifest(".spice/pods/trader.yaml")
pod, err := pods.LoadPodFromManifest("spicepods/trader.yaml")
if assert.NoError(t, err) {
assert.Contains(t, pod.Name, "trader")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (r *SpiceRuntime) scanForPods() error {
podsManifestDir := context.CurrentContext().PodsDir()
_, err = os.Stat(podsManifestDir)
if err != nil {
// No .spice/pods means no pods
// No spicepods means no pods
return nil
}

Expand Down

0 comments on commit cd24200

Please sign in to comment.