Merge branch 'birkirb-master' into develop

This commit is contained in:
Jeevanandam M
2016-05-22 20:40:58 -07:00
4 changed files with 34 additions and 10 deletions

View File

@@ -12,12 +12,17 @@ import (
) )
var cmdBuild = &Command{ var cmdBuild = &Command{
UsageLine: "build [import path] [target path]", UsageLine: "build [import path] [target path] [run mode]",
Short: "build a Revel application (e.g. for deployment)", Short: "build a Revel application (e.g. for deployment)",
Long: ` Long: `
Build the Revel web application named by the given import path. Build the Revel web application named by the given import path.
This allows it to be deployed and run on a machine that lacks a Go installation. This allows it to be deployed and run on a machine that lacks a Go installation.
The run mode is used to select which set of app.conf configuration should
apply and may be used to determine logic in the application itself.
Run mode defaults to "prod".
WARNING: The target path will be completely deleted, if it already exists! WARNING: The target path will be completely deleted, if it already exists!
For example: For example:
@@ -31,14 +36,20 @@ func init() {
} }
func buildApp(args []string) { func buildApp(args []string) {
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)
return return
} }
appImportPath, destPath := args[0], args[1] appImportPath, destPath, mode := args[0], args[1], "prod"
if len(args) >= 3 {
mode = args[2]
}
fmt.Println("mode:", mode)
if !revel.Initialized { if !revel.Initialized {
revel.Init("", appImportPath, "") revel.Init(mode, appImportPath, "")
} }
// First, verify that it is either already empty or looks like a previous // First, verify that it is either already empty or looks like a previous
@@ -96,6 +107,7 @@ func buildApp(args []string) {
tmplData, runShPath := map[string]interface{}{ tmplData, runShPath := map[string]interface{}{
"BinName": filepath.Base(app.BinaryPath), "BinName": filepath.Base(app.BinaryPath),
"ImportPath": appImportPath, "ImportPath": appImportPath,
"Mode": mode,
}, path.Join(destPath, "run.sh") }, path.Join(destPath, "run.sh")
mustRenderTemplate( mustRenderTemplate(

View File

@@ -2,19 +2,25 @@ package main
import ( import (
"fmt" "fmt"
"github.com/revel/revel"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"github.com/revel/revel"
) )
var cmdPackage = &Command{ var cmdPackage = &Command{
UsageLine: "package [import path]", UsageLine: "package [import path] [run mode]",
Short: "package a Revel application (e.g. for deployment)", Short: "package a Revel application (e.g. for deployment)",
Long: ` Long: `
Package the Revel web application named by the given import path. Package the Revel web application named by the given import path.
This allows it to be deployed and run on a machine that lacks a Go installation. This allows it to be deployed and run on a machine that lacks a Go installation.
The run mode is used to select which set of app.conf configuration should
apply and may be used to determine logic in the application itself.
Run mode defaults to "prod".
For example: For example:
revel package github.com/revel/samples/chat revel package github.com/revel/samples/chat
@@ -31,8 +37,14 @@ func packageApp(args []string) {
return return
} }
// Determine the run mode.
mode := "prod"
if len(args) >= 2 {
mode = args[1]
}
appImportPath := args[0] appImportPath := args[0]
revel.Init("", appImportPath, "") revel.Init(mode, appImportPath, "")
// Remove the archive if it already exists. // Remove the archive if it already exists.
destFile := filepath.Base(revel.BasePath) + ".tar.gz" destFile := filepath.Base(revel.BasePath) + ".tar.gz"
@@ -42,7 +54,7 @@ func packageApp(args []string) {
tmpDir, err := ioutil.TempDir("", filepath.Base(revel.BasePath)) tmpDir, err := ioutil.TempDir("", filepath.Base(revel.BasePath))
panicOnError(err, "Failed to get temp dir") panicOnError(err, "Failed to get temp dir")
buildApp([]string{args[0], tmpDir}) buildApp([]string{args[0], tmpDir, mode})
// Create the zip file. // Create the zip file.
archiveName := mustTarGzDir(destFile, tmpDir) archiveName := mustTarGzDir(destFile, tmpDir)

View File

@@ -1,2 +1,2 @@
@echo off @echo off
{{.BinName}} -importPath {{.ImportPath}} -srcPath %CD%\src -runMode prod {{.BinName}} -importPath {{.ImportPath}} -srcPath %CD%\src -runMode {{.Mode}}

View File

@@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd) SCRIPTPATH=$(cd "$(dirname "$0")"; pwd)
"$SCRIPTPATH/{{.BinName}}" -importPath {{.ImportPath}} -srcPath "$SCRIPTPATH/src" -runMode prod "$SCRIPTPATH/{{.BinName}}" -importPath {{.ImportPath}} -srcPath "$SCRIPTPATH/src" -runMode {{.Mode}}