Esempio n. 1
0
        /**
         * Builds the container.
         *
         * @param containerizer the {@link Containerizer} that configures how to containerize
         * @return the built container
         * @throws IOException if an I/O exception occurs
         * @throws CacheDirectoryCreationException if a directory to be used for the cache could not be
         *     created
         * @throws HttpHostConnectException if fib failed to connect to a registry
         * @throws RegistryUnauthorizedException if a registry request is unauthorized and needs
         *     authentication
         * @throws RegistryAuthenticationFailedException if registry authentication failed
         * @throws UnknownHostException if the registry does not exist
         * @throws InsecureRegistryException if a server could not be verified due to an insecure
         *     connection
         * @throws RegistryException if some other error occurred while interacting with a registry
         * @throws ExecutionException if some other exception occurred during execution
         * @throws InterruptedException if the execution was interrupted
         */
        public async Task <FibContainer> ContainerizeAsync(IContainerizer containerizer)
        {
            containerizer = containerizer ?? throw new ArgumentNullException(nameof(containerizer));
            BuildConfiguration buildConfiguration = ToBuildConfiguration(containerizer);

            IEventHandlers eventHandlers = buildConfiguration.GetEventHandlers();

            LogSources(eventHandlers);

            using (new TimerEventDispatcher(eventHandlers, containerizer.GetDescription()))
            {
                try
                {
                    IBuildResult result = await containerizer.CreateStepsRunner(buildConfiguration).RunAsync().ConfigureAwait(false);

                    return(new FibContainer(result.GetImageDigest(), result.GetImageId()));
                }
                catch (Exception ex)
                {
                    eventHandlers.Dispatch(LogEvent.Error(ex.Message));
                    // If an ExecutionException occurs, re-throw the cause to be more easily handled by the user
                    if (ex.InnerException is RegistryException)
                    {
                        throw (RegistryException)ex.InnerException;
                    }
                    throw;
                }
            }
        }
        private IContainerizer CreateMockContainerizer()
        {
            ImageReference targetImage       = ImageReference.Parse("target-image");
            IContainerizer mockContainerizer = Mock.Of <IContainerizer>();
            IStepsRunner   stepsRunner       = Mock.Of <IStepsRunner>();
            IBuildResult   mockBuildResult   = Mock.Of <IBuildResult>();

            Mock.Get(mockContainerizer).Setup(m => m.GetImageConfiguration()).Returns(ImageConfiguration.CreateBuilder(targetImage).Build());

            Mock.Get(mockContainerizer).Setup(m => m.CreateStepsRunner(It.IsAny <BuildConfiguration>())).Returns(stepsRunner);

            Mock.Get(stepsRunner).Setup(s => s.RunAsync()).Returns(Task.FromResult(mockBuildResult));

            Mock.Get(mockBuildResult).Setup(m => m.GetImageDigest()).Returns(
                DescriptorDigest.FromHash(
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));

            Mock.Get(mockBuildResult).Setup(m => m.GetImageId()).Returns(
                DescriptorDigest.FromHash(
                    "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));

            Mock.Get(mockContainerizer).Setup(m => m.GetAdditionalTags()).Returns(new HashSet <string>());

            Mock.Get(mockContainerizer).Setup(m => m.GetBaseImageLayersCacheDirectory()).Returns(Paths.Get("/"));

            Mock.Get(mockContainerizer).Setup(m => m.GetApplicationLayersCacheDirectory()).Returns(Paths.Get("/"));

            Mock.Get(mockContainerizer).Setup(m => m.GetAllowInsecureRegistries()).Returns(false);

            Mock.Get(mockContainerizer).Setup(m => m.GetToolName()).Returns("mocktool");

            Mock.Get(mockContainerizer).Setup(m => m.BuildEventHandlers()).Returns(EventHandlers.NONE);

            return(mockContainerizer);
        }
Esempio n. 3
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="sourceUrl"></param>
        public ResourceBuildResult(string sourceUrl, IBuildResult buildResult)
        {
            if (sourceUrl == null)
            {
                sourceUrl = String.Empty;
            }

            this.sourceUrl   = sourceUrl;
            this.buildResult = buildResult != null ? buildResult : this as IBuildResult;
        }
Esempio n. 4
0
        public override void Write(TextWriter writer)
        {
            IBuildResult result     = this.BuildResult;
            bool         customType = this.Attributes.ContainsKey("type");

            try
            {
                if (!customType)
                {
                    string mimeType;
                    if (result == null)
                    {
                        mimeType = ScriptResourceCodeProvider.MimeType;
                    }
                    else
                    {
                        mimeType = result.ContentType;
                    }
                    this.Attributes["type"] = mimeType;
                }
                string url = this.ResolveUrl();
                this.Attributes["src"] = url;

                writer.Write(ScriptBuildResult.ScriptStart);

                this.WriteAttributes(writer);

                writer.Write(ScriptBuildResult.ScriptEnd);

                if (!this.SuppressLocalization &&
                    this is IGlobalizedBuildResult)
                {
                    string culture = this.UsePageCulture ?
                                     Thread.CurrentThread.CurrentCulture.Name :
                                     String.Empty;

                    this.Attributes["src"] = ResourceHandler.GetLocalizationUrl(url, culture);

                    writer.Write(ScriptBuildResult.ScriptStart);
                    this.WriteAttributes(writer);
                    writer.Write(ScriptBuildResult.ScriptEnd);
                }
            }
            finally
            {
                if (!customType)
                {
                    this.Attributes.Remove("type");
                }
                this.Attributes.Remove("src");
            }
        }
Esempio n. 5
0
        public async Task <IBuildResult> BuildAsync(string target, IDictionary <string, string> globalProperties)
        {
            if (globalProperties == null)
            {
                globalProperties = new Dictionary <string, string>();
            }

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsOutputWindowPane outputWindowPane = null;
            IVsOutputWindow     outputWindow     = ServiceProvider.GlobalProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;

            if (outputWindow != null)
            {
                outputWindow.GetPane(VSConstants.GUID_BuildOutputWindowPane, out outputWindowPane);
            }

            var hostObjects = new HashSet <IHostObject>();

            ILogger logger = null;

            if (outputWindowPane != null)
            {
                outputWindowPane.Activate();
                logger = new PublishLogger(outputWindowPane);
            }

            var loggers = new HashSet <ILogger>()
            {
                logger
            };

            if (_buildProject == null)
            {
                _buildProject = await GetBuildProject(_hier.GetUnconfiguredProject());
            }

            _hier.GetDTEProject().DTE.Solution.SolutionBuild.BuildProject(globalProperties["Configuration"], _hier.GetDTEProject().UniqueName, true);
            IBuildResult result = await _buildProject?.BuildAsync(new string[] { target }, CancellationToken.None, true, ImmutableDictionary.ToImmutableDictionary(globalProperties), hostObjects.ToImmutableHashSet(), BuildRequestPriority.High, loggers.ToImmutableHashSet());

            return(result);
        }
Esempio n. 6
0
        public override void Write(TextWriter writer)
        {
            bool customType = this.Attributes.ContainsKey("type");

            try
            {
                if (!customType)
                {
                    IBuildResult result = this.BuildResult;

                    string mimeType;
                    if (result == null)
                    {
                        mimeType = CssResourceCodeProvider.MimeType;
                    }
                    else
                    {
                        mimeType = result.ContentType;
                    }
                    this.Attributes["type"] = mimeType;
                }

                string url = this.ResolveUrl();
                if (this.StyleFormat == CssIncludeType.Import)
                {
                    this.WriteImport(writer, url);
                }
                else
                {
                    this.WriteLink(writer, url);
                }
            }
            finally
            {
                if (!customType)
                {
                    this.Attributes.Remove("type");
                }
                this.Attributes.Remove("href");
                this.Attributes.Remove("rel");
            }
        }
Esempio n. 7
0
        protected internal static string GetResourceUrl(IBuildResult info, string path, bool isDebug)
        {
            if (info == null)
            {
                if ((path == null) || (path.IndexOf("://") < 0))
                {
                    return(path);
                }

                string alt;
                MergeResourceCodeProvider.SplitAlternates(path, out path, out alt);
                return(isDebug ? path : alt);
            }

            string cache;

            if (isDebug)
            {
                cache = '?' + DebugResourceHandlerFactory.DebugFlag;
            }
            else if (!String.IsNullOrEmpty(info.Hash))
            {
                cache = '?' + info.Hash;
            }
            else
            {
                cache = "";
            }

            int index = path.IndexOf('?');

            if (index >= 0)
            {
                path = path.Substring(0, index);
            }

            return(path + cache);
        }
Esempio n. 8
0
        public static ResourceBuildResult FindResource(string url)
        {
            bool isExternal = (url != null) && (url.IndexOf("://") > 0);

            object buildResult;

            if (isExternal)
            {
                buildResult = null;
            }
            else
            {
                buildResult = BuildManager.CreateInstanceFromVirtualPath(url, typeof(object));
            }

            ResourceBuildResult resource;

            if (buildResult is ResourceBuildResult)
            {
                resource = (ResourceBuildResult)buildResult;
            }
            else if (isExternal || buildResult is IBuildResult)
            {
                resource = new ScriptBuildResult(url, buildResult as IBuildResult);
            }
            else
            {
                throw new ArgumentException(String.Format(
                                                "Error loading resources for \"{0}\".\r\n" +
                                                "This can be caused by an invalid path, build errors, or incorrect configuration.\r\n" +
                                                "Check http://help.jsonfx.net/instructions for troubleshooting.",
                                                url));
            }

            return(resource);
        }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="sourceUrl"></param>
 public CssBuildResult(string sourceUrl, IBuildResult buildResult)
     : base(sourceUrl, buildResult)
 {
 }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="sourceUrl"></param>
 public ScriptBuildResult(string sourceUrl, IBuildResult buildResult)
     : base(sourceUrl, buildResult)
 {
 }
        public static ResourceBuildResult FindResource(string url)
        {
            bool isExternal = (url != null) && (url.IndexOf("://") > 0);

            object buildResult;
            if (isExternal)
            {
                buildResult = null;
            }
            else
            {
                buildResult = BuildManager.CreateInstanceFromVirtualPath(url, typeof(object));
            }

            ResourceBuildResult resource;

            if (buildResult is ResourceBuildResult)
            {
                resource = (ResourceBuildResult)buildResult;
            }
            else if (isExternal || buildResult is IBuildResult)
            {
                resource = new ScriptBuildResult(url, buildResult as IBuildResult);
            }
            else
            {
                throw new ArgumentException(String.Format(
                    "Error loading resources for \"{0}\".\r\n"+
                    "This can be caused by an invalid path, build errors, or incorrect configuration.\r\n"+
                    "Check http://help.jsonfx.net/instructions for troubleshooting.",
                    url));
            }

            return resource;
        }
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="sourceUrl"></param>
        public ResourceBuildResult(string sourceUrl, IBuildResult buildResult)
        {
            if (sourceUrl == null)
            {
                sourceUrl = String.Empty;
            }

            this.sourceUrl = sourceUrl;
            this.buildResult = buildResult != null ? buildResult : this as IBuildResult;
        }
Esempio n. 13
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="sourceUrl"></param>
 public CssBuildResult(string sourceUrl, IBuildResult buildResult)
     : base(sourceUrl, buildResult)
 {
 }
Esempio n. 14
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="sourceUrl"></param>
 public ScriptBuildResult(string sourceUrl, IBuildResult buildResult)
     : base(sourceUrl, buildResult)
 {
 }