public static string ResolveBinary(this string dockerCommand, bool preferMachine = false, bool forceResolve = false)
        {
            if (forceResolve)
            {
                _binaryResolver = new DockerBinariesResolver(_sudoMechanism, _sudoPassword);
            }

            var binary = _binaryResolver.Resolve(dockerCommand, preferMachine);

            if (FdOs.IsWindows() || binary.Sudo == SudoMechanism.None)
            {
                return(binary.FqPath);
            }

            string cmd;

            if (binary.Sudo == SudoMechanism.NoPassword)
            {
                cmd = $"sudo {binary.FqPath}";
            }
            else
            {
                cmd = $"echo {binary.SudoPassword} | sudo -S {binary.FqPath}";
            }

            return(cmd);
        }
Example #2
0
        public void DiscoverBinariesShallWork()
        {
            var resolver = new DockerBinariesResolver();

            Console.WriteLine(
                $"{resolver.MainDockerClient.FqPath} {resolver.MainDockerMachine.FqPath} {resolver.MainDockerCompose.FqPath}");
        }
        public static string ResolveBinary(this string dockerCommand, DockerBinariesResolver resolver, bool preferMachine = false)
        {
            var binary = resolver.Resolve(dockerCommand, preferMachine);

            if (FdOs.IsWindows() || binary.Sudo == SudoMechanism.None)
            {
                return(binary.FqPath);
            }

            string cmd;

            if (binary.Sudo == SudoMechanism.NoPassword)
            {
                cmd = $"sudo {binary.FqPath}";
            }
            else
            {
                cmd = $"echo {binary.SudoPassword} | sudo -S {binary.FqPath}";
            }

            if (string.IsNullOrEmpty(cmd))
            {
                if (!string.IsNullOrEmpty(dockerCommand) && dockerCommand.ToLower() == "docker-machine")
                {
                    throw new FluentDockerException(
                              $"Could not find {dockerCommand} make sure it is on your path. From 2.2.0 you have to seprately install it via https://github.com/docker/machine/releases");
                }

                throw new FluentDockerException($"Could not find {dockerCommand}, make sure it is on your path.");
            }

            return(cmd);
        }
Example #4
0
        public static bool IsComposeBinaryPresent()
        {
            if (null == _binaryResolver)
            {
                _binaryResolver = new DockerBinariesResolver();
            }

            return(null != _binaryResolver.MainDockerCompose);
        }
Example #5
0
        public static string ResolveBinary(this string dockerCommand, bool preferMachine = false, bool forceResolve = false)
        {
            if (forceResolve)
            {
                _binaryResolver = new DockerBinariesResolver();
            }

            return(_binaryResolver.Resolve(dockerCommand, preferMachine).FqPath);
        }
Example #6
0
        public static bool IsComposeBinaryPresent()
        {
            if (null == _binaryResolver)
            {
                _binaryResolver = new DockerBinariesResolver(_sudoMechanism, _sudoPassword);
            }

            return(null != _binaryResolver.MainDockerCompose);
        }
        public static string ResolveBinary(this string dockerCommand, bool preferMachine = false, bool forceResolve = false)
        {
            if (forceResolve || null == _binaryResolver)
            {
                _binaryResolver = new DockerBinariesResolver(_sudoMechanism, _sudoPassword);
            }

            return(dockerCommand.ResolveBinary(_binaryResolver, preferMachine));
        }
Example #8
0
        public static void SetSudo(this SudoMechanism sudo, string password = null)
        {
            if (string.IsNullOrWhiteSpace(password) && sudo == SudoMechanism.Password)
            {
                throw new ArgumentException("When using SudoMechanism.Password a password must be provided!", nameof(password));
            }

            _sudoMechanism  = sudo;
            _sudoPassword   = password;
            _binaryResolver = new DockerBinariesResolver(_sudoMechanism, _sudoPassword);
        }
Example #9
0
        public static IEnumerable <string> GetResolvedBinaries()
        {
            if (null == _binaryResolver)
            {
                _binaryResolver = new DockerBinariesResolver();
            }

            return(new List <string>
            {
                "docker        : " + (_binaryResolver.MainDockerClient.FqPath ?? "not found"),
                "docker-compose: " + (_binaryResolver.MainDockerCompose.FqPath ?? "not found"),
                "docker-machine: " + (_binaryResolver.MainDockerMachine.FqPath ?? "not found")
            });
        }
        public void MissingDockerComposeShallThrowExceptionInResolveBinary()
        {
            var dockerFile = Path.Combine(Directory.GetCurrentDirectory(), FdOs.IsWindows() ? "docker.exe" : "docker");

            try
            {
                using (StreamWriter outputFile = new StreamWriter(dockerFile))
                {
                    outputFile.WriteLine("fake docker client to satisfy DockerBinariesResolver");
                }

                var resolver = new DockerBinariesResolver(SudoMechanism.None, "", Directory.GetCurrentDirectory());
                "docker-compose".ResolveBinary(resolver, false);
                Assert.Fail("Shall never reach here since it shall throw a FluentDockerException");
            } finally {
                System.IO.File.Delete(dockerFile);
            }
        }