/** * Gets a new {@link Containerizer} that containerizes to a Docker daemon. * * @param dockerDaemonImage the {@link DockerDaemonImage} that defines target Docker daemon * @return a new {@link Containerizer} */ public static Containerizer To(DockerDaemonImage dockerDaemonImage) { dockerDaemonImage = dockerDaemonImage ?? throw new ArgumentNullException(nameof(dockerDaemonImage)); ImageConfiguration imageConfiguration = ImageConfiguration.CreateBuilder(dockerDaemonImage.GetImageReference()) .SetCredentialRetrievers(new List <CredentialRetriever> { () => Maybe.Of(dockerDaemonImage.Credential) }) .Build(); DockerClient.Builder dockerClientBuilder = DockerClient.CreateBuilder(); dockerDaemonImage.GetDockerExecutable().IfPresent(dockerClientBuilder.SetDockerExecutable); dockerClientBuilder.SetDockerEnvironment(ImmutableDictionary.CreateRange(dockerDaemonImage.GetDockerEnvironment())); return(new Containerizer( DescriptionForDockerDaemon, imageConfiguration, StepsRunnerFactory, false)); StepsRunner StepsRunnerFactory(BuildConfiguration buildConfiguration) => StepsRunner.Begin(buildConfiguration) .PullBaseImage(1) .PullAndCacheBaseImageLayers(2) .BuildAndCacheApplicationLayers(3) .BuildImage(4) .LoadDocker(dockerClientBuilder.Build(), 5); }
/** * Gets a new {@link Containerizer} that containerizes to a tarball archive. * * @param tarImage the {@link TarImage} that defines target output file * @return a new {@link Containerizer} */ public static Containerizer To(TarImage tarImage) { tarImage = tarImage ?? throw new ArgumentNullException(nameof(tarImage)); ImageConfiguration imageConfiguration = ImageConfiguration.CreateBuilder(tarImage.GetImageReference()).Build(); return(new Containerizer( DescriptionForImageTarFile, imageConfiguration, StepsRunnerFactory, false)); StepsRunner StepsRunnerFactory(BuildConfiguration buildConfiguration) => StepsRunner.Begin(buildConfiguration) .PullBaseImage() .PullAndCacheBaseImageLayers() .BuildAndCacheApplicationLayers() .BuildImage() .WriteTarFile(tarImage.GetOutputFile()); }
/** * Gets a new {@link Containerizer} that containerizes to a container registry. * * @param registryImage the {@link RegistryImage} that defines target container registry and * credentials * @return a new {@link Containerizer} */ public static Containerizer To(RegistryImage registryImage) { registryImage = registryImage ?? throw new ArgumentNullException(nameof(registryImage)); ImageConfiguration imageConfiguration = ImageConfiguration.CreateBuilder(registryImage.GetImageReference()) .SetCredentialRetrievers(registryImage.GetCredentialRetrievers()) .Build(); return(new Containerizer( DescriptionForDockerRegistry, imageConfiguration, StepsRunnerFactory, true)); StepsRunner StepsRunnerFactory(BuildConfiguration buildConfiguration) => StepsRunner.Begin(buildConfiguration) .RetrieveTargetRegistryCredentials() .AuthenticatePush() .PullBaseImage() .PullAndCacheBaseImageLayers() .PushBaseImageLayers() .BuildAndCacheApplicationLayers() .BuildImage() .PushContainerConfiguration() .PushApplicationLayers() .PushImage(); }