func NewValidDesiredLRP(guid string) *models.DesiredLRP { myRouterJSON := json.RawMessage(`{"foo":"bar"}`) modTag := models.NewModificationTag("epoch", 0) desiredLRP := &models.DesiredLRP{ ProcessGuid: guid, Domain: "some-domain", RootFs: "some:rootfs", Instances: 1, EnvironmentVariables: []*models.EnvironmentVariable{{Name: "FOO", Value: "bar"}}, CachedDependencies: []*models.CachedDependency{ {Name: "app bits", From: "blobstore.com/bits/app-bits", To: "/usr/local/app", CacheKey: "cache-key", LogSource: "log-source"}, {Name: "app bits with checksum", From: "blobstore.com/bits/app-bits-checksum", To: "/usr/local/app-checksum", CacheKey: "cache-key", LogSource: "log-source", ChecksumAlgorithm: "md5", ChecksumValue: "checksum-value"}, }, Setup: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), StartTimeoutMs: 15000, Monitor: models.WrapAction(models.EmitProgressFor( models.Timeout(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"}))), 10*time.Second, ), "start-message", "success-message", "failure-message", )), DiskMb: 512, MemoryMb: 1024, CpuWeight: 42, Routes: &models.Routes{"my-router": &myRouterJSON}, LogSource: "some-log-source", LogGuid: "some-log-guid", MetricsGuid: "some-metrics-guid", Annotation: "some-annotation", Network: &models.Network{ Properties: map[string]string{ "some-key": "some-value", "some-other-key": "some-other-value", }, }, EgressRules: []*models.SecurityGroupRule{{ Protocol: models.TCPProtocol, Destinations: []string{"1.1.1.1/32", "2.2.2.2/32"}, PortRange: &models.PortRange{Start: 10, End: 16000}, }}, ModificationTag: &modTag, LegacyDownloadUser: "******", TrustedSystemCertificatesPath: "/etc/somepath", VolumeMounts: []*models.VolumeMount{ { Driver: "my-driver", VolumeId: "my-volume", ContainerPath: "/mnt/mypath", Mode: models.BindMountMode_RO, }, }, } err := desiredLRP.Validate() Expect(err).NotTo(HaveOccurred()) return desiredLRP }
func NewValidDesiredLRP(guid string) *models.DesiredLRP { myRouterJSON := json.RawMessage(`{"foo":"bar"}`) modTag := models.NewModificationTag("epoch", 0) desiredLRP := &models.DesiredLRP{ ProcessGuid: guid, Domain: "some-domain", RootFs: "some:rootfs", Instances: 1, EnvironmentVariables: []*models.EnvironmentVariable{{Name: "FOO", Value: "bar"}}, Setup: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), StartTimeout: 15, Monitor: models.WrapAction(models.EmitProgressFor( models.Timeout(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"}))), 10*time.Second, ), "start-message", "success-message", "failure-message", )), DiskMb: 512, MemoryMb: 1024, CpuWeight: 42, Routes: &models.Routes{"my-router": &myRouterJSON}, LogSource: "some-log-source", LogGuid: "some-log-guid", MetricsGuid: "some-metrics-guid", Annotation: "some-annotation", EgressRules: []*models.SecurityGroupRule{{ Protocol: models.TCPProtocol, Destinations: []string{"1.1.1.1/32", "2.2.2.2/32"}, PortRange: &models.PortRange{Start: 10, End: 16000}, }}, ModificationTag: &modTag, } err := desiredLRP.Validate() Expect(err).NotTo(HaveOccurred()) return desiredLRP }
Describe("Try", func() { itSerializesAndDeserializes( `{ "action": { "run": { "path": "echo", "resource_limits":{}, "user": "******", "suppress_log_output": false } } }`, models.WrapAction(models.Try(&models.RunAction{ Path: "echo", User: "******", ResourceLimits: &models.ResourceLimits{}, })), ) Describe("Validate", func() { var tryAction *models.TryAction Context("when the action has 'action' specified", func() { It("is valid", func() { tryAction = &models.TryAction{ Action: &models.Action{ UploadAction: &models.UploadAction{ From: "local_location", To: "web_location", User: "******",
func (backend *traditionalBackend) 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") if request.LifecycleData == nil { return &models.TaskDefinition{}, "", "", ErrMissingLifecycleData } var lifecycleData cc_messages.BuildpackStagingData 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(request, lifecycleData) if err != nil { return &models.TaskDefinition{}, "", "", err } buildpacksOrder := []string{} for _, buildpack := range lifecycleData.Buildpacks { buildpacksOrder = append(buildpacksOrder, buildpack.Key) } skipDetect := len(lifecycleData.Buildpacks) == 1 && lifecycleData.Buildpacks[0].SkipDetect builderConfig := buildpack_app_lifecycle.NewLifecycleBuilderConfig(buildpacksOrder, skipDetect, backend.config.SkipCertVerify) timeout := traditionalTimeout(request, backend.logger) actions := []models.ActionInterface{} //Download app package appDownloadAction := &models.DownloadAction{ Artifact: "app package", From: lifecycleData.AppBitsDownloadUri, To: builderConfig.BuildDir(), User: "******", } actions = append(actions, appDownloadAction) downloadActions := []models.ActionInterface{} downloadNames := []string{} //Download builder downloadActions = append( downloadActions, models.EmitProgressFor( &models.DownloadAction{ From: compilerURL.String(), To: path.Dir(builderConfig.ExecutablePath), CacheKey: fmt.Sprintf("buildpack-%s-lifecycle", lifecycleData.Stack), User: "******", }, "", "", "Failed to set up staging environment", ), ) //Download buildpacks buildpackNames := []string{} downloadMsgPrefix := "" if !skipDetect { downloadMsgPrefix = "No buildpack specified; fetching standard buildpacks to detect and build your application.\n" } for _, buildpack := range lifecycleData.Buildpacks { if buildpack.Name == cc_messages.CUSTOM_BUILDPACK { buildpackNames = append(buildpackNames, buildpack.Url) } else { buildpackNames = append(buildpackNames, buildpack.Name) downloadActions = append( downloadActions, &models.DownloadAction{ Artifact: buildpack.Name, From: buildpack.Url, To: builderConfig.BuildpackPath(buildpack.Key), CacheKey: buildpack.Key, User: "******", }, ) } } downloadNames = append(downloadNames, fmt.Sprintf("buildpacks (%s)", strings.Join(buildpackNames, ", "))) //Download buildpack artifacts cache downloadURL, err := backend.buildArtifactsDownloadURL(lifecycleData) if err != nil { return &models.TaskDefinition{}, "", "", err } if downloadURL != nil { downloadActions = append( downloadActions, models.Try( &models.DownloadAction{ Artifact: "build artifacts cache", From: downloadURL.String(), To: builderConfig.BuildArtifactsCacheDir(), User: "******", }, ), ) downloadNames = append(downloadNames, "build artifacts cache") } downloadMsg := downloadMsgPrefix + fmt.Sprintf("Downloading %s...", strings.Join(downloadNames, ", ")) actions = append(actions, models.EmitProgressFor(models.Parallel(downloadActions...), downloadMsg, "Downloaded buildpacks", "Downloading buildpacks failed")) fileDescriptorLimit := uint64(request.FileDescriptors) //Run Builder runEnv := append(request.Environment, &models.EnvironmentVariable{"CF_STACK", lifecycleData.Stack}) actions = append( actions, models.EmitProgressFor( &models.RunAction{ User: "******", Path: builderConfig.Path(), Args: builderConfig.Args(), Env: runEnv, ResourceLimits: &models.ResourceLimits{ Nofile: &fileDescriptorLimit, }, }, "Staging...", "Staging complete", "Staging failed", ), ) //Upload Droplet uploadActions := []models.ActionInterface{} uploadNames := []string{} uploadURL, err := backend.dropletUploadURL(request, lifecycleData) if err != nil { return &models.TaskDefinition{}, "", "", err } uploadActions = append( uploadActions, &models.UploadAction{ Artifact: "droplet", From: builderConfig.OutputDroplet(), // get the droplet To: addTimeoutParamToURL(*uploadURL, timeout).String(), User: "******", }, ) uploadNames = append(uploadNames, "droplet") //Upload Buildpack Artifacts Cache uploadURL, err = backend.buildArtifactsUploadURL(request, lifecycleData) if err != nil { return &models.TaskDefinition{}, "", "", err } uploadActions = append(uploadActions, models.Try( &models.UploadAction{ Artifact: "build artifacts cache", From: builderConfig.OutputBuildArtifactsCache(), // get the compressed build artifacts cache To: addTimeoutParamToURL(*uploadURL, timeout).String(), User: "******", }, ), ) uploadNames = append(uploadNames, "build artifacts cache") uploadMsg := fmt.Sprintf("Uploading %s...", strings.Join(uploadNames, ", ")) actions = append(actions, models.EmitProgressFor(models.Parallel(uploadActions...), uploadMsg, "Uploading complete", "Uploading failed")) annotationJson, _ := json.Marshal(cc_messages.StagingTaskAnnotation{ Lifecycle: TraditionalLifecycleName, CompletionCallback: request.CompletionCallback, }) taskDefinition := &models.TaskDefinition{ RootFs: models.PreloadedRootFS(lifecycleData.Stack), ResultFile: builderConfig.OutputMetadata(), MemoryMb: int32(request.MemoryMB), DiskMb: int32(request.DiskMB), CpuWeight: uint32(StagingTaskCpuWeight), Action: models.WrapAction(models.Timeout(models.Serial(actions...), timeout)), LogGuid: request.LogGuid, LogSource: TaskLogSource, CompletionCallbackUrl: backend.config.CallbackURL(stagingGuid), EgressRules: request.EgressRules, Annotation: string(annotationJson), Privileged: true, EnvironmentVariables: []*models.EnvironmentVariable{{"LANG", DefaultLANG}}, } logger.Debug("staging-task-request") return taskDefinition, stagingGuid, backend.config.TaskDomain, nil }
}) Describe("Try", func() { itSerializesAndDeserializes( `{ "action": { "run": { "path": "echo", "resource_limits":{}, "user": "******" } } }`, models.Try(&models.Action{RunAction: &models.RunAction{ Path: "echo", User: "******", ResourceLimits: &models.ResourceLimits{}, }}), ) itSerializesAndDeserializes( `{}`, models.Try(nil), ) Describe("Validate", func() { var tryAction models.TryAction Context("when the action has 'action' specified", func() { It("is valid", func() { tryAction = models.TryAction{
CacheKey: "zfirst-buildpack", User: "******", } downloadSecondBuildpackAction = &models.DownloadAction{ Artifact: "asecond", From: "second-buildpack-url", To: "/tmp/buildpacks/58015c32d26f0ad3418f87dd9bf47797", CacheKey: "asecond-buildpack", User: "******", } downloadBuildArtifactsAction = models.Try( &models.DownloadAction{ Artifact: "build artifacts cache", From: "http://example-uri.com/bunny-droppings", To: "/tmp/cache", User: "******", }, ) buildpackOrder = "zfirst-buildpack,asecond-buildpack" uploadDropletAction = &models.UploadAction{ Artifact: "droplet", From: "/tmp/droplet", To: "http://cc-uploader.com/v1/droplet/bunny?" + cc_messages.CcDropletUploadUriKey + "=http%3A%2F%2Fexample-uri.com%2Fdroplet-upload" + "&" + cc_messages.CcTimeoutKey + "=" + fmt.Sprintf("%d", timeout), User: "******", } uploadBuildArtifactsAction = models.Try( &models.UploadAction{
) BeforeEach(func() { processGuid = "process-guid-1" desiredLRP = model_helpers.NewValidDesiredLRP(processGuid) desiredLRP.DeprecatedStartTimeoutS = 15 desiredLRP.Action = models.WrapAction(&models.TimeoutAction{Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), DeprecatedTimeoutNs: 4 * int64(time.Second), }) desiredLRP.Setup = models.WrapAction(&models.TimeoutAction{Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), DeprecatedTimeoutNs: 7 * int64(time.Second), }) desiredLRP.Monitor = models.WrapAction(models.EmitProgressFor( &models.TimeoutAction{ Action: models.WrapAction(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"})))), DeprecatedTimeoutNs: 10 * int64(time.Second), }, "start-message", "success-message", "failure-message", )) }) JustBeforeEach(func() { schedulingInfo, runInfo := desiredLRP.CreateComponents(fakeClock.Now()) runInfo.DeprecatedStartTimeoutS = 15 _, err := json.Marshal(desiredLRP.Routes) Expect(err).NotTo(HaveOccurred())
}) var newValidDesiredLRP = func(guid string) *models.DesiredLRP { myRouterJSON := json.RawMessage(`{"foo":"bar"}`) modTag := models.NewModificationTag("epoch", 0) desiredLRP := &models.DesiredLRP{ ProcessGuid: guid, Domain: "some-domain", RootFs: "some:rootfs", Instances: 1, EnvironmentVariables: []*models.EnvironmentVariable{{Name: "FOO", Value: "bar"}}, Setup: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}), DeprecatedStartTimeoutS: 15, Monitor: models.WrapAction(models.EmitProgressFor( models.Timeout(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"}))), 10*time.Second, ), "start-message", "success-message", "failure-message", )), DiskMb: 512, MemoryMb: 1024, CpuWeight: 42, Routes: &models.Routes{"my-router": &myRouterJSON}, LogSource: "some-log-source", LogGuid: "some-log-guid", MetricsGuid: "some-metrics-guid", Annotation: "some-annotation", EgressRules: []*models.SecurityGroupRule{{