mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-23 07:21:28 +00:00
Enhanced package and build to by default not include any source code
This commit is contained in:
@@ -69,7 +69,7 @@ func (h *Harness) renderError(iw http.ResponseWriter, ir *http.Request, err erro
|
|||||||
if !utils.Exists(path) {
|
if !utils.Exists(path) {
|
||||||
path = filepath.Join(h.paths.RevelPath, "templates", "errors", view)
|
path = filepath.Join(h.paths.RevelPath, "templates", "errors", view)
|
||||||
}
|
}
|
||||||
println(path)
|
|
||||||
data,err := ioutil.ReadFile(path)
|
data,err := ioutil.ReadFile(path)
|
||||||
if err!=nil {
|
if err!=nil {
|
||||||
utils.Logger.Error("Unable to read template file", path)
|
utils.Logger.Error("Unable to read template file", path)
|
||||||
@@ -127,7 +127,6 @@ func (h *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Flush any change events and rebuild app if necessary.
|
// Flush any change events and rebuild app if necessary.
|
||||||
// Render an error page if the rebuild / restart failed.
|
// Render an error page if the rebuild / restart failed.
|
||||||
err := h.watcher.Notify()
|
err := h.watcher.Notify()
|
||||||
println("Serving ", err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// In a thread safe manner update the flag so that a request for
|
// In a thread safe manner update the flag so that a request for
|
||||||
// /favicon.ico does not trigger a rebuild
|
// /favicon.ico does not trigger a rebuild
|
||||||
@@ -265,9 +264,12 @@ func (h *Harness) Run() {
|
|||||||
|
|
||||||
if h.useProxy {
|
if h.useProxy {
|
||||||
go func() {
|
go func() {
|
||||||
|
// Check the port to start on a random port
|
||||||
|
if h.paths.HTTPPort==0 {
|
||||||
|
h.paths.HTTPPort = getFreePort()
|
||||||
|
}
|
||||||
addr := fmt.Sprintf("%s:%d", h.paths.HTTPAddr, h.paths.HTTPPort)
|
addr := fmt.Sprintf("%s:%d", h.paths.HTTPAddr, h.paths.HTTPPort)
|
||||||
utils.Logger.Infof("Proxy server is listening on %s", addr)
|
utils.Logger.Infof("Proxy server is listening on %s", addr)
|
||||||
println("Proxy server is listening on ", addr)
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if h.paths.HTTPSsl {
|
if h.paths.HTTPSsl {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ type (
|
|||||||
// The Command config for the line input
|
// The Command config for the line input
|
||||||
CommandConfig struct {
|
CommandConfig struct {
|
||||||
Index COMMAND // The index
|
Index COMMAND // The index
|
||||||
Verbose bool `short:"v" long:"debug" description:"If set the logger is set to verbose"` // True if debug is active
|
Verbose bool `short:"v" long:"debug" description:"If set the logger is set to verbose"` // True if debug is active
|
||||||
HistoricMode bool `long:"historic-run-mode" description:"If set the runmode is passed a string not json"` // True if debug is active
|
HistoricMode bool `long:"historic-run-mode" description:"If set the runmode is passed a string not json"` // True if debug is active
|
||||||
ImportPath string // The import path (converted from various commands)
|
ImportPath string // The import path (converted from various commands)
|
||||||
GoPath string // The GoPath
|
GoPath string // The GoPath
|
||||||
@@ -30,6 +30,7 @@ type (
|
|||||||
TargetPath string `short:"t" long:"target-path" description:"Path to target folder. Folder will be completely deleted if it exists" required:"true"`
|
TargetPath string `short:"t" long:"target-path" description:"Path to target folder. Folder will be completely deleted if it exists" required:"true"`
|
||||||
ImportPath string `short:"a" long:"application-path" description:"Path to applicaiton folder" required:"true"`
|
ImportPath string `short:"a" long:"application-path" description:"Path to applicaiton folder" required:"true"`
|
||||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||||
|
CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"`
|
||||||
} `command:"build"`
|
} `command:"build"`
|
||||||
// The run command
|
// The run command
|
||||||
Run struct {
|
Run struct {
|
||||||
@@ -42,6 +43,7 @@ type (
|
|||||||
Package struct {
|
Package struct {
|
||||||
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"`
|
||||||
ImportPath string `short:"a" long:"application-path" description:"Path to applicaiton folder" required:"true"`
|
ImportPath string `short:"a" long:"application-path" description:"Path to applicaiton folder" required:"true"`
|
||||||
|
CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"`
|
||||||
} `command:"package"`
|
} `command:"package"`
|
||||||
// The clean command
|
// The clean command
|
||||||
Clean struct {
|
Clean struct {
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast
|
|||||||
)
|
)
|
||||||
|
|
||||||
// For each source file in the package...
|
// For each source file in the package...
|
||||||
utils.Logger.Info("Exaiming files in path", "package", pkgPath)
|
utils.Logger.Info("Exaimining files in path", "package", pkgPath)
|
||||||
for fname, file := range pkg.Files {
|
for fname, file := range pkg.Files {
|
||||||
// Imports maps the package key to the full import path.
|
// Imports maps the package key to the full import path.
|
||||||
// e.g. import "sample/app/models" => "models": "sample/app/models"
|
// e.g. import "sample/app/models" => "models": "sample/app/models"
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
"github.com/revel/cmd/harness"
|
"github.com/revel/cmd/harness"
|
||||||
"github.com/revel/cmd/model"
|
"github.com/revel/cmd/model"
|
||||||
"go/build"
|
|
||||||
"github.com/revel/cmd/utils"
|
"github.com/revel/cmd/utils"
|
||||||
"fmt"
|
"go/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdBuild = &Command{
|
var cmdBuild = &Command{
|
||||||
@@ -36,7 +36,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The update config updates the configuration command so that it can run
|
// The update config updates the configuration command so that it can run
|
||||||
func updateBuildConfig(c *model.CommandConfig, args []string) (bool) {
|
func updateBuildConfig(c *model.CommandConfig, args []string) bool {
|
||||||
c.Index = BUILD
|
c.Index = BUILD
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
fmt.Fprintf(os.Stderr, "%s\n%s", cmdBuild.UsageLine, cmdBuild.Long)
|
fmt.Fprintf(os.Stderr, "%s\n%s", cmdBuild.UsageLine, cmdBuild.Long)
|
||||||
@@ -44,7 +44,7 @@ func updateBuildConfig(c *model.CommandConfig, args []string) (bool) {
|
|||||||
}
|
}
|
||||||
c.Build.ImportPath = args[0]
|
c.Build.ImportPath = args[0]
|
||||||
c.Build.TargetPath = args[1]
|
c.Build.TargetPath = args[1]
|
||||||
if len(args)>2 {
|
if len(args) > 2 {
|
||||||
c.Build.Mode = args[1]
|
c.Build.Mode = args[1]
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -53,7 +53,7 @@ func updateBuildConfig(c *model.CommandConfig, args []string) (bool) {
|
|||||||
// The main entry point to build application from command line
|
// The main entry point to build application from command line
|
||||||
func buildApp(c *model.CommandConfig) {
|
func buildApp(c *model.CommandConfig) {
|
||||||
c.ImportPath = c.Build.ImportPath
|
c.ImportPath = c.Build.ImportPath
|
||||||
appImportPath, destPath, mode := c.Build.ImportPath , c.Build.TargetPath, DefaultRunMode
|
appImportPath, destPath, mode := c.Build.ImportPath, c.Build.TargetPath, DefaultRunMode
|
||||||
if len(c.Build.Mode) > 0 {
|
if len(c.Build.Mode) > 0 {
|
||||||
mode = c.Build.Mode
|
mode = c.Build.Mode
|
||||||
}
|
}
|
||||||
@@ -71,18 +71,18 @@ func buildApp(c *model.CommandConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := os.RemoveAll(destPath); err != nil && !os.IsNotExist(err) {
|
if err := os.RemoveAll(destPath); err != nil && !os.IsNotExist(err) {
|
||||||
utils.Logger.Error("Remove all error","error", err)
|
utils.Logger.Error("Remove all error", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.MkdirAll(destPath, 0777); err != nil {
|
if err := os.MkdirAll(destPath, 0777); err != nil {
|
||||||
utils.Logger.Error("makedir error","error",err)
|
utils.Logger.Error("makedir error", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app, reverr := harness.Build(c,revel_paths)
|
app, reverr := harness.Build(c, revel_paths)
|
||||||
if reverr!=nil {
|
if reverr != nil {
|
||||||
utils.Logger.Error("Failed to build application","error",reverr)
|
utils.Logger.Error("Failed to build application", "error", reverr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,14 +98,40 @@ func buildApp(c *model.CommandConfig) {
|
|||||||
tmpRevelPath := filepath.Join(srcPath, filepath.FromSlash(model.RevelImportPath))
|
tmpRevelPath := filepath.Join(srcPath, filepath.FromSlash(model.RevelImportPath))
|
||||||
utils.MustCopyFile(destBinaryPath, app.BinaryPath)
|
utils.MustCopyFile(destBinaryPath, app.BinaryPath)
|
||||||
utils.MustChmod(destBinaryPath, 0755)
|
utils.MustChmod(destBinaryPath, 0755)
|
||||||
|
|
||||||
|
// Copy the templates from the revel
|
||||||
_ = utils.MustCopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel_paths.RevelPath, "conf"), nil)
|
_ = utils.MustCopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel_paths.RevelPath, "conf"), nil)
|
||||||
_ = utils.MustCopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel_paths.RevelPath, "templates"), nil)
|
_ = utils.MustCopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel_paths.RevelPath, "templates"), nil)
|
||||||
_ = utils.MustCopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel_paths.BasePath, nil)
|
|
||||||
|
// Get the folders to be packaged
|
||||||
|
packageFolders := strings.Split(revel_paths.Config.StringDefault("package.folders", "conf,public,app/views"), ",")
|
||||||
|
for i,p:=range packageFolders {
|
||||||
|
// Clean spaces, reformat slash to filesystem
|
||||||
|
packageFolders[i]=filepath.FromSlash(strings.TrimSpace(p))
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Build.CopySource {
|
||||||
|
_ = utils.MustCopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel_paths.BasePath, nil)
|
||||||
|
} else {
|
||||||
|
for _, folder := range packageFolders {
|
||||||
|
_ = utils.MustCopyDir(
|
||||||
|
filepath.Join(srcPath, filepath.FromSlash(appImportPath), folder),
|
||||||
|
filepath.Join(revel_paths.BasePath, folder),
|
||||||
|
nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Find all the modules used and copy them over.
|
// Find all the modules used and copy them over.
|
||||||
config := revel_paths.Config.Raw()
|
config := revel_paths.Config.Raw()
|
||||||
modulePaths := make(map[string]string) // import path => filesystem path
|
modulePaths := make(map[string]string) // import path => filesystem path
|
||||||
|
|
||||||
|
// We should only copy over the section of options what the build is targeted for
|
||||||
|
// We will default to prod
|
||||||
for _, section := range config.Sections() {
|
for _, section := range config.Sections() {
|
||||||
|
// If the runmode is defined we will only import modules defined for that run mode
|
||||||
|
if c.Build.Mode != "" && c.Build.Mode != section {
|
||||||
|
continue
|
||||||
|
}
|
||||||
options, _ := config.SectionOptions(section)
|
options, _ := config.SectionOptions(section)
|
||||||
for _, key := range options {
|
for _, key := range options {
|
||||||
if !strings.HasPrefix(key, "module.") {
|
if !strings.HasPrefix(key, "module.") {
|
||||||
@@ -116,15 +142,28 @@ func buildApp(c *model.CommandConfig) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
modPkg, err := build.Import(c.ImportPath, revel_paths.RevelPath, build.FindOnly)
|
modPkg, err := build.Import(moduleImportPath, revel_paths.RevelPath, build.FindOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Logger.Fatalf("Failed to load module %s (%s): %s", key[len("module."):], c.ImportPath, err)
|
utils.Logger.Fatalf("Failed to load module %s (%s): %s", key[len("module."):], c.ImportPath, err)
|
||||||
}
|
}
|
||||||
modulePaths[moduleImportPath] = modPkg.Dir
|
modulePaths[moduleImportPath] = modPkg.Dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy the the paths for each of the modules
|
||||||
for importPath, fsPath := range modulePaths {
|
for importPath, fsPath := range modulePaths {
|
||||||
_ = utils.MustCopyDir(filepath.Join(srcPath, importPath), fsPath, nil)
|
utils.Logger.Info("Copy files ", "to", filepath.Join(srcPath, importPath), "from", fsPath)
|
||||||
|
if c.Build.CopySource {
|
||||||
|
_ = utils.MustCopyDir(filepath.Join(srcPath, importPath), fsPath, nil)
|
||||||
|
} else {
|
||||||
|
for _, folder := range packageFolders {
|
||||||
|
_ = utils.MustCopyDir(
|
||||||
|
filepath.Join(srcPath, importPath, folder),
|
||||||
|
filepath.Join(fsPath, folder),
|
||||||
|
nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplData := map[string]interface{}{
|
tmplData := map[string]interface{}{
|
||||||
|
|||||||
@@ -76,8 +76,11 @@ func packageApp(c *model.CommandConfig) {
|
|||||||
|
|
||||||
// Build expects the command the build to contain the proper data
|
// Build expects the command the build to contain the proper data
|
||||||
c.Build.ImportPath = appImportPath
|
c.Build.ImportPath = appImportPath
|
||||||
c.Build.Mode = mode
|
if len(c.Package.Mode) >= 0 {
|
||||||
|
c.Build.Mode = c.Package.Mode
|
||||||
|
}
|
||||||
c.Build.TargetPath = tmpDir
|
c.Build.TargetPath = tmpDir
|
||||||
|
c.Build.CopySource = c.Package.CopySource
|
||||||
buildApp(c)
|
buildApp(c)
|
||||||
|
|
||||||
// Create the zip file.
|
// Create the zip file.
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ func updateRunConfig(c *model.CommandConfig, args []string) bool {
|
|||||||
// 1st arg is the run mode
|
// 1st arg is the run mode
|
||||||
c.Run.Mode = args[0]
|
c.Run.Mode = args[0]
|
||||||
}
|
}
|
||||||
|
case 0:
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
c.Index = RUN
|
c.Index = RUN
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -3,6 +3,22 @@
|
|||||||
# More info at http://revel.github.io/manual/appconf.html
|
# More info at http://revel.github.io/manual/appconf.html
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
# Revel build section
|
||||||
|
# This section contains values that are not reloadable
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Comma delimited list of folders that are included with the package, or build commands
|
||||||
|
# If you want to not include folders within these ones prefix the folder with a . to make it hidden
|
||||||
|
package.folders = conf, public, app/views
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Revel reconfigurable section
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
# Sets `revel.AppName` for use in-app.
|
# Sets `revel.AppName` for use in-app.
|
||||||
# Example:
|
# Example:
|
||||||
# `if revel.AppName {...}`
|
# `if revel.AppName {...}`
|
||||||
@@ -197,9 +213,9 @@ watch = false
|
|||||||
|
|
||||||
module.testrunner =
|
module.testrunner =
|
||||||
|
|
||||||
log.warn.output = log/%(app.name)-warn.json # Log all warn messages to file
|
log.warn.output = log/%(app.name)s-warn.json # Log all warn messages to file
|
||||||
log.error.output = log/%(app.name)-error.json # Log all errors to file
|
log.error.output = log/%(app.name)s-error.json # Log all errors to file
|
||||||
log.crit.output = log/%(app.name)-critical.json # Log all critical to file
|
log.crit.output = log/%(app.name)s-critical.json # Log all critical to file
|
||||||
|
|
||||||
# Revel request access log (json format)
|
# Revel request access log (json format)
|
||||||
# Example:
|
# Example:
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ func runTestSuites(paths *model.RevelContainer, baseURL, resultPath string, test
|
|||||||
err = json.NewDecoder(resp.Body).Decode(&testResult)
|
err = json.NewDecoder(resp.Body).Decode(&testResult)
|
||||||
if err == nil && !testResult.Passed {
|
if err == nil && !testResult.Passed {
|
||||||
suiteResult.Passed = false
|
suiteResult.Passed = false
|
||||||
|
utils.Logger.Error("Test Failed","suite", suite.Name, "test", test.Name)
|
||||||
fmt.Printf(" %s.%s : FAILED\n", suite.Name, test.Name)
|
fmt.Printf(" %s.%s : FAILED\n", suite.Name, test.Name)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" %s.%s : PASSED\n", suite.Name, test.Name)
|
fmt.Printf(" %s.%s : PASSED\n", suite.Name, test.Name)
|
||||||
|
|||||||
@@ -45,10 +45,9 @@ func versionApp(c *model.CommandConfig) {
|
|||||||
utils.Logger.Errorf("Failed to find Revel with error:", "error", err)
|
utils.Logger.Errorf("Failed to find Revel with error:", "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.Logger.Info("Fullpath to revel", revelPkg.Dir)
|
||||||
fset := token.NewFileSet() // positions are relative to fset
|
fset := token.NewFileSet() // positions are relative to fset
|
||||||
|
|
||||||
|
|
||||||
version, err := ioutil.ReadFile(filepath.Join(revelPkg.Dir,"version.go"))
|
version, err := ioutil.ReadFile(filepath.Join(revelPkg.Dir,"version.go"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Logger.Errorf("Failed to find Revel version:", "error", err)
|
utils.Logger.Errorf("Failed to find Revel version:", "error", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user