generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: embed runner template for
ftl serve
(#544)
In development mode this will build the template directory first, in release mode it will embed a zip file containing the template directory. Fixes #541
- Loading branch information
1 parent
3839bbb
commit 58ddc8a
Showing
7 changed files
with
91 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build !release | ||
|
||
package localscaling | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"sync" | ||
|
||
"github.com/TBD54566975/ftl/backend/common/exec" | ||
"github.com/TBD54566975/ftl/backend/common/log" | ||
"github.com/TBD54566975/ftl/internal" | ||
) | ||
|
||
var templateDirOnce sync.Once | ||
|
||
func templateDir(ctx context.Context) string { | ||
templateDirOnce.Do(func() { | ||
cmd := exec.Command(ctx, log.Info, internal.FTLSourceRoot(), "bit", "build/template/ftl/jars/ftl-runtime.jar") | ||
err := cmd.Run() | ||
if err != nil { | ||
panic(err) | ||
} | ||
}) | ||
return filepath.Join(internal.FTLSourceRoot(), "build/template") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//go:build release | ||
|
||
package localscaling | ||
|
||
import ( | ||
"archive/zip" | ||
"bytes" | ||
"context" | ||
_ "embed" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
|
||
"github.com/TBD54566975/ftl/internal" | ||
) | ||
|
||
//go:embed template.zip | ||
var archive []byte | ||
|
||
var templateDirOnce sync.Once | ||
|
||
func templateDir(ctx context.Context) string { | ||
cacheDir, err := os.UserCacheDir() | ||
if err != nil { | ||
panic(err) | ||
} | ||
cacheDir = filepath.Join(cacheDir, "ftl-runner-template") | ||
templateDirOnce.Do(func() { | ||
_ = os.RemoveAll(cacheDir) | ||
zr, err := zip.NewReader(bytes.NewReader(archive), int64(len(archive))) | ||
if err != nil { | ||
panic(err) | ||
} | ||
err = internal.UnzipDir(zr, cacheDir) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}) | ||
return cacheDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build !release | ||
|
||
package internal | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func FTLSourceRoot() string { | ||
return filepath.Clean(filepath.Join(filepath.Dir(os.Args[0]), "..", "..")) | ||
} |