Exemple #1
0
        public async Task Publish()
        {
            Console.WriteLine("Publish");

            // https://stackoverflow.com/questions/28349392/how-to-push-a-docker-image-to-a-private-repository
            //docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
            //Then docker push using that same tag.
            //docker push NAME[:TAG]
            using (var client = dockerWrapper.GetClient())
            {
                var parameters = new ImageTagParameters();
                parameters.RepositoryName = "privateregistry.mynetwork.local:5443/" + ImageName;
                parameters.Tag            = "1";
                Console.WriteLine("Tag");
                await client.Images.TagImageAsync(ImageName + ":1", parameters);

                Console.WriteLine("try to find : " + ImageName + ":1");
                var foundImage = await dockerWrapper.FindImage(ImageName + ":1");

                var p = new ImagePushParameters();
                p.ImageID = foundImage.ID;
                p.Tag     = "1";

                var progress = new DockerProgress(m => {
                    if (m.Progress != null)
                    {
                        Console.WriteLine(m.ID + " " + m.ProgressMessage /*+ " : " + m.Progress.Current + "/" + m.Progress.Total*/);
                    }
                });
                var authConfig = new AuthConfig();
                await client.Images.PushImageAsync("privateregistry.mynetwork.local:5443/" + ImageName + ":1", p, authConfig, progress);
            }
        }
Exemple #2
0
        public async Task CreateImageIfNotFound(string repoTag)
        {
            var foundImage = await this.FindImage(repoTag);

            if (foundImage != null)
            {
                return;
            }

            using (var client = GetClient())
            {
                var parameters = new ImagesCreateParameters();
                var split      = repoTag.Split(':');
                parameters.FromImage = split[0];
                parameters.Repo      = split[0];
                parameters.Tag       = split[1];

                var progress = new DockerProgress(m => {
                    if (m.Progress != null)
                    {
                        Console.WriteLine(m.ID + " " + m.ProgressMessage /*+ " : " + m.Progress.Current + "/" + m.Progress.Total*/);
                    }
                });
                await client.Images.CreateImageAsync(parameters, null, progress);
            }
        }