Пример #1
0
        private void VerifyImages(
            ImageDescriptor imageDescriptor,
            IEnumerable <string> buildArgs,
            string appDescriptor,
            string runCommand,
            string testUrl)
        {
            string appId   = $"{appDescriptor}-{DateTime.Now.ToFileTime()}";
            string workDir = Path.Combine(
                Directory.GetCurrentDirectory(),
                "projects",
                $"{appDescriptor}-{imageDescriptor.RuntimeVersion}");

            try
            {
                _dockerHelper.Build(
                    tag: appId,
                    dockerfile: Path.Combine(workDir, "Dockerfile"),
                    buildContextPath: workDir,
                    buildArgs: buildArgs);

                _dockerHelper.Run(image: appId, containerName: appId, command: runCommand, detach: !string.IsNullOrEmpty(testUrl));
                if (!string.IsNullOrEmpty(testUrl))
                {
                    VerifyHttpResponseFromContainer(appId, testUrl);
                }
            }
            finally
            {
                _dockerHelper.DeleteContainer(appId, !string.IsNullOrEmpty(testUrl));
                _dockerHelper.DeleteImage(appId);
            }
        }
Пример #2
0
        public string BuildAndTestImage(
            ImageDescriptor imageDescriptor,
            IEnumerable <string> buildArgs,
            string appDescriptor,
            string runCommand,
            string testUrl,
            string optionalRunArgs = null)
        {
            string appId   = $"{appDescriptor}-{DateTime.Now.ToFileTime()}";
            string workDir = Path.Combine(
                Directory.GetCurrentDirectory(),
                "projects",
                $"{appDescriptor}-{imageDescriptor.Version}");

            string output;

            try
            {
                DockerHelper.Build(
                    tag: appId,
                    dockerfile: Path.Combine(workDir, "Dockerfile"),
                    contextDir: workDir,
                    buildArgs: buildArgs.ToArray());

                output = DockerHelper.Run(image: appId, name: appId, command: runCommand, optionalRunArgs: optionalRunArgs, detach: !string.IsNullOrEmpty(testUrl));
                if (!string.IsNullOrEmpty(testUrl))
                {
                    VerifyHttpResponseFromContainer(appId, testUrl);
                }
            }
            finally
            {
                DockerHelper.DeleteContainer(appId, !string.IsNullOrEmpty(testUrl));
                DockerHelper.DeleteImage(appId);
            }

            return(output);
        }