本文整理匯總了Golang中github.com/mitchellh/packer/packer.Environment.Cache方法的典型用法代碼示例。如果您正苦於以下問題:Golang Environment.Cache方法的具體用法?Golang Environment.Cache怎麽用?Golang Environment.Cache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mitchellh/packer/packer.Environment
的用法示例。
在下文中一共展示了Environment.Cache方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
//.........這裏部分代碼省略.........
env.Ui().Error(err.Error())
return 1
}
}
// Run all the builds in parallel and wait for them to complete
var interruptWg, wg sync.WaitGroup
interrupted := false
artifacts := make(map[string][]packer.Artifact)
errors := make(map[string]error)
for _, b := range builds {
// Increment the waitgroup so we wait for this item to finish properly
wg.Add(1)
// Handle interrupts for this build
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
defer signal.Stop(sigCh)
go func(b packer.Build) {
<-sigCh
interruptWg.Add(1)
defer interruptWg.Done()
interrupted = true
log.Printf("Stopping build: %s", b.Name())
b.Cancel()
log.Printf("Build cancelled: %s", b.Name())
}(b)
// Run the build in a goroutine
go func(b packer.Build) {
defer wg.Done()
name := b.Name()
log.Printf("Starting build run: %s", name)
ui := buildUis[name]
runArtifacts, err := b.Run(ui, env.Cache())
if err != nil {
ui.Error(fmt.Sprintf("Build '%s' errored: %s", name, err))
errors[name] = err
} else {
ui.Say(fmt.Sprintf("Build '%s' finished.", name))
artifacts[name] = runArtifacts
}
}(b)
if cfgDebug {
log.Printf("Debug enabled, so waiting for build to finish: %s", b.Name())
wg.Wait()
}
if interrupted {
log.Println("Interrupted, not going to start any more builds.")
break
}
}
// Wait for both the builds to complete and the interrupt handler,
// if it is interrupted.
log.Printf("Waiting on builds to complete...")
wg.Wait()
log.Printf("Builds completed. Waiting on interrupt barrier...")
interruptWg.Wait()
if interrupted {
env.Ui().Say("Cleanly cancelled builds after being interrupted.")
return 1
}
if len(errors) > 0 {
env.Ui().Error("\n==> Some builds didn't complete successfully and had errors:")
for name, err := range errors {
env.Ui().Error(fmt.Sprintf("--> %s: %s", name, err))
}
}
if len(artifacts) > 0 {
env.Ui().Say("\n==> Builds finished. The artifacts of successful builds are:")
for name, buildArtifacts := range artifacts {
for _, artifact := range buildArtifacts {
var message bytes.Buffer
fmt.Fprintf(&message, "--> %s: ", name)
if artifact != nil {
fmt.Fprintf(&message, artifact.String())
} else {
fmt.Fprint(&message, "<nothing>")
}
env.Ui().Say(message.String())
}
}
} else {
env.Ui().Say("\n==> Builds finished but no artifacts were created.")
}
return 0
}
示例2: Run
//.........這裏部分代碼省略.........
}
// Run all the builds in parallel and wait for them to complete
var interruptWg, wg sync.WaitGroup
interrupted := false
artifacts := make(map[string][]packer.Artifact)
errors := make(map[string]error)
for _, b := range builds {
// Increment the waitgroup so we wait for this item to finish properly
wg.Add(1)
// Handle interrupts for this build
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
defer signal.Stop(sigCh)
go func(b packer.Build) {
<-sigCh
interruptWg.Add(1)
defer interruptWg.Done()
interrupted = true
log.Printf("Stopping build: %s", b.Name())
b.Cancel()
log.Printf("Build cancelled: %s", b.Name())
}(b)
// Run the build in a goroutine
go func(b packer.Build) {
defer wg.Done()
name := b.Name()
log.Printf("Starting build run: %s", name)
ui := buildUis[name]
runArtifacts, err := b.Run(ui, env.Cache())
if err != nil {
ui.Error(fmt.Sprintf("Build '%s' errored: %s", name, err))
errors[name] = err
} else {
ui.Say(fmt.Sprintf("Build '%s' finished.", name))
artifacts[name] = runArtifacts
}
}(b)
if cfgDebug {
log.Printf("Debug enabled, so waiting for build to finish: %s", b.Name())
wg.Wait()
}
if interrupted {
log.Println("Interrupted, not going to start any more builds.")
break
}
}
// Wait for both the builds to complete and the interrupt handler,
// if it is interrupted.
log.Printf("Waiting on builds to complete...")
wg.Wait()
log.Printf("Builds completed. Waiting on interrupt barrier...")
interruptWg.Wait()
if interrupted {
env.Ui().Say("Cleanly cancelled builds after being interrupted.")
return 1