From 0fd5bcfcbaa045cc8419303a0e61f3141380ac92 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Fri, 31 Oct 2014 16:10:22 +0100 Subject: [PATCH 1/2] Add environment mode to package. --- revel/build.go | 5 +++-- revel/package.go | 18 +++++++++++++++--- revel/package_run.bat.template | 2 +- revel/package_run.sh.template | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/revel/build.go b/revel/build.go index 47423db..bf6f2ba 100644 --- a/revel/build.go +++ b/revel/build.go @@ -31,12 +31,12 @@ func init() { } func buildApp(args []string) { - if len(args) != 2 { + if len(args) != 3 { fmt.Fprintf(os.Stderr, "%s\n%s", cmdBuild.UsageLine, cmdBuild.Long) return } - appImportPath, destPath := args[0], args[1] + appImportPath, destPath, mode := args[0], args[1], args[2] if !revel.Initialized { revel.Init("", appImportPath, "") } @@ -96,6 +96,7 @@ func buildApp(args []string) { tmplData, runShPath := map[string]interface{}{ "BinName": filepath.Base(app.BinaryPath), "ImportPath": appImportPath, + "Mode": mode, }, path.Join(destPath, "run.sh") mustRenderTemplate( diff --git a/revel/package.go b/revel/package.go index b909901..a4c62fe 100644 --- a/revel/package.go +++ b/revel/package.go @@ -2,19 +2,25 @@ package main import ( "fmt" - "github.com/revel/revel" "io/ioutil" "os" "path/filepath" + + "github.com/revel/revel" ) var cmdPackage = &Command{ - UsageLine: "package [import path]", + UsageLine: "package [import path] [run mode]", Short: "package a Revel application (e.g. for deployment)", Long: ` 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. +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: revel package github.com/revel/revel/samples/chat @@ -31,6 +37,12 @@ func packageApp(args []string) { return } + // Determine the run mode. + mode := "prod" + if len(args) >= 2 { + mode = args[1] + } + appImportPath := args[0] revel.Init("", appImportPath, "") @@ -42,7 +54,7 @@ func packageApp(args []string) { tmpDir, err := ioutil.TempDir("", filepath.Base(revel.BasePath)) panicOnError(err, "Failed to get temp dir") - buildApp([]string{args[0], tmpDir}) + buildApp([]string{args[0], tmpDir, mode}) // Create the zip file. archiveName := mustTarGzDir(destFile, tmpDir) diff --git a/revel/package_run.bat.template b/revel/package_run.bat.template index e73399b..f101d80 100644 --- a/revel/package_run.bat.template +++ b/revel/package_run.bat.template @@ -1,2 +1,2 @@ @echo off -{{.BinName}} -importPath {{.ImportPath}} -srcPath %CD%\src -runMode prod +{{.BinName}} -importPath {{.ImportPath}} -srcPath %CD%\src -runMode {{.Mode}} diff --git a/revel/package_run.sh.template b/revel/package_run.sh.template index ac0e12a..69bcaa6 100644 --- a/revel/package_run.sh.template +++ b/revel/package_run.sh.template @@ -1,3 +1,3 @@ #!/bin/sh SCRIPTPATH=$(cd "$(dirname "$0")"; pwd) -"$SCRIPTPATH/{{.BinName}}" -importPath {{.ImportPath}} -srcPath "$SCRIPTPATH/src" -runMode prod +"$SCRIPTPATH/{{.BinName}}" -importPath {{.ImportPath}} -srcPath "$SCRIPTPATH/src" -runMode {{.Mode}} From 6d12b806d3d0da51e958a1c0384c1709b07dbbd3 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sun, 22 May 2016 20:40:13 -0700 Subject: [PATCH 2/2] Validated PR #14 and fixed issues for the PR --- revel/build.go | 19 +++++++++++++++---- revel/package.go | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/revel/build.go b/revel/build.go index 95dbf47..33b9174 100644 --- a/revel/build.go +++ b/revel/build.go @@ -12,12 +12,17 @@ import ( ) 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)", Long: ` 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. +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! For example: @@ -31,14 +36,20 @@ func init() { } func buildApp(args []string) { - if len(args) != 3 { + if len(args) < 2 { fmt.Fprintf(os.Stderr, "%s\n%s", cmdBuild.UsageLine, cmdBuild.Long) return } - appImportPath, destPath, mode := args[0], args[1], args[2] + appImportPath, destPath, mode := args[0], args[1], "prod" + if len(args) >= 3 { + mode = args[2] + } + + fmt.Println("mode:", mode) + if !revel.Initialized { - revel.Init("", appImportPath, "") + revel.Init(mode, appImportPath, "") } // First, verify that it is either already empty or looks like a previous diff --git a/revel/package.go b/revel/package.go index f18161b..9c8272b 100644 --- a/revel/package.go +++ b/revel/package.go @@ -44,7 +44,7 @@ func packageApp(args []string) { } appImportPath := args[0] - revel.Init("", appImportPath, "") + revel.Init(mode, appImportPath, "") // Remove the archive if it already exists. destFile := filepath.Base(revel.BasePath) + ".tar.gz"