/// <inheritdoc />
        protected override void Do(CommandLineApplication app, IConsole console)
        {
            // getting stack info
            var stack = ApiClient.GetStacks().FirstOrDefault(s => s.Name == StackName);

            if (stack == null)
            {
                throw new Exception("Stack with this name is not found");
            }

            var stackId = int.Parse(stack.Id);
            // check file
            string fileContent = null;

            if (!string.IsNullOrWhiteSpace(FilePath))
            {
                if (!File.Exists(FilePath))
                {
                    throw new Exception("Definition file is not found. Provide valid path.");
                }

                fileContent = File.ReadAllText(FilePath);
            }

            if (FileFromStdin && fileContent == null)
            {
                var    sb = new StringBuilder();
                string s;
                while ((s = Console.ReadLine()) != null)
                {
                    sb.AppendLine(s);
                }

                fileContent = sb.ToString();
            }

            var envs = CmdHelpers.ParseEnvs(Envs);

            // if file content not provided (we use old file and change only provided env vars)
            if (fileContent == null)
            {
                envs.AddRange(stack.Env.Where(e => envs.All(newEnv => newEnv.Name != e.Name)));
                fileContent = ApiClient.GetStackFile(stackId);
            }

            console.Write("Sending stack update request to Portainer...");
            ApiClient.UpdateStack(stackId, envs, fileContent, prune: false, stack.EndpointId);
            console.WriteLine("Done!");
        }
Example #2
0
        /// <inheritdoc />
        protected override void Do(CommandLineApplication app, IConsole console)
        {
            if (!File.Exists(FilePath))
            {
                throw new Exception("Stack definition file is not found. Please, give correct path to file.");
            }

            var stackEnvs = CmdHelpers.ParseEnvs(Envs);

            // 1 - swarm stack
            console.WriteLine("Sending deploy request to Portainer...");
            var result = ApiClient.DeployStack(endpointId: EndpointId,
                                               StackName,
                                               SwarmId,
                                               FilePath,
                                               stackEnvs);

            console.WriteLine("Stack deployed.");
        }