-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.go
64 lines (48 loc) · 1.36 KB
/
package.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/yext/revel"
)
var cmdPackage = &Command{
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 build options.
For package, run mode defaults to "prod".
For example:
revel package github.com/yext/revel/samples/chat
`,
}
func init() {
cmdPackage.Run = packageApp
}
func packageApp(args []string) {
if len(args) == 0 {
fmt.Fprint(os.Stderr, cmdPackage.Long)
return
}
appImportPath := args[0]
// Determine the run mode.
mode := "prod"
if len(args) >= 2 {
mode = args[1]
}
revel.Init(mode, appImportPath, "")
revel.LoadModules()
// Remove the archive if it already exists.
destFile := filepath.Base(revel.BasePath) + ".tar.gz"
os.Remove(destFile)
// Collect stuff in a temp directory.
tmpDir, err := ioutil.TempDir("", filepath.Base(revel.BasePath))
panicOnError(err, "Failed to get temp dir")
buildApp([]string{args[0], tmpDir})
// Create the zip file.
archiveName := mustTarGzDir(destFile, tmpDir)
fmt.Println("Your archive is ready:", archiveName)
}