本文整理汇总了Golang中github.com/cloudfoundry-incubator/runtime-schema/cc_messages.StagingRequestFromCC.EgressRules方法的典型用法代码示例。如果您正苦于以下问题:Golang StagingRequestFromCC.EgressRules方法的具体用法?Golang StagingRequestFromCC.EgressRules怎么用?Golang StagingRequestFromCC.EgressRules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/runtime-schema/cc_messages.StagingRequestFromCC
的用法示例。
在下文中一共展示了StagingRequestFromCC.EgressRules方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BuildRecipe
func (backend *dockerBackend) BuildRecipe(stagingGuid string, request cc_messages.StagingRequestFromCC) (*models.TaskDefinition, string, string, error) {
logger := backend.logger.Session("build-recipe", lager.Data{"app-id": request.AppId, "staging-guid": stagingGuid})
logger.Info("staging-request")
var lifecycleData cc_messages.DockerStagingData
err := json.Unmarshal(*request.LifecycleData, &lifecycleData)
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
err = backend.validateRequest(request, lifecycleData)
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
compilerURL, err := backend.compilerDownloadURL()
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
cachedDependencies := []*models.CachedDependency{
&models.CachedDependency{
From: compilerURL.String(),
To: path.Dir(DockerBuilderExecutablePath),
CacheKey: "docker-lifecycle",
},
}
runActionArguments := []string{
"-outputMetadataJSONFilename", DockerBuilderOutputPath,
"-dockerRef", lifecycleData.DockerImageUrl,
}
if len(backend.config.InsecureDockerRegistries) > 0 {
insecureDockerRegistries := strings.Join(backend.config.InsecureDockerRegistries, ",")
runActionArguments = append(runActionArguments, "-insecureDockerRegistries", insecureDockerRegistries)
}
fileDescriptorLimit := uint64(request.FileDescriptors)
runAs := "vcap"
actions := []models.ActionInterface{}
if cacheDockerImage(request.Environment) {
runAs = "root"
additionalEgressRules, additionalArgs, err := cachingEgressRulesAndArgs(
logger,
backend.config.DockerRegistryAddress,
backend.config.ConsulCluster,
lifecycleData,
)
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
runActionArguments = append(runActionArguments, additionalArgs...)
request.EgressRules = append(request.EgressRules, additionalEgressRules...)
actions = append(
actions,
models.EmitProgressFor(
&models.RunAction{
Path: MountCgroupsPath,
ResourceLimits: &models.ResourceLimits{
Nofile: &fileDescriptorLimit,
},
User: runAs,
},
"Preparing docker daemon...",
"",
"Failed to set up docker environment",
),
)
}
actions = append(
actions,
models.EmitProgressFor(
&models.RunAction{
Path: DockerBuilderExecutablePath,
Args: runActionArguments,
Env: request.Environment,
ResourceLimits: &models.ResourceLimits{
Nofile: &fileDescriptorLimit,
},
User: runAs,
},
"Staging...",
"Staging Complete",
"Staging Failed",
),
)
annotationJson, _ := json.Marshal(cc_messages.StagingTaskAnnotation{
Lifecycle: DockerLifecycleName,
CompletionCallback: request.CompletionCallback,
})
taskDefinition := &models.TaskDefinition{
//.........这里部分代码省略.........
示例2: BuildRecipe
func (backend *dockerBackend) BuildRecipe(stagingGuid string, request cc_messages.StagingRequestFromCC) (*models.TaskDefinition, string, string, error) {
logger := backend.logger.Session("build-recipe", lager.Data{"app-id": request.AppId, "staging-guid": stagingGuid})
logger.Info("staging-request")
var lifecycleData cc_messages.DockerStagingData
err := json.Unmarshal(*request.LifecycleData, &lifecycleData)
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
err = backend.validateRequest(request, lifecycleData)
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
compilerURL, err := backend.compilerDownloadURL()
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
cacheDockerImage := false
for _, envVar := range request.Environment {
if envVar.Name == "DIEGO_DOCKER_CACHE" && envVar.Value == "true" {
cacheDockerImage = true
break
}
}
actions := []models.ActionInterface{}
//Download builder
actions = append(
actions,
models.EmitProgressFor(
&models.DownloadAction{
From: compilerURL.String(),
To: path.Dir(DockerBuilderExecutablePath),
CacheKey: "docker-lifecycle",
User: "vcap",
},
"",
"",
"Failed to set up docker environment",
),
)
runActionArguments := []string{"-outputMetadataJSONFilename", DockerBuilderOutputPath, "-dockerRef", lifecycleData.DockerImageUrl}
runAs := "vcap"
if cacheDockerImage {
runAs = "root"
host, port, err := net.SplitHostPort(backend.config.DockerRegistryAddress)
if err != nil {
logger.Debug("invalid docker registry address", lager.Data{"address": backend.config.DockerRegistryAddress, "error": err.Error()})
return &models.TaskDefinition{}, "", "", ErrInvalidDockerRegistryAddress
}
registryServices, err := getDockerRegistryServices(backend.config.ConsulCluster, backend.logger)
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
registryRules := addDockerRegistryRules(request.EgressRules, registryServices)
request.EgressRules = append(request.EgressRules, registryRules...)
registryIPs := strings.Join(buildDockerRegistryAddresses(registryServices), ",")
runActionArguments, err = addDockerCachingArguments(runActionArguments, registryIPs, backend.config.InsecureDockerRegistry, host, port, lifecycleData)
if err != nil {
return &models.TaskDefinition{}, "", "", err
}
}
fileDescriptorLimit := uint64(request.FileDescriptors)
// Run builder
actions = append(
actions,
models.EmitProgressFor(
&models.RunAction{
Path: DockerBuilderExecutablePath,
Args: runActionArguments,
Env: request.Environment,
ResourceLimits: &models.ResourceLimits{
Nofile: &fileDescriptorLimit,
},
User: runAs,
},
"Staging...",
"Staging Complete",
"Staging Failed",
),
)
annotationJson, _ := json.Marshal(cc_messages.StagingTaskAnnotation{
Lifecycle: DockerLifecycleName,
})
taskDefinition := &models.TaskDefinition{
RootFs: models.PreloadedRootFS(backend.config.DockerStagingStack),
ResultFile: DockerBuilderOutputPath,
//.........这里部分代码省略.........