Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
 public Task PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig, IProgress <JSONMessage> progress)
 {
     return(StreamUtil.MonitorStreamForMessagesAsync(
                PushImageAsync(name, parameters, authConfig),
                this._client,
                default(CancellationToken),
                progress));
 }
Exemplo n.º 3
0
        public async Task PublishImage(string image, Action <string> onStatus, Action <string> onError, Action <string> onProgress)
        {
            var authConfig = new AuthConfig()
            {
                Username = "******",
                Password = "******"
            };

            var parameters = new ImagePushParameters()
            {
            };

            // TODO: send progress results
            await _client.Images.PushImageAsync(image, parameters, authConfig, new ProgressMonitor(onStatus, onError, onProgress));
        }
Exemplo n.º 4
0
        public Task <Stream> PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            IQueryString queryParameters = new QueryString <ImagePushParameters>(parameters);

            return(this._client.MakeRequestForStreamAsync(this._client.NoErrorHandlers, HttpMethod.Post, $"images/{name}/push", queryParameters, RegistryAuthHeaders(authConfig), null, CancellationToken.None));
        }
Exemplo n.º 5
0
        public Task <Stream> PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            string       path            = string.Format(CultureInfo.InvariantCulture, "images/{0}/push", name);
            IQueryString queryParameters = new QueryString <ImagePushParameters>(parameters);

            return(this.Client.MakeRequestForStreamAsync(this.Client.NoErrorHandlers, HttpMethod.Post, path, queryParameters, RegistryAuthHeaders(authConfig), null, CancellationToken.None));
        }
Exemplo n.º 6
0
        public Task PushImageAsync(string name, ImagePushParameters parameters, AuthConfig authConfig, IProgress <JSONMessage> progress, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            IQueryString queryParameters = new QueryString <ImagePushParameters>(parameters);

            return(StreamUtil.MonitorStreamForMessagesAsync(
                       this._client.MakeRequestForStreamAsync(this._client.NoErrorHandlers, HttpMethod.Post, $"images/{name}/push", queryParameters, null, RegistryAuthHeaders(authConfig), CancellationToken.None),
                       this._client,
                       cancellationToken,
                       progress));
        }
 public static Stream PushImage(this IImageOperations operations, string name, ImagePushParameters parameters, AuthConfig authConfig)
 {
     return(operations.PushImageAsync(name, parameters, authConfig).Result);
 }
Exemplo n.º 8
0
        private async Task <int> DeployAsync(CommandContext context, IDockerClient dockerClient, BuildResult result,
                                             string tag, CancellationToken cancellationToken)
        {
            //Get the last id
            var imageId = result.Ids.LastOrDefault();

            if (string.IsNullOrWhiteSpace(imageId))
            {
                Console.Error.WriteLine("No image id was found. Unable to deploy.");

                return(1);
            }

            if (string.IsNullOrWhiteSpace(DeviceType))
            {
                Console.Error.WriteLine("No device type was specified.");
                return(1);
            }

            DeviceType deviceType = await context.FindDeviceTypeAsync(DeviceType, cancellationToken);

            if (deviceType == null)
            {
                return(1);
            }

            //Create the request
            var uploadInforRequest = new GetAgentUploadInfoRequest()
            {
                DeviceTypeId = deviceType.Id,
                ImageId      = imageId,
                Name         = tag
            };

            var applicationUploadInfo = await context.Client.AgentUploadInfo.GetAgentUploadInfo(uploadInforRequest, cancellationToken);

            if (applicationUploadInfo.CanUpload)
            {
                Console.WriteLine($"Deploying '{tag}' with imageid '{imageId}'...");

                var parameters = new ImagePushParameters
                {
                    ImageID = imageId,
                    Tag     = tag
                };

                string registryHost = RegistryHost ?? applicationUploadInfo.RegistryHost;

                var target = $"{registryHost}/{applicationUploadInfo.Repository}";

                //Tag it!
                await dockerClient.Images.TagImageAsync(imageId, new ImageTagParameters
                {
                    RepositoryName = target,
                    Tag            = tag
                }, cancellationToken);

                //Auth config (will have to include the token)
                var authConfig = new AuthConfig
                {
                    ServerAddress = registryHost
                };

                Console.WriteLine($"Pushing to '{target}:{tag}'...");

                //Push it to the application registry!
                await dockerClient.Images.PushImageAsync(target, parameters, authConfig,
                                                         new Progress <JSONMessage>(p => { }), cancellationToken);

                //Let the service now about the new application version.
                var uploadRequest = new CreateAgentVersionRequest()
                {
                    DeviceTypeId = deviceType.Id,
                    Name         = tag,
                    ImageId      = imageId,
                    Logs         = result.ToString(),
                    MakeCurrent  = MakeCurrent
                };

                //Upload the application version
                await context.Client.AgentVersions.CreateAgentVersion(uploadRequest, cancellationToken);
            }
            else
            {
                Console.Error.WriteLine($"Warning: Unable to upload image - '{applicationUploadInfo.Reason}'.");
            }

            return(0);
        }