This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
/
app.go
88 lines (74 loc) · 2.36 KB
/
app.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package rubyapp
import (
"strings"
"github.com/hashicorp/otto/app"
"github.com/hashicorp/otto/helper/bindata"
"github.com/hashicorp/otto/helper/compile"
"github.com/hashicorp/otto/helper/packer"
"github.com/hashicorp/otto/helper/schema"
"github.com/hashicorp/otto/helper/terraform"
"github.com/hashicorp/otto/helper/vagrant"
)
//go:generate go-bindata -pkg=rubyapp -nomemcopy -nometadata ./data/...
// App is an implementation of app.App
type App struct{}
func (a *App) Compile(ctx *app.Context) (*app.CompileResult, error) {
var opts compile.AppOptions
custom := &customizations{Opts: &opts}
opts = compile.AppOptions{
Ctx: ctx,
Bindata: &bindata.Data{
Asset: Asset,
AssetDir: AssetDir,
Context: map[string]interface{}{},
},
Customizations: []*compile.Customization{
&compile.Customization{
Type: "ruby",
Callback: custom.processRuby,
Schema: map[string]*schema.FieldSchema{
"ruby_version": &schema.FieldSchema{
Type: schema.TypeString,
Default: "2.2",
Description: "Ruby version to install",
},
},
},
},
}
return compile.App(&opts)
}
func (a *App) Build(ctx *app.Context) error {
return packer.Build(ctx, &packer.BuildOptions{
InfraOutputMap: map[string]string{
"region": "aws_region",
},
})
}
func (a *App) Deploy(ctx *app.Context) error {
return terraform.Deploy(&terraform.DeployOptions{
InfraOutputMap: map[string]string{
"region": "aws_region",
"subnet-private": "private_subnet_id",
"subnet-public": "public_subnet_id",
},
}).Route(ctx)
}
func (a *App) Dev(ctx *app.Context) error {
return vagrant.Dev(&vagrant.DevOptions{
Instructions: strings.TrimSpace(devInstructions),
}).Route(ctx)
}
func (a *App) DevDep(dst, src *app.Context) (*app.DevDep, error) {
return vagrant.DevDep(dst, src, &vagrant.DevDepOptions{})
}
const devInstructions = `
A development environment has been created for writing a generic
Ruby-based app.
Ruby is pre-installed. To work on your project, edit files locally on your
own machine. The file changes will be synced to the development environment.
When you're ready to build your project, run 'otto dev ssh' to enter
the development environment. You'll be placed directly into the working
directory where you can run 'bundle' and 'ruby' as you normally would.
You can access any running web application using the IP above.
`