public async Task <string> BuildAsync(IImageFromDockerfileConfiguration config, CancellationToken ct = default) { var dockerFileArchive = new DockerfileArchive(config.DockerfileDirectory, config.Dockerfile, config.Image); var imageExists = await this.ExistsWithNameAsync(config.Image.FullName, ct) .ConfigureAwait(false); if (imageExists && config.DeleteIfExists) { await this.DeleteAsync(config.Image, ct) .ConfigureAwait(false); } using (var stream = new FileStream(dockerFileArchive.Tar(), FileMode.Open)) { using (var image = await this.Docker.Images.BuildImageFromDockerfileAsync(stream, new ImageBuildParameters { Dockerfile = config.Dockerfile, Tags = new[] { config.Image.FullName } }, ct) .ConfigureAwait(false)) { // Read the image stream to the end, to avoid disposing before Docker has done it's job. _ = await new StreamReader(image).ReadToEndAsync() .ConfigureAwait(false); } } return(config.Image.FullName); }
public async Task <string> BuildAsync(IImageFromDockerfileConfiguration configuration, CancellationToken ct = default) { var image = configuration.Image; ITarArchive dockerFileArchive = new DockerfileArchive(configuration.DockerfileDirectory, configuration.Dockerfile, image, this.logger); var imageExists = await this.ExistsWithNameAsync(image.FullName, ct) .ConfigureAwait(false); if (imageExists && configuration.DeleteIfExists) { await this.DeleteAsync(image, ct) .ConfigureAwait(false); } var buildParameters = new ImageBuildParameters { Dockerfile = configuration.Dockerfile, Tags = new[] { image.FullName }, Labels = configuration.Labels.ToDictionary(item => item.Key, item => item.Value), }; using (var dockerFileStream = new FileStream(dockerFileArchive.Tar(), FileMode.Open)) { await this.Docker.Images.BuildImageFromDockerfileAsync(buildParameters, dockerFileStream, Array.Empty <AuthConfig>(), new Dictionary <string, string>(), this.traceProgress, ct) .ConfigureAwait(false); } this.logger.DockerImageBuilt(image); return(image.FullName); }
public async Task <string> BuildAsync(IImageFromDockerfileConfiguration config, CancellationToken ct = default) { var dockerFileArchive = new DockerfileArchive(config.DockerfileDirectory); var imageExists = await this.ExistsWithNameAsync(config.Image.FullName, ct); if (imageExists && config.DeleteIfExists) { await this.DeleteAsync(config.Image, ct); } using (var stream = new FileStream(dockerFileArchive.Tar(), FileMode.Open)) { using (var unused = await this.Docker.Images.BuildImageFromDockerfileAsync(stream, new ImageBuildParameters { Dockerfile = config.Dockerfile, Tags = new[] { config.Image.FullName } }, ct)) { // New Docker image built, ready to use. } } return(config.Image.FullName); }
public async Task <string> BuildAsync(IImageFromDockerfileConfiguration configuration, CancellationToken ct = default) { return(await this.images.BuildAsync(configuration, ct)); }
private ImageFromDockerfileBuilder(IImageFromDockerfileConfiguration configuration) { this.configuration = configuration; }