Skip to content

Commit c141f59

Browse files
committed
feat(run): Seperate the run dir from the stack
This is because our tarring can't filter out the .nitric
1 parent a66b8dc commit c141f59

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

pkg/cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package main
1919
import (
2020
"fmt"
2121
"os"
22-
"path"
2322
"strings"
2423
"time"
2524

@@ -35,6 +34,7 @@ import (
3534
cmdTarget "github.com/nitrictech/newcli/pkg/cmd/target"
3635
"github.com/nitrictech/newcli/pkg/output"
3736
"github.com/nitrictech/newcli/pkg/tasklet"
37+
"github.com/nitrictech/newcli/pkg/utils"
3838
)
3939

4040
const configFileName = ".nitric-config"
@@ -107,7 +107,7 @@ func initConfig() {
107107

108108
// Search config in home directory with name ".nitric" (without extension).
109109
viper.AddConfigPath(home)
110-
viper.AddConfigPath(path.Join(home, ".config", "nitric"))
110+
viper.AddConfigPath(utils.NitricConfigDir())
111111
viper.SetConfigType("yaml")
112112
viper.SetConfigName(".nitric-config")
113113
}

pkg/cmd/run/root.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"os/signal"
23+
"path"
2324
"path/filepath"
2425
"syscall"
2526
"time"
@@ -64,7 +65,8 @@ var runCmd = &cobra.Command{
6465
}
6566
tasklet.MustRun(createBaseImage, tasklet.Opts{Signal: term})
6667

67-
ls := run.NewLocalServices(stackPath)
68+
ls := run.NewLocalServices(path.Base(stackPath), stackPath)
69+
6870
memerr := make(chan error)
6971

7072
startLocalServices := tasklet.Runner{

pkg/run/run.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"fmt"
2121
"net"
2222
"os"
23+
"path"
2324
"time"
2425

26+
"github.com/nitrictech/newcli/pkg/utils"
2527
"github.com/nitrictech/nitric/pkg/membrane"
2628
boltdb_service "github.com/nitrictech/nitric/pkg/plugins/document/boltdb"
2729
secret_service "github.com/nitrictech/nitric/pkg/plugins/secret/dev"
@@ -36,13 +38,15 @@ type LocalServices interface {
3638
}
3739

3840
type localServices struct {
41+
stackName string
3942
stackPath string
4043
mio *MinioServer
4144
mem *membrane.Membrane
4245
}
4346

44-
func NewLocalServices(stackPath string) LocalServices {
47+
func NewLocalServices(stackName, stackPath string) LocalServices {
4548
return &localServices{
49+
stackName: stackName,
4650
stackPath: stackPath,
4751
}
4852
}
@@ -65,8 +69,10 @@ func (l *localServices) Running() bool {
6569
}
6670

6771
func (l *localServices) Start() error {
72+
runDir := path.Join(utils.NitricRunDir(), l.stackName)
73+
6874
var err error
69-
l.mio, err = NewMinio("./.nitric/run", "test-run")
75+
l.mio, err = NewMinio(runDir, "test-run")
7076
if err != nil {
7177
return err
7278
}
@@ -87,14 +93,14 @@ func (l *localServices) Start() error {
8793
}
8894

8995
// Connect dev documents
90-
os.Setenv("LOCAL_DB_DIR", "./.nitric/run")
96+
os.Setenv("LOCAL_DB_DIR", runDir)
9197
dp, err := boltdb_service.New()
9298
if err != nil {
9399
return err
94100
}
95101

96102
// Connect secrets plugin
97-
os.Setenv("LOCAL_SEC_DIR", "./.nitric/run")
103+
os.Setenv("LOCAL_SEC_DIR", runDir)
98104
secp, err := secret_service.New()
99105
if err != nil {
100106
return err

pkg/templates/contents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var _ Downloader = &downloader{}
6161

6262
func NewDownloader() Downloader {
6363
return &downloader{
64-
configPath: path.Join(utils.NitricHome(), "store", "repositories.yml"),
64+
configPath: path.Join(utils.NitricTemplatesDir(), "repositories.yml"),
6565
newGetter: utils.NewGetter,
6666
}
6767
}

pkg/utils/paths.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package utils
1919
import (
2020
"log"
2121
"os"
22+
"os/user"
2223
"path"
24+
"runtime"
2325
"strings"
2426
)
2527

@@ -35,10 +37,9 @@ func SplitPath(p string) []string {
3537
return strings.FieldsFunc(p, slashSplitter)
3638
}
3739

38-
// Gets the nitric home directory
39-
func NitricHome() string {
40+
// homeDir gets the nitric home directory
41+
func homeDir() string {
4042
nitricHomeEnv := os.Getenv("NITRIC_HOME")
41-
4243
if nitricHomeEnv != "" {
4344
return nitricHomeEnv
4445
}
@@ -50,3 +51,33 @@ func NitricHome() string {
5051

5152
return path.Join(dirname, ".nitric")
5253
}
54+
55+
// NitricRunDir returns the directory to place runtime data.
56+
func NitricRunDir() string {
57+
if runtime.GOOS == "linux" {
58+
u, err := user.Current()
59+
if err != nil {
60+
log.Fatal(err)
61+
}
62+
return path.Join("/run/user/", u.Uid, "nitric")
63+
}
64+
return path.Join(homeDir(), "run")
65+
}
66+
67+
// NitricTemplatesDir returns the directory to place template related data.
68+
func NitricTemplatesDir() string {
69+
return path.Join(homeDir(), "store")
70+
}
71+
72+
// NitricConfigDir returns the directory to find configuration.
73+
func NitricConfigDir() string {
74+
if runtime.GOOS == "linux" {
75+
dirname, err := os.UserHomeDir()
76+
if err != nil {
77+
log.Fatal(err)
78+
}
79+
80+
return path.Join(dirname, ".config", "nitric")
81+
}
82+
return homeDir()
83+
}

0 commit comments

Comments
 (0)