in windows-builder/builder/builder/remote.go [112:147]
func (r *Remote) copyViaBucket(ctx context.Context, inputPath, outputPath string, copyTimeoutMin int) error {
var bucket string
if r.BucketName == nil || *r.BucketName == "" {
// Cloud Build creates a bucket called <PROJECT-ID>_cloudbuild. Put
// the object there.
client := metadata.NewClient(http.DefaultClient)
projectID, err := client.ProjectID()
if err != nil {
return fmt.Errorf("metadata.ProjectID: %v", err)
}
bucket = fmt.Sprintf("%s_cloudbuild", projectID)
} else {
bucket = *r.BucketName
}
object := fmt.Sprintf("windows-builder-%d", time.Now().UnixNano())
gsURL, err := writeZipToBucket(
ctx,
bucket,
object,
inputPath,
)
if err != nil {
return err
}
pwrScript := fmt.Sprintf(`
$ErrorActionPreference = "Stop"
$ProgressPreference = 'SilentlyContinue'
gsutil cp %q c:\workspace.zip
Expand-Archive -Path c:\workspace.zip -DestinationPath c:\workspace -Force
`, gsURL)
// Now tell the Windows VM to download it.
return r.Run(winrm.Powershell(pwrScript), copyTimeoutMin)
}