本文整理汇总了Golang中github.com/hashicorp/otto/appfile.File.ActiveInfrastructure方法的典型用法代码示例。如果您正苦于以下问题:Golang File.ActiveInfrastructure方法的具体用法?Golang File.ActiveInfrastructure怎么用?Golang File.ActiveInfrastructure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hashicorp/otto/appfile.File
的用法示例。
在下文中一共展示了File.ActiveInfrastructure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: appContext
func (c *Core) appContext(f *appfile.File) (*app.Context, error) {
// Whether or not this is the root Appfile
root := f.ID == c.appfile.ID
// We need the configuration for the active infrastructure
// so that we can build the tuple below
config := f.ActiveInfrastructure()
if config == nil {
return nil, fmt.Errorf(
"infrastructure not found in appfile: %s",
f.Project.Infrastructure)
}
// The tuple we're looking for is the application type, the
// infrastructure type, and the infrastructure flavor. Build that
// tuple.
tuple := app.Tuple{
App: f.Application.Type,
Infra: config.Type,
InfraFlavor: config.Flavor,
}
// The output directory for data. This is either the main app so
// it goes directly into "app" or it is a dependency and goes into
// a dep folder.
outputDir := filepath.Join(c.compileDir, "app")
if !root {
outputDir = filepath.Join(
c.compileDir, fmt.Sprintf("dep-%s", f.ID))
}
// The cache directory for this app
cacheDir := filepath.Join(c.dataDir, "cache", f.ID)
if err := os.MkdirAll(cacheDir, 0755); err != nil {
return nil, fmt.Errorf(
"error making cache directory '%s': %s",
cacheDir, err)
}
// The directory for global data
globalDir := filepath.Join(c.dataDir, "global-data")
if err := os.MkdirAll(globalDir, 0755); err != nil {
return nil, fmt.Errorf(
"error making global data directory '%s': %s",
globalDir, err)
}
// Build the contexts for the foundations. We use this
// to also compile the list of foundation dirs.
foundationDirs := make([]string, len(config.Foundations))
for i, f := range config.Foundations {
foundationDirs[i] = filepath.Join(
outputDir, fmt.Sprintf("foundation-%s", f.Name))
}
// Get the dev IP address
ipDB := &localaddr.CachedDB{
DB: &localaddr.DB{Path: filepath.Join(c.dataDir, "ip.db")},
CachePath: filepath.Join(c.localDir, "dev_ip"),
}
ip, err := ipDB.IP()
if err != nil {
return nil, fmt.Errorf(
"Error retrieving dev IP address: %s", err)
}
// Get the metadata
var compileResult *app.CompileResult
md, err := c.compileMetadata()
if err != nil {
return nil, fmt.Errorf(
"Error loading compilation metadata: %s", err)
}
if md != nil {
if root {
compileResult = md.App
} else {
compileResult = md.AppDeps[f.ID]
}
}
return &app.Context{
CompileResult: compileResult,
Dir: outputDir,
CacheDir: cacheDir,
LocalDir: c.localDir,
GlobalDir: globalDir,
Tuple: tuple,
Application: f.Application,
DevIPAddress: ip.String(),
Shared: context.Shared{
Appfile: f,
FoundationDirs: foundationDirs,
InstallDir: filepath.Join(c.dataDir, "binaries"),
Directory: c.dir,
Ui: c.ui,
},
}, nil
}
示例2: Run
//.........这里部分代码省略.........
}
detectorDir := filepath.Join(dataDir, DefaultLocalDataDetectorDir)
log.Printf("[DEBUG] loading detectors from: %s", detectorDir)
detectConfig, err := detect.ParseDir(detectorDir)
if err != nil {
c.Ui.Error(err.Error())
return 1
}
if detectConfig == nil {
detectConfig = &detect.Config{}
}
err = detectConfig.Merge(&detect.Config{Detectors: c.Detectors})
if err != nil {
c.Ui.Error(err.Error())
return 1
}
// Load the default Appfile so we can merge in any defaults into
// the loaded Appfile (if there is one).
appDef, err := appfile.Default(filepath.Dir(flagAppfile), detectConfig)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error loading Appfile: %s", err))
return 1
}
// If there was no loaded Appfile and we don't have an application
// type then we weren't able to detect the type. Error.
if app == nil && appDef.Application.Type == "" {
c.Ui.Error(strings.TrimSpace(errCantDetectType))
return 1
}
// Merge the appfiles
if app != nil {
if err := appDef.Merge(app); err != nil {
c.Ui.Error(fmt.Sprintf(
"Error loading Appfile: %s", err))
return 1
}
}
app = appDef
// Compile the Appfile
ui.Header("Fetching all Appfile dependencies...")
capp, err := appfile.Compile(app, &appfile.CompileOpts{
Dir: filepath.Join(
filepath.Dir(app.Path), DefaultOutputDir, DefaultOutputDirCompiledAppfile),
Detect: detectConfig,
Callback: c.compileCallback(ui),
})
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error compiling Appfile: %s", err))
return 1
}
// Get a core
core, err := c.Core(capp)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error loading core: %s", err))
return 1
}
// Get the active infrastructure just for UI reasons
infra := app.ActiveInfrastructure()
// Before the compilation, output to the user what is going on
ui.Header("Compiling...")
ui.Message(fmt.Sprintf(
"Application: %s (%s)",
app.Application.Name,
app.Application.Type))
ui.Message(fmt.Sprintf("Project: %s", app.Project.Name))
ui.Message(fmt.Sprintf(
"Infrastructure: %s (%s)",
infra.Type,
infra.Flavor))
ui.Message("")
// Compile!
if err := core.Compile(); err != nil {
c.Ui.Error(fmt.Sprintf(
"Error compiling: %s", err))
return 1
}
// Success!
ui.Header("[green]Compilation success!")
ui.Message(fmt.Sprintf(
"[green]This means that Otto is now ready to start a development environment,\n" +
"deploy this application, build the supporting infastructure, and\n" +
"more. See the help for more information.\n\n" +
"Supporting files to enable Otto to manage your application from\n" +
"development to deployment have been placed in the output directory.\n" +
"These files can be manually inspected to determine what Otto will do."))
return 0
}