F1bonacc1 / process-compose

Process Compose is a simple and flexible scheduler and orchestrator to manage non-containerized applications.

Home Page:https://f1bonacc1.github.io/process-compose/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`$` (dollar sign) is being removed from `command`

MrFoxPro opened this issue · comments

I'm using https://github.com/Platonic-Systems/process-compose-flake. My config is:

process-compose."dev:web-node" = {
  debug = true;
  settings = {
    shell.shell_command = "nu";
    processes.web = {
      command = "print $env.PWD; print $PWD; print (pwd)";
      working_dir = "./node/web";
    };
  };
};

results in

processes:
  web:
    command: print $env.PWD; print $PWD; print (pwd)
    working_dir: ./node/web
shell:
  shell_argument: -c
  shell_command: nu
[web_1  ] .PWD
[web_1  ] /home/foxpro/craft/sferadel/next
[web_1  ] /home/foxpro/craft/sferadel/next/node/web

so $env.PWD breaks, but $PWD is okay.

Can we have configuration in toml pls?

Hi,

Environment variables expansion is a documented feature of Process Compose.
Since $env is not defined it is replaced by an empty string.
What is the expected behavior in this case?

Can we have configuration in toml pls?

Currently, there is no plan to support other configuration formats, but PRs are welcome 😉

Hi,

Environment variables expansion is a documented feature of Process Compose. Since $env is not defined it is replaced by an empty string. What is the expected behavior in this case?

this is a nushell script, so it should run as-is.

I mean $env.PWD in Nushell is accessing PWD field in $env record.
When process-compose replaces $env, script doesn't work as it suppose to

@MrFoxPro can you tell me a little bit more about your use case?
Why are you replacing the default (bash) shell in process compose with nushell? Are the processes commands that you are running not supported by other, POSIX compliant shells?

I am trying to decide what would be the proper solution in this case:

  1. Configuration to disable substitution.
  2. Recognize nushell and disable it automatically.
  3. Reimplement the substitution (standard library) with the ability to escape $$ the $env.KEY and let the script handle it.
commented

Reimplement the substitution (standard library) with the ability to escape $$ the $env.KEY and let the script handle it.

I’d vote for this

@MrFoxPro can you tell me a little bit more about your use case? Why are you replacing the default (bash) shell in process compose with nushell? Are the processes commands that you are running not supported by other, POSIX compliant shells?

I am trying to decide what would be the proper solution in this case:

1. Configuration to disable substitution.

2. Recognize nushell and disable it automatically.

3. Reimplement the substitution (standard library) with the ability to escape `$$` the `$env.KEY` and let the script handle it.

I'm using Nix for developer environment managment, and I need to setup groups of scripts and/or processes. process-compose-flake (that is build on top of process-compose) is the only solution right now.
So, there are some complex scripts that I prefer to write in Nushell and I was disappointed that my script breaks because of $ substiution, that is completely unnecessary when using Nix.

I would like to have configuration to disable it (maybe by default) so I can configure it in Nix.

Using a shebanged script to your preferred interpreter is a better solution until a change is made to process-compose.

It is anyway more readable and scalable as your number of statements increase.

@MrFoxPro I completely agree with @thenonameguy, this can be easily solved by adding shebang to your scripts and running process-compose with the default shell (bash).

For more exotic cases I found another workaround for nushell.
Create a .env file with the following content in your working directory:
env='$env'
It should work as expected now.
Let me know if this resolves the issue.

Cheers!

Using a shebanged script to your preferred interpreter is a better solution until a change is made to process-compose.

It is anyway more readable and scalable as your number of statements increase.

So it assumes I need to write config like this:

process-compose."dev".settings.processes = {
  web = {
    command = ''
      echo $'Running from PWD: ($env.PWD)'
      pnpm dev
    '';
    working_dir = web_cwd;
    shell.shell_command = pkgs.nushell;
  };
    api = {
      command = "deno run -A --unstable main.ts";
      working_dir = api_cwd;
      shell.shell_command = pkgs.nushell;
    };
  };
}

And now I need more derivations:

process-compose."dev".settings.processes = {
  web = {
    command = pkgs.nuenv.mkSimpleScript "web-cmd.nu" ''
      echo $'Running from PWD: ($env.PWD)'
      pnpm dev
    '';
    working_dir = web_cwd;
    shell.shell_command = pkgs.nushell;
  };
  api = {
    command = pkgs.nuenv.mkSimpleScript "api-cmd.nu"  "deno run -A --unstable main.ts";
    working_dir = api_cwd;
    shell.shell_command = pkgs.nushell;
  };
}

That's a lot of code for simple task.

@MrFoxPro I completely agree with @thenonameguy, this can be easily solved by adding shebang to your scripts and running process-compose with the default shell (bash).

For more exotic cases I found another workaround for nushell. Create a .env file with the following content in your working directory: env='$env' It should work as expected now. Let me know if this resolves the issue.

Cheers!

$env is not only expression like this in Nushell, basically every variable usage is prefixed with $ :D

That's a lot of code for simple task.

It is, thankfully with a little extra abstraction it can be reduced by quite a bit:

let
  mkNuProcess = name: script: extra: {
    command = pkgs.nuenv.mkSimpleScript "${name}-cmd.nu" script;
  } // extra;
in
process-compose."dev".settings.processes = {
  web = mkNuProcess "web" ''
    echo $'Running from PWD: ($env.PWD)'
    pnpm dev
  '' { working_dir = web_cwd; };
  api = {
    # no need to run this process via nushell, since you are not using any feature from it.
    command = "deno run -A --unstable main.ts";
    working_dir = api_cwd;
  };
}

To keep process-compose implementation lean, I think this is a fair tradeoff.