예제 #1
0
        public string Generate(TestGroup testGroup)
        {
            var sb = new StringBuilder();

            sb.AppendLine("#### Image ####");
            sb.AppendLine($"FROM {testGroup.ResourceGroup}");
            sb.AppendLine();

            sb.AppendLine("#### Copy files ####");
            foreach (var copy in testGroup.CopySteps)
            {
                sb.AppendLine($"RUN mkdir -p {copy.Destination.Replace("\\", "/").Replace(WellKnownVars.WorkingDir, WellKnownVars.Values[WellKnownVars.WorkingDir])}");
                sb.AppendLine($"COPY {copy.Source.Replace("\\", "/").Replace(WellKnownVars.BuildRoot, WellKnownVars.Values[WellKnownVars.BuildRoot])} {copy.Destination.Replace("\\", "/").Replace(WellKnownVars.WorkingDir, WellKnownVars.Values[WellKnownVars.WorkingDir])}");
            }
            sb.AppendLine();

            sb.AppendLine("#### Setup Steps ####");
            sb.AppendLine();

            var script     = GenerateScript(testGroup.ExecutionSteps);
            var scriptName = Path.GetFileName(script);

            sb.AppendLine("#### Entry Point ####");
            sb.AppendLine($"COPY {scriptName} /");
            sb.AppendLine($"RUN [\"chmod\", \"+x\", \"/{scriptName}\"]");
            sb.AppendLine($"ENTRYPOINT /{scriptName}");

            var docFile = GetNextFileName(Path.Combine(WellKnownVars.Values[WellKnownVars.TestMapDir], "Dockerfile"));

            File.WriteAllText(docFile, sb.ToString());
            return(docFile);
        }
예제 #2
0
        public TestMap ReadTestMap(string path, int testGroupId)
        {
            var testMap = new TestMap();
            var xreader = new XmlDocument();

            xreader.Load(path);

            var testGroupList = xreader.SelectNodes("/TestMap/TestJobGroup");

            if (testGroupId >= testGroupList.Count)
            {
                return(testMap);
            }

            var testGroups = testGroupList.Cast <XmlNode>().Where((x, i) => i % testGroupId == 0);

            foreach (XmlNode tg in testGroups)
            {
                var testGroupPath = tg.Attributes["ConfigPath"].Value;
                var testGroup     = new TestGroup();

                xreader.Load(Path.Combine(WellKnownVars.Values[WellKnownVars.TestMapDir], testGroupPath));

                var resource = xreader.SelectSingleNode("/TestJobGroup/ResourceSpec/Resource");
                testGroup.ResourceGroup = resource.Attributes["Image"].Value;

                var copyStepsList = xreader.SelectNodes("/TestJobGroup/Setup/BuildFiles/Copy");
                foreach (XmlNode copyStep in copyStepsList)
                {
                    var c = new CopyStep()
                    {
                        Source      = copyStep.Attributes["Src"].Value,
                        Destination = copyStep.Attributes["Dest"].Value
                    };
                    testGroup.CopySteps.Add(c);
                }

                var executionList = xreader.SelectNodes("/TestJobGroup/TestJob/Execution");
                foreach (XmlNode execution in executionList)
                {
                    var e = new Execution()
                    {
                        Type = execution.Attributes["Type"].Value,
                        Args = execution.Attributes["Args"].Value,
                        Path = execution.Attributes["Path"].Value
                    };
                    testGroup.ExecutionSteps.Add(e);
                }

                testMap.TestGroups.Add(testGroup);
            }

            return(testMap);
        }