github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/app/java/app.go (about)

     1  package javaapp
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/hashicorp/otto/app"
     7  	"github.com/hashicorp/otto/appfile"
     8  	javaSP "github.com/hashicorp/otto/builtin/scriptpack/java"
     9  	stdSP "github.com/hashicorp/otto/builtin/scriptpack/stdlib"
    10  	"github.com/hashicorp/otto/foundation"
    11  	"github.com/hashicorp/otto/helper/bindata"
    12  	"github.com/hashicorp/otto/helper/compile"
    13  	"github.com/hashicorp/otto/helper/packer"
    14  	"github.com/hashicorp/otto/helper/schema"
    15  	"github.com/hashicorp/otto/helper/terraform"
    16  	"github.com/hashicorp/otto/helper/vagrant"
    17  	"github.com/hashicorp/otto/scriptpack"
    18  )
    19  
    20  //go:generate go-bindata -pkg=javaapp -nomemcopy -nometadata ./data/...
    21  
    22  // App is an implementation of app.App
    23  type App struct{}
    24  
    25  func (a *App) Meta() (*app.Meta, error) {
    26  	return Meta, nil
    27  }
    28  
    29  func (a *App) Implicit(ctx *app.Context) (*appfile.File, error) {
    30  	return nil, nil
    31  }
    32  
    33  // Compile ...
    34  func (a *App) Compile(ctx *app.Context) (*app.CompileResult, error) {
    35  	var opts compile.AppOptions
    36  	custom := &customizations{Opts: &opts}
    37  	opts = compile.AppOptions{
    38  		Ctx: ctx,
    39  		Result: &app.CompileResult{
    40  			Version: 1,
    41  		},
    42  		FoundationConfig: foundation.Config{
    43  			ServiceName: ctx.Application.Name,
    44  		},
    45  		Bindata: &bindata.Data{
    46  			Asset:    Asset,
    47  			AssetDir: AssetDir,
    48  			Context:  map[string]interface{}{},
    49  		},
    50  		ScriptPacks: []*scriptpack.ScriptPack{
    51  			&stdSP.ScriptPack,
    52  			&javaSP.ScriptPack,
    53  		},
    54  		Customization: (&compile.Customization{
    55  			Callback: custom.processDev,
    56  			Schema: map[string]*schema.FieldSchema{
    57  				"gradle_version": &schema.FieldSchema{
    58  					Type:        schema.TypeString,
    59  					Default:     "2.8",
    60  					Description: "Java version to install",
    61  				},
    62  				"maven_version": &schema.FieldSchema{
    63  					Type:        schema.TypeString,
    64  					Default:     "3.3.9",
    65  					Description: "Maven version to install",
    66  				},
    67  			},
    68  		}).Merge(compile.VagrantCustomizations(&opts)),
    69  	}
    70  
    71  	return compile.App(&opts)
    72  }
    73  
    74  // Build ...
    75  func (a *App) Build(ctx *app.Context) error {
    76  	return packer.Build(ctx, &packer.BuildOptions{
    77  		InfraOutputMap: map[string]string{
    78  			"region": "aws_region",
    79  		},
    80  	})
    81  }
    82  
    83  // Deploy ...
    84  func (a *App) Deploy(ctx *app.Context) error {
    85  	return terraform.Deploy(&terraform.DeployOptions{
    86  		InfraOutputMap: map[string]string{
    87  			"region":         "aws_region",
    88  			"subnet-private": "private_subnet_id",
    89  			"subnet-public":  "public_subnet_id",
    90  		},
    91  	}).Route(ctx)
    92  }
    93  
    94  // Dev ...
    95  func (a *App) Dev(ctx *app.Context) error {
    96  	return vagrant.Dev(&vagrant.DevOptions{
    97  		Instructions: strings.TrimSpace(devInstructions),
    98  	}).Route(ctx)
    99  }
   100  
   101  // DevDep ...
   102  func (a *App) DevDep(dst, src *app.Context) (*app.DevDep, error) {
   103  	return vagrant.DevDep(dst, src, &vagrant.DevDepOptions{})
   104  }
   105  
   106  const devInstructions = `
   107  A development environment has been created for writing a generic Java based
   108  application using Java as the build system. For this development environment,
   109  Java is pre-installed. To work on your project, edit files locally on your own
   110  machine. The file changes will be synced to the development environment.
   111  
   112  When you're ready to build or test your project, run 'otto dev ssh'
   113  to enter the development environment. You'll be placed directly into the
   114  working directory where you can run "gradle init", "gradle build", etc.
   115  
   116  You can access the environment from this machine using the IP address above.
   117  For example, if your app is running on port 5000, then access it using the
   118  IP above plus that port.
   119  `