Beispiel #1
0
        public async override Task DoStuff()
        {
            await _signalrClients.Client(_connectionId).SendAsync("logGuid", _myGuid);

            using (var logs = await GetClient().Containers.GetContainerLogsAsync(_id, new ContainerLogsParameters
            {
                ShowStderr = true,
                ShowStdout = true,
                Follow = true,
                Tail = "200",
                Timestamps = false,
            }, _cancellation.Token))
            {
                byte[] eight     = new byte[8];
                bool   foundData = false;
                while (logs.Read(eight, 0, 8) == 8)
                {
                    byte[] lastFour = eight.TakeLast(4).ToArray();
                    Array.Reverse(lastFour);
                    int size = BitConverter.ToInt32(lastFour, 0);

                    byte[] lineBytes = new byte[size];
                    logs.Read(lineBytes, 0, size);
                    string line = System.Text.Encoding.UTF8.GetString(lineBytes);
                    if (!foundData && line.Length > 0 && !line.StartsWith("Error grabbing logs: EOF"))
                    {
                        foundData = true;
                    }
                    if ((!foundData && line.Length == 0) || (line == "Error grabbing logs: EOF"))
                    {
                        await _signalrClients.Client(_connectionId).SendAsync("No data found. Either the container has not yet produced logs or the URL is wrong");
                    }

                    if (foundData)
                    {
                        /* string timestampS = line.Substring(0, 30);
                         * DateTime timestamp = DateTime.Parse(timestampS);
                         * line = timestamp.ToString("yyyy-MM-dd HH:mm:ss") + "   " + line.Substring(31);*/

                        if (!ProgressHub.IsBroken(_myGuid))
                        {
                            await _signalrClients.Client(_connectionId).SendAsync("log", line);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public async override Task DoStuff()
        {
            await _signalrClients.Client(_connectionId).SendAsync("pullGuid", _myGuid);

            var progress = new Progress <JSONMessage>(async message =>
            {
                if (ProgressHub.IsBroken(_myGuid))
                {
                    _cancellation.Cancel();
                }
                else
                {
                    await _signalrClients.Client(_connectionId).SendAsync("pullProgress", message);
                }
            });
            AuthConfig authConfig = null;

            if (_regCreds != null)
            {
                authConfig = new AuthConfig()
                {
                    ServerAddress = _regCreds.Registry,
                    Username      = _regCreds.Username,
                    Password      = _regCreds.Password
                };
            }
            await GetClient().Images.CreateImageAsync(
                new ImagesCreateParameters()
            {
                FromImage = _fqin,
                Tag       = _tag
            },
                authConfig,
                progress,
                _cancellation.Token
                );

            await _signalrClients.Client(_connectionId).SendAsync("pullFinished");
        }