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;
                }
            }
        }