Manan Kapoor
Manan Kapoor

Reputation: 327

Unable to run Argo workflow with containerized .Net Console app

I have a .Net Core Console Application which I have containerized. The purpose of my application is to accept a file url and return the text. Below is my Dockerfile.

FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["CLI_ReadData/CLI_ReadData.csproj", "CLI_ReadData/"]
RUN dotnet restore "CLI_ReadData/CLI_ReadData.csproj"
COPY . .
WORKDIR "/src/CLI_ReadData"
RUN dotnet build "CLI_ReadData.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "CLI_ReadData.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CLI_ReadData.dll"]

I now want to create an Argo Workflow for the same. Below is the corresponding .yaml file

metadata:
  name: read-data
  namespace: argo
spec:
  entrypoint: read-data
  templates:
    - name: read-data
      dag:
        tasks:
          - name: read-all-data
            template: read-all-data
            arguments:
              parameters:
                - name: fileUrl
                  value: 'https://dpaste.com/24593EK38'
    - name: read-all-data
      inputs:
        parameters:
          - name: fileUrl
      container:
        image: 'manankapoor2705/cli_readdata:latest'
          - app/bin/Debug/net5.0/CLI_ReadData.dll
        args:
          - '--fileUrl={{inputs.parameters.fileUrl}}'  
  ttlStrategy:
    secondsAfterCompletion: 300

While creating the Argo Workflow I am getting the below error :

task 'read-data.read-all-data' errored: container "main" in template "read-all-data", does not have the command specified: when using the emissary executor you must either explicitly specify the command, or list the image's command in the index: https://argoproj.github.io/argo-workflows/workflow-executors/#emissary-emissary

I am also attaching my Program.cs file for reference purposes

class Program
    {
        public class CommandLineOptions
        {
            [Option("fileUrl", Required = true, HelpText = "Please provide a url of the text file.")]
            public string fileUrl { get; set; }
        }

        static void Main(string[] args)
        {
            try
            {
                var result = Parser.Default.ParseArguments<CommandLineOptions>(args)
               .WithParsed<CommandLineOptions>(options =>
               {

                   Console.WriteLine("Arguments received...Processing further !");

                   var text = readTextFromFile(options.fileUrl);
                   Console.WriteLine("Read names from textfile...");

                   var names = generateListOfNames(text);
               });
                if (result.Errors.Any())
                {
                    throw new Exception($"Task Failed {String.Join('\n', result.Errors)}");
                }
                //exit successfully
                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Task failed!!");
                Console.WriteLine(ex.ToString());
                //failed exit
                Environment.Exit(1);
            }

            Console.WriteLine("Hello World!");
        }

        public static string readTextFromFile(string path)
        {
            System.Net.WebRequest request = System.Net.WebRequest.Create(path);
            System.Net.WebResponse response = request.GetResponse();
            Stream dataStream = response.GetResponseStream();

            var reader = new StreamReader(dataStream);
            var text = reader.ReadToEnd();

            reader.Close();
            response.Close();

            return text;
        }

        public static List<string> generateListOfNames(string text)
        {
            var names = text.Split(',').ToList<string>();

            foreach (var name in names)
                Console.WriteLine(name);

            return names;
        }
    }

Can anyone please help me out ?

Upvotes: 1

Views: 1717

Answers (1)

crenshaw-dev
crenshaw-dev

Reputation: 8382

The read-all-data template looks to me like invalid YAML. I think you're missing the command field name. I think the path also needs either a leading / (for an absolute path), or to start with bin/ (for a relative path with /app as the working directory).

    - name: read-all-data
      inputs:
        parameters:
          - name: fileUrl
      container:
        image: 'manankapoor2705/cli_readdata:latest'
        command:
          - /app/bin/Debug/net5.0/CLI_ReadData.dll
        args:
          - '--fileUrl={{inputs.parameters.fileUrl}}'  

Upvotes: 2

Related Questions