예제 #1
0
        /// <summary>
        /// Gets image mapping specific to this project
        /// </summary>
        private ImageMapping GetImageMapping()
        {
            var content     = ProjectUtilities.ReadDockerFileConfig();
            var definitions = JsonConvert.DeserializeObject <List <ImageDefinition> >(content);
            var mappings    = definitions.Where(x => x.SdkType.Equals(_project.SdkType)).FirstOrDefault();

            return(mappings.ImageMapping.FirstOrDefault(x => x.TargetFramework.Equals(_project.TargetFramework)));
        }
예제 #2
0
        /// <summary>
        /// Gets image mapping specific to this project
        /// </summary>
        private ImageMapping GetImageMapping()
        {
            var content     = ProjectUtilities.ReadDockerFileConfig();
            var definitions = JsonConvert.DeserializeObject <List <ImageDefinition> >(content);
            var mappings    = definitions.FirstOrDefault(x => x.SdkType.Equals(_project.SdkType));

            if (mappings == null)
            {
                throw new UnsupportedProjectException($"The project with SDK Type {_project.SdkType} is not supported.");
            }

            return(mappings.ImageMapping.FirstOrDefault(x => x.TargetFramework.Equals(_project.TargetFramework))
                   ?? throw new UnsupportedProjectException($"The project with Target Framework {_project.TargetFramework} is not supported."));
        }
예제 #3
0
        /// <summary>
        /// Writes a docker file based on project information
        /// </summary>
        public void WriteDockerFile(string projectDirectory, List <string> projectList)
        {
            var dockerFileTemplate = ProjectUtilities.ReadTemplate();
            var projects           = "";
            var projectPath        = "";
            var projectFolder      = "";

            if (projectList == null)
            {
                projects    = $"COPY [\"{_projectName}\", \"\"]";
                projectPath = _projectName;
            }
            else
            {
                projectList = projectList.Select(x => x.Replace("\\", "/")).ToList();
                for (int i = 0; i < projectList.Count; i++)
                {
                    projects += $"COPY [\"{projectList[i]}\", \"{projectList[i].Substring(0, projectList[i].LastIndexOf("/") + 1)}\"]" + (i < projectList.Count - 1 ? Environment.NewLine : "");
                }

                projectPath = projectList.Where(x => x.EndsWith(_projectName)).FirstOrDefault();
                if (projectPath.LastIndexOf("/") > -1)
                {
                    projectFolder = projectPath.Substring(0, projectPath.LastIndexOf("/"));
                }
            }

            var dockerFile = dockerFileTemplate
                             .Replace("{docker-base-image}", _imageMapping.BaseImage)
                             .Replace("{docker-build-image}", _imageMapping.BuildImage)
                             .Replace("{project-path-list}", projects)
                             .Replace("{project-path}", projectPath)
                             .Replace("{project-folder}", projectFolder)
                             .Replace("{project-name}", _projectName)
                             .Replace("{assembly-name}", _assemblyName);

            File.WriteAllText(Path.Combine(projectDirectory, DockerFileName), dockerFile);
        }