Skip to content

Commit

Permalink
Enable node framework applications to create a volume
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed May 29, 2023
1 parent cb025b0 commit fb09ab4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
18 changes: 16 additions & 2 deletions internal/command/launch/srcinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,22 @@ func runCallback(ctx context.Context, srcInfo *scanner.SourceInfo, options map[s
cfg, err := appconfig.LoadConfig(srcInfo.MergeConfig.Name)
if err == nil {
// In theory, any part of the configuration could be merged here, but for now
// we will only copy over the processes
srcInfo.Processes = cfg.Processes
// we will only copy over the processes and volume
if srcInfo.Processes == nil {
srcInfo.Processes = cfg.Processes
}

if len(srcInfo.Volumes) == 0 && len(cfg.Mounts) > 0 {
volume := scanner.Volume{
Source: cfg.Mounts[0].Source,
Destination: cfg.Mounts[0].Destination,
// TODO: shouldn't srcInfo.Volumes and appConfig.Mounts be reconciled?
// * ideally they should be the same type
// * failing that, Volume should include Processes []string
}

srcInfo.Volumes = []scanner.Volume{volume}
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions scanner/nodeFramework.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/fs"
"log"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -73,6 +74,23 @@ func configureNodeFramework(sourceDir string, config *ScannerConfig) (*SourceInf
Callback: NodeFrameworkCallback,
}

flyToml := "fly.toml"
_, err = os.Stat(flyToml)
if os.IsNotExist(err) {
// "touch" fly.toml
file, err := os.Create(flyToml)
if err != nil {
log.Fatal(err)
}
file.Close()

// inform caller of the presence of this file
srcInfo.MergeConfig = &MergeConfigStruct{
Name: flyToml,
Temporary: true,
}
}

return srcInfo, nil
}

Expand Down Expand Up @@ -116,6 +134,7 @@ func NodeFrameworkCallback(srcInfo *SourceInfo, options map[string]bool) error {

// install/run command
if !installed || args[0] == "npx" {
fmt.Printf("installing: %s\n", strings.Join(args[:], " "))
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = nil
cmd.Stdout = os.Stdout
Expand Down
4 changes: 2 additions & 2 deletions scanner/rails.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ func RailsCallback(srcInfo *SourceInfo, options map[string]bool) error {
_, err := os.Stat(flyToml)
if os.IsNotExist(err) {
// "touch" fly.toml
file, err := os.Create("fly.toml")
file, err := os.Create(flyToml)
if err != nil {
log.Fatal(err)
}
file.Close()

// inform caller of the presence of this file
srcInfo.MergeConfig = &MergeConfigStruct{
Name: "fly.toml",
Name: flyToml,
Temporary: true,
}
}
Expand Down

0 comments on commit fb09ab4

Please sign in to comment.