예제 #1
0
 /// <summary>
 /// レシピモデルをキーにしてレシピViewModelを生成
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="logger"></param>
 /// <param name="recipe">レシピModel</param>
 /// <returns>レシピViewModel</returns>
 internal static IRecipeViewModel CreateRecipeViewModelInstance(ISettings settings, ILogger logger, IRecipe recipe)
 {
     if (recipe == null)
     {
         return(null);
     }
     return(DispatcherHelper.UIDispatcher.Invoke(() => {
         return RecipeSitePlugins
         .Single(p => p.ModelType == recipe.GetType())
         .CreateRecipeViewModelInstance(settings, logger, recipe);
     }));
 }
예제 #2
0
        public RecipeModel ConvertRecipe(IRecipe recipe)
        {
            // Transform to DTO and transmit
            var converted = new RecipeModel
            {
                Id         = recipe.Id,
                Name       = recipe.Name,
                Type       = recipe.GetType().Name,
                State      = recipe.State,
                Revision   = recipe.Revision,
                Properties = EntryConvert.EncodeObject(recipe, RecipeSerialization),
                IsClone    = recipe.Classification.HasFlag(RecipeClassification.Clone)
            };

            switch (recipe.Classification & RecipeClassification.CloneFilter)
            {
            case RecipeClassification.Unset:
                converted.Classification = RecipeClassificationModel.Unset;
                break;

            case RecipeClassification.Default:
                converted.Classification = RecipeClassificationModel.Default;
                break;

            case RecipeClassification.Alternative:
                converted.Classification = RecipeClassificationModel.Alternative;
                break;

            case RecipeClassification.Intermediate:
                converted.Classification = RecipeClassificationModel.Intermediate;
                break;

            case RecipeClassification.Part:
                converted.Classification = RecipeClassificationModel.Part;
                break;
            }

            var wpRecipe = recipe as IWorkplanRecipe;

            if (wpRecipe?.Workplan != null)
            {
                converted.WorkplanId    = wpRecipe.Workplan.Id;
                converted.WorkplanModel = ConvertWorkplan(wpRecipe.Workplan);
            }


            return(converted);
        }
예제 #3
0
        /// <inheritdoc/>
        public V1Pod BuildFrom(ImprovementContext context, IRecipe recipe)
        {
            var pod = new V1Pod {
                Metadata = new V1ObjectMeta {
                    Name = context.Improvement.Id.ToString(),
                    NamespaceProperty = "dolittle-builds",
                    Labels            = new Dictionary <string, string> {
                        { PodLabels.RecipeType, recipe.GetType().Name },
                        { PodLabels.Version, context.Version },
                        { PodLabels.Tenant, context.Tenant.ToString() },
                        { PodLabels.Improvement, context.Improvement.Id.ToString() },
                        { PodLabels.Improvable, context.Improvement.Improvable.ToString() },
                    },
                },

                Spec = new V1PodSpec {
                    RestartPolicy = "Never",

                    Containers = new [] {
                        new V1Container {
                            Name    = "done",
                            Image   = "alpine:3.9",
                            Command = new [] { "/bin/true" },
                        },
                    },

                    Volumes = new [] {
                        new V1Volume {
                            Name      = "azure",
                            AzureFile = new V1AzureFileVolumeSource {
                                ShareName        = "continuousimprovement",
                                SecretName       = "azure-storage-secret",
                                ReadOnlyProperty = false,
                            },
                        },
                        new V1Volume {
                            Name     = "workdir",
                            EmptyDir = new V1EmptyDirVolumeSource {
                            },
                        },
                    },
                },
            };

            var containers = pod.Spec.InitContainers = new List <V1Container>();

            // Copy the loghandler binary to the workdir before anything else
            containers.Add(new V1Container {
                Name         = "copy-loghandler-to-workdir",
                Image        = "alpine:3.9",
                Command      = new [] { "/bin/cp", "/azure-binaries/loghandler", "/workdir-binaries/loghandler" },
                VolumeMounts = new [] {
                    new V1VolumeMount {
                        Name      = "azure",
                        SubPath   = "binaries",
                        MountPath = "/azure-binaries/",
                    },
                    new V1VolumeMount {
                        Name      = "workdir",
                        SubPath   = "binaries",
                        MountPath = "/workdir-binaries/",
                    },
                },
            });

            // Prepare the actual build steps
            StepNumber stepNumber = 0;

            recipe.GetStepsFor(context).ForEach(step => {
                StepNumber subStepNumber = 0;
                step.GetContainersFor(stepNumber, context).ForEach(subStep => {
                    containers.Add(subStep);

                    // Prepend the name of the container with step-N-M- to identify the step later
                    subStep.Name = $"step-{stepNumber}-{subStepNumber}-{subStep.Name}";

                    // Use the log handler to run the actual command
                    ThrowIfNoCommandIsSetForStepContainer(subStep);
                    subStep.Command = subStep.Command.Prepend("/dolittle/loghandler").ToList();

                    if (subStep.Env == null)
                    {
                        subStep.Env = new List <V1EnvVar>();
                    }
                    subStep.Env.Add(new V1EnvVar {
                        Name = "DOLITTLE_BUILD_LOG_RAW_PATH", Value = $"/steps/{stepNumber}.log"
                    });
                    subStep.Env.Add(new V1EnvVar {
                        Name = "DOLITTLE_BUILD_LOG_PARSED_PATH", Value = $"/steps/{stepNumber}.json"
                    });
                    subStep.Env.Add(new V1EnvVar {
                        Name = "DOLITTLE_BUILD_LOG_PARSER", Value = step.GetLogParserNameFor(stepNumber, context)
                    });

                    if (subStep.VolumeMounts == null)
                    {
                        subStep.VolumeMounts = new List <V1VolumeMount>();
                    }
                    subStep.VolumeMounts = subStep.VolumeMounts.Concat(new []   {
                        new V1VolumeMount {
                            Name      = "azure",
                            SubPath   = context.GetImprovementSubPath("steps"),
                            MountPath = "/steps/",
                        },
                        new V1VolumeMount {
                            Name      = "workdir",
                            SubPath   = "binaries",
                            MountPath = "/dolittle/",
                        },
                    }).ToList();

                    subStepNumber++;
                });
                stepNumber++;
            });

            return(pod);
        }