Beispiel #1
0
        private static void GenerateTar(string linux_temporary_folder, string tmp_rootfs_name, string distro_name)
        {
            string session_id             = UserConfig.session_id;
            string win10_temporary_folder = UserConfig.linux_windows_temp_path;
            string win10_imagepath        = UserConfig.linux_windows_image_path;

            string[] commands2 =
            {
                Linux_Commands.Change_directory(win10_temporary_folder),
                Linux_Commands.Create_directory_tree(linux_temporary_folder),
                Linux_Commands.CopyFile(tmp_rootfs_name,                      linux_temporary_folder),
                Linux_Commands.Change_directory(linux_temporary_folder),
                Linux_Commands.Untar_rootfs_joined(tmp_rootfs_name,           linux_temporary_folder),
                Linux_Commands.EraseFile(tmp_rootfs_name),
                Linux_Commands.Tar_rootfs(distro_name,                        session_id),
                Linux_Commands.Create_directory_tree(win10_imagepath),
                Linux_Commands.CopyFile(Linux_Commands.RootfsName(distro_name,session_id),             win10_imagepath),
                Linux_Commands.EraseDirectory(linux_temporary_folder),
                Linux_Commands.Change_directory(win10_temporary_folder),
                Linux_Commands.EraseFile(tmp_rootfs_name)
            };

            var command = Linux_Commands.GenerateCommand(commands2);

            //Console.WriteLine(command);
            Commands.RunProgram(command);
        }
Beispiel #2
0
        public static bool DownloadImageUsingDocker()
        {
            string linux_temporary_folder    = UserConfig.linux_temporary_folder;
            string temp_linux_path_extracted = linux_temporary_folder + "/image";
            string win10_imagepath           = UserConfig.wsl_windows_image_path;

            string[] commands =
            {
                Linux_Commands.Create_directory_tree(win10_imagepath),
                Linux_Commands.Create_directory_tree(linux_temporary_folder),
                Linux_Commands.Create_directory_tree(temp_linux_path_extracted),
                Linux_Commands.Change_directory(linux_temporary_folder),
                Linux_Commands.StartDockerService(),
                Linux_Commands.DockerPull(UserConfig.repo_image_tag)
            };

            var command = Linux_Commands.GenerateCommand(commands);
            var res     = Commands.BashRunCommand_stdout(command);

            if (res.Contains("docker login"))
            {
                Console.WriteLine("repository does not exist or may require 'wsld docker login'");
                Commands.BashRunCommand_stdout(Linux_Commands.EraseDirectory(linux_temporary_folder));
                System.Environment.Exit(0);
            }

            string[] commands2 =
            {
                Linux_Commands.Change_directory(linux_temporary_folder),
                Linux_Commands.DockerSave(UserConfig.repo_image,           "docker"),
                Linux_Commands.UnTar("docker"),
                Linux_Commands.UnTarAllFilesThatMatchesIntoFolder("*.tar", linux_temporary_folder, temp_linux_path_extracted),
                Linux_Commands.Change_directory(temp_linux_path_extracted),
                Linux_Commands.CreateUser(),
                Linux_Commands.Tar_rootfs(UserConfig.wsld_distro_name,     UserConfig.session_id),
                Linux_Commands.MoveFile(UserConfig.rootfs_name,            win10_imagepath),
                Linux_Commands.EraseDirectory(linux_temporary_folder),
                "docker rmi -f $(docker images -q)",
            };
            var command2 = Linux_Commands.GenerateCommand(commands2);

            Console.WriteLine("Generating tar from docker...");
            Commands.BashRunCommand_stdout(command2);

            Console.WriteLine("Generated.");

            return(true);
        }
Beispiel #3
0
        public static string wslToDockerHub()
        {
            string wsl_tmp = UserConfig.linux_temporary_folder;

            string[] command_1 =
            {
                Linux_Commands.Create_directory_tree(wsl_tmp),
                Linux_Commands.Change_directory(wsl_tmp),
                "wsl.exe --export " + UserConfig.wsld_distro_name + " import_docker.tar.gz"
            };

            Commands.BashRunCommand_stdout(Linux_Commands.GenerateCommand(command_1));

            if (!Commands.CheckIfFileExists(wsl_tmp + "/import_docker.tar.gz"))
            {
                return("ERROR: The image could not be exported from WSL");
            }

            string marker = "@@@@@@@@@@";

            string[] command_2 =
            {
                Linux_Commands.Change_directory(wsl_tmp),
                "service docker start",
                "docker import import_docker.tar.gz " + UserConfig.repo_image_tag,
                "echo " + marker,
                "docker push " + UserConfig.repo_image_tag,
                "echo " + marker,
                "docker rmi -f $(docker images -q)",
                Linux_Commands.EraseDirectory(wsl_tmp)
            };

            var ret = Commands.BashRunCommand_stdout(Linux_Commands.GenerateCommand(command_2));


            int    pFrom  = ret.IndexOf(marker) + marker.Length;
            int    pTo    = ret.LastIndexOf(marker);
            string result = ret.Substring(pFrom, pTo - pFrom);

            if (result.Contains("Pushed") || result.Contains("Mounted") || result.Contains("exists"))
            {
                return("Success.");
            }


            return("Couldn't push the image to the repo");
        }
Beispiel #4
0
        public static bool BuildDockerfile(bool remote = false)
        {
            string linux_temporary_folder = UserConfig.linux_temporary_folder + "/";

            string from = remote ? UserConfig.dockerfile_path : ". -f " + UserConfig.dockerfile_path;


            string docker_build_command = "docker build " + from + " -t " + UserConfig.repo_image_tag;


            string[] commands;

            string[] remoteCommands =
            {
                Linux_Commands.Create_directory_tree(linux_temporary_folder),
                Linux_Commands.Change_directory(linux_temporary_folder),
                Linux_Commands.StartDockerService(),
                docker_build_command,
                Linux_Commands.EraseDirectory(linux_temporary_folder)
            };

            string[] localCommands =
            {
                Linux_Commands.Create_directory_tree(linux_temporary_folder),
                Linux_Commands.Change_directory(linux_temporary_folder),
                Linux_Commands.StartDockerService(),
                Linux_Commands.CopyDir(UserConfig.wsl_PWD + "/*",            linux_temporary_folder),
                docker_build_command,
                Linux_Commands.EraseDirectory(linux_temporary_folder)
            };

            commands = remote ? remoteCommands : localCommands;

            var com    = Linux_Commands.GenerateCommand(commands);
            var stderr = Commands.BashRunCommand_stderr(com);

            if (stderr == null || stderr.Length == 0)
            {
                return(false);
            }
            return(true);
        }
Beispiel #5
0
        //string config = get_layers["config"]["digest"].ToString();
        //var blobs = GetBlobs(config, repository);
        public static string DownloadAndGenerateImage(string repo, string image, string tag, string distro_name)
        {
            string session_id = UserConfig.session_id;
            string repository = repo + "/" + image;


            SetupAuth(repository);


            string temp_rootfs_name     = Linux_Commands.TemporalRootfsName(distro_name, session_id);
            string win10_temp_file_path = UserConfig.windows_temp_path + temp_rootfs_name;



            var layers = AskForLayers(repository, tag)["layers"];

            Console.WriteLine("Image with " + layers.Count() + " layers");
            Console.WriteLine("Downloading...");
            int i = 1;

            foreach (var layer in layers)
            {
                Fops.WriteToFileAppend(DownloadLayer(layer["digest"].ToString(), repository), win10_temp_file_path);
                Console.WriteLine("Downloaded " + i++ + " of " + layers.Count());
            }
            Console.WriteLine("Downloaded.");

            var linux_temporary_folder = "/tmp/wsld/" + distro_name + session_id;

            Console.WriteLine("Generating tar...");
            GenerateTar(linux_temporary_folder, temp_rootfs_name, distro_name);
            Console.WriteLine("Generated.");
            File.Delete(win10_temp_file_path);

            return(Path.Combine(UserConfig.windows_image_path, Linux_Commands.RootfsName(distro_name, session_id)));
        }