Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement process entrypoint and run cmd #89

Merged
merged 6 commits into from
Nov 18, 2023

Conversation

adrian-gierakowski
Copy link
Contributor

@adrian-gierakowski adrian-gierakowski commented Sep 4, 2023

process entrypoint

entrypoint is an optional array of strings which can be set on the process config
to override default shell (and shellArg) used to run the command

When entrypoint is set and is non-empty, command can also be omitted.

This is useful if one want's to:

  1. use a different shell per process
  2. run any other executable directly, without a shell wrapper

run cmd

Equivalent of docker-compose run
which can be used to run a chosen process in the foreground (with std(in|out|err) attached),
while it's dependencies are ran in the background (no logs printed to stdio).

Deps can be disabled via --no-deps flag.

Additional arguments can be passed to the process after -- separator, for example:

process-compose run main -- arg1 arg2

The separator is necessary in order to distinguish process-compose flags from flags
meant to be passed to the process.

While the process is running, the logs of the deps can be inspected using the
usual command:

process-compose process logs dep

The process being ran will have availability.exit_on_end set to true and
manually setting it to false will have no effect.

implements #88 and #83

@adrian-gierakowski
Copy link
Contributor Author

adrian-gierakowski commented Sep 4, 2023

Happy to extract #88 into separate PR.

regarding #83, the way I made it work is to silence std(out|err) output for all processes apart from the main one passed to run as an argument, and then connecting os.std(in|out|err) directly to the main process. Currently the logs for the main process would not show up in process logs but I guess it should be trivial to make this work if desired.

note that I had to skip p.command.SetCmdArgs() since otherwise things would break in some cases (like running tests with yarn jest --watch in a node project). I guess this means that the main process will receive signals (Ctrl+C) directly. This is ok in my case as I set exit_on_end on the main process (which I guess would be a good default anyway).

@adrian-gierakowski
Copy link
Contributor Author

note that I'm not well versed in go so don't hesitate to criticise the implementation :)

@adrian-gierakowski
Copy link
Contributor Author

run command can be tested using the config file:

shell:
  shell_command: "bash"
  shell_argument: "-c"

processes:
  main:
    command: |
      echo say hi
      read -r in
      echo $in
      echo by
    depends_on:
      dep:
        condition: process_started
    availability:
      exit_on_end: true

  dep:
    command: while true; do echo sleeping... && sleep 2; done

run the main process:

./result/bin/process-compose run main -f process-compose.yaml

the dep will start in background but it's logs will not be output by the command above
instead you can view its logs with:

./result/bin/process-compose process logs -f dep

@adrian-gierakowski
Copy link
Contributor Author

and here's an example of how to configure a process to run without a shell wrapper:

processes:
  main:
    no_shell: true
    command: yarn
    args:
      - jest
      - --watch

We could potentially default to no_shell: true if args are set. Technically you could pass extra args to a shell, as in:

> bash -c 'echo name: $0 arg1: $1' my-name my-arg
name: my-name arg1: my-arg

but not sure if that would of use to anyone

@F1bonacc1
Copy link
Owner

and here's an example of how to configure a process to run without a shell wrapper:

processes:
  main:
    no_shell: true
    command: yarn
    args:
      - jest
      - --watch

We could potentially default to no_shell: true if args are set. Technically you could pass extra args to a shell, as in:

> bash -c 'echo name: $0 arg1: $1' my-name my-arg
name: my-name arg1: my-arg

but not sure if that would of use to anyone

Not sure this is going to be a widely used notation :)
I think that if the args list is not empty, the configured shell can be ignored and run cmd ...args

@F1bonacc1
Copy link
Owner

F1bonacc1 commented Sep 8, 2023

Are there use cases where it only makes sense to run a process as part of the run command? In other words, should the interactive process be disabled when ran as part of the full process-compose.yaml?

I tested the code (as is) with vim (along with other stdout writing processes) and it creates some unwanted visual issues when Tui is disabled.

@F1bonacc1
Copy link
Owner

@adrian-gierakowski
That's a more than welcome PR!
Having STDIN is a super useful feature, that was asked by other users before.
I was trying to crack the TUI approach, but I like your, more practical and actually working direction, more.

Thank you for that!

@adrian-gierakowski
Copy link
Contributor Author

I think that if the args list is not empty, the configured shell can be ignored and run cmd ...args

👍

Are there use cases where it only makes sense to run a process as part of the run command? In other words, should the interactive process be disabled when ran as part of the full process-compose.yaml?

There might be some, but in my case it works both with run and up, the latter with or without TUI. With extra args passed from cli, I would setup main process as yarn jest and then pass —watch when running with run for interactive experience. And if I wanted to do a one shot execution with outputs from all service interleaved I’d use up.

@adrian-gierakowski
Copy link
Contributor Author

I tested the code (as is) with vim and it creates some unwanted visual issues when Tui is disabled.

could you post a minimal config I could use to reproduce? Or a nix expression? Thanks!

@F1bonacc1
Copy link
Owner

I tested the code (as is) with vim and it creates some unwanted visual issues when Tui is disabled.

could you post a minimal config I could use to reproduce? Or a nix expression? Thanks!

version: "0.5"
log_level: debug

processes:
  vim:
    command: vim
    args:
      - compose.yaml
    depends_on:
      dep:
        condition: process_started

  dep:
    command: while true; do echo sleeping... && sleep 0.5; done

To reproduce:

  1. Run: process-compose -t=false
  2. Exit
  3. Run again

I think this can be avoided if interactive processes are disabled when run with others.

@adrian-gierakowski
Copy link
Contributor Author

I guess vim doesn’t have non-interactive mode so it would only make sense to run it via run. But many cli tools detect tty and work with and without it.

I think we can leave it up to the user to choose the correct command to make their config work. We could also add a new flag which would disable the service when ran via up, but then we’d have to decide if it’s deps should also be disabled.

@F1bonacc1
Copy link
Owner

I guess vim doesn’t have non-interactive mode so it would only make sense to run it via run. But many cli tools detect tty and work with and without it.

I think we can leave it up to the user to choose the correct command to make their config work. We could also add a new flag which would disable the service when ran via up, but then we’d have to decide if it’s deps should also be disabled.

I agree, We can start by letting the users manage the configuration if they want to skip the interactive processes. Since it's an edge case, I think it's a reasonable compromise.
Once we have more feedback and more specific use cases (debuggers, wizards, setup) we can decide on a flag or other behavior.

@adrian-gierakowski
Copy link
Contributor Author

So, do you think adding the capability to pass additional args from cli to the main process ran with run cmd would be enough for you to accept this PR? Do you have any comments or improvements suggestions regarding implementation?

@F1bonacc1
Copy link
Owner

So, do you think adding the capability to pass additional args from cli to the main process ran with run cmd would be enough for you to accept this PR? Do you have any comments or improvements suggestions regarding implementation?

Yes, it looks good. There are a few things that I would have done differently, some small typos and no documentation, but for a WIP PR, it's in a great shape :)

@adrian-gierakowski
Copy link
Contributor Author

Yes, it looks good. There are a few things that I would have done differently, some small typos and no documentation, but for a WIP PR, it's in a great shape :)

Ah yes, I’ll definitely add documentation. I’ll also double check for typos. Happy to make any further changes if you provide specific pointers. Thanks!

src/cmd/run.go Show resolved Hide resolved
src/types/process.go Outdated Show resolved Hide resolved
src/cmd/run.go Outdated
// runCmd represents the up command
var runCmd = &cobra.Command{
Use: "run [PROCESS]",
Short: "Run PROCESS in the forground (witn stdin, stdout, stderr attached), and and it's dependencies in the background",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos foreground, with

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to be pedantic, "it's" as well 😄
https://www.merriam-webster.com/grammar/when-to-use-its-vs-its

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And witn -> with 🤣

src/types/process.go Show resolved Hide resolved
src/command/command_wrapper.go Outdated Show resolved Hide resolved
src/app/commander_interface.go Outdated Show resolved Hide resolved
@adrian-gierakowski
Copy link
Contributor Author

@F1bonacc1 apologies for the long silence but I’ve been quite busy after coming back from holidays. I should have some time to work on this in about a week as I’ve got a couple of flights to take 😄

@F1bonacc1
Copy link
Owner

@F1bonacc1 apologies for the long silence but I’ve been quite busy after coming back from holidays. I should have some time to work on this in about a week as I’ve got a couple of flights to take 😄

@adrian-gierakowski,
Don't worry about it. I know the feeling all too well 😉

 ### process entrypoint

`entrypoint` is an optional array of strings which can be set on the process config
to override default shell (and shellArg) used to run the `command`

When `entrypoint` is set and is non-empty, `command` can also be omitted.

This is useful if one want's to:
1. use a different shell per process
2. run any other executable directly, without a shell wrapper

 ### `run` cmd

Equivalent of [docker-compose run](https://docs.docker.com/engine/reference/commandline/compose_run/)
which can be used to run a chosen process in the foreground (with std(in|out|err) attached),
while it's dependencies are ran in the background (no logs printed to stdio).

Deps can be disabled via --no-deps flag.

Additional arguments can be passed to the process after `--` separator, for example:

```sh
process-compose run main -- arg1 arg2
```

The separator is necessary in order to distinguish process-compose flags from flags
meant to be passed to the process.

While the process is running, the logs of the deps can be inspected using the
usual command:

```
process-compose process logs dep
```

The process being ran will have `availability.exit_on_end` set to `true` and
manually setting it to `false` will have no effect.
@adrian-gierakowski adrian-gierakowski marked this pull request as ready for review October 5, 2023 22:14
@adrian-gierakowski adrian-gierakowski changed the title [WIP] implement run cmd and allow running processes without shell wrapper implement process entrypoint and run cmd Oct 5, 2023
@adrian-gierakowski
Copy link
Contributor Author

@F1bonacc1 I believe I now got the desired behaviour implemented. I've updated PR description.

Still missing documentation, but I'll add this once the implementation is finished (in case you have any further comments you'd like me to address).

Not sure why tests are failing (haven't ran them before pushing), will have a look at it tomorrow.

@adrian-gierakowski
Copy link
Contributor Author

@F1bonacc1 not quite sure how to run the tests locally. There doesn't seem to be a way to do it via nix. And I also wasn't able to run the command which is used in github workflow from within nix develop. Would be great if instructions were added on the Readme about how to setup a dev environment, or at least allow the tests to be ran via nix flake check

@F1bonacc1
Copy link
Owner

@adrian-gierakowski,
You are right, I should have made it clearer in the Readme. Especially now when when there are more and more amazing contributions coming our way. Thank you for that!
If you have make you can run make testrace.
If not, go test -race ./src/... will do the trick.

@adrian-gierakowski
Copy link
Contributor Author

@adrian-gierakowski, You are right, I should have made it clearer in the Readme. Especially now when when there are more and more amazing contributions coming our way. Thank you for that! If you have make you can run make testrace. If not, go test -race ./src/... will do the trick.

no luck:

> nix develop
> make testrace
go test -race ./src/...
go: inconsistent vendoring in /home/adrian/code/process-compose:
	github.com/InVisionApp/go-health/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/adrg/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/cakturk/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/f1bonacc1/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/fatih/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gdamore/tcell/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gin-gonic/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gorilla/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/imdario/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/joho/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/rivo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/spf13/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/swaggo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	gopkg.in/natefinch/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	gopkg.in/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/InVisionApp/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/KyleBanks/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/bytedance/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/chenzhuoyu/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gabriel-vasile/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gdamore/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gin-contrib/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-playground/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-playground/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-playground/validator/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/goccy/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/inconshreveable/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/jezek/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/josharian/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/json-iterator/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/klauspost/cpuid/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/leodido/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/lucasb-eyer/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mailru/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mattn/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/modern-go/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/modern-go/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/pelletier/go-toml/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/rivo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/spf13/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/twitchyliquid64/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/ugorji/go/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	google.golang.org/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	gopkg.in/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mattn/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mattn/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/rs/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/swaggo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/swaggo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/InVisionApp/go-health/v2: is replaced in go.mod, but not marked as replaced in vendor/modules.txt
	github.com/cakturk/go-netstat: is replaced in go.mod, but not marked as replaced in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
make: *** [Makefile:53: testrace] Error 1

@F1bonacc1
Copy link
Owner

@adrian-gierakowski, You are right, I should have made it clearer in the Readme. Especially now when when there are more and more amazing contributions coming our way. Thank you for that! If you have make you can run make testrace. If not, go test -race ./src/... will do the trick.

no luck:

> nix develop
> make testrace
go test -race ./src/...
go: inconsistent vendoring in /home/adrian/code/process-compose:
	github.com/InVisionApp/go-health/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/adrg/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/cakturk/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/f1bonacc1/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/fatih/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gdamore/tcell/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gin-gonic/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gorilla/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/imdario/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/joho/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/rivo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/spf13/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/swaggo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	gopkg.in/natefinch/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	gopkg.in/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/InVisionApp/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/KyleBanks/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/bytedance/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/chenzhuoyu/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gabriel-vasile/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gdamore/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/gin-contrib/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-openapi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-playground/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-playground/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/go-playground/validator/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/goccy/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/inconshreveable/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/jezek/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/josharian/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/json-iterator/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/klauspost/cpuid/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/leodido/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/lucasb-eyer/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mailru/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mattn/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/modern-go/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/modern-go/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/pelletier/go-toml/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/rivo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/spf13/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/twitchyliquid64/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/ugorji/go/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	google.golang.org/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	gopkg.in/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mattn/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/mattn/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/rs/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/swaggo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/swaggo/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
	github.com/InVisionApp/go-health/v2: is replaced in go.mod, but not marked as replaced in vendor/modules.txt
	github.com/cakturk/go-netstat: is replaced in go.mod, but not marked as replaced in vendor/modules.txt

	To ignore the vendor directory, use -mod=readonly or -mod=mod.
	To sync the vendor directory, run:
		go mod vendor
make: *** [Makefile:53: testrace] Error 1

@adrian-gierakowski,
It looks like you need to get those packages first:

git clone https://github.com/F1bonacc1/process-compose.git
cd process-compose
go get ./...    # probably the missing step, please notice the 3 dots
make testrace

@adrian-gierakowski
Copy link
Contributor Author

still now luck:

> nix shell nixpkgs#go
> go get ./...
go: github.com/InVisionApp/go-health/[email protected] requires
	github.com/zaffka/[email protected]: invalid version: unknown revision 49954d88fa3e

I did manage to run the tests by commenting out this bit:

doCheck = false; # it takes ages to run the tests

and running nix build

however some tests timed out due to lack of python3 in the sandbox. I think I should be able to deal with that.

@adrian-gierakowski
Copy link
Contributor Author

with the following patch I am able to run tests with: nix flake check -L

diff --git a/flake.nix b/flake.nix
index 5d17b81..c5de5a9 100644
--- a/flake.nix
+++ b/flake.nix
@@ -22,6 +22,14 @@
           drv = self.packages."${system}".process-compose;
         };
         apps.default = self.apps."${system}".process-compose;
+        checks.default = self.packages."${system}".process-compose.overrideAttrs (prev: {
+          doCheck = true;
+          nativeBuildInputs =
+            prev.nativeBuildInputs
+            ++
+            (with nixpkgs.legacyPackages.${system}; [python3])
+          ;
+        });
       })

@adrian-gierakowski
Copy link
Contributor Author

@F1bonacc1 tests are fixed now

do let me know if you have any comments, improvement suggestions or if you'd like me to add some tests, thanks!

if you're happy with the implementation (or at least the interface), I'll start working on docs

src/app/project_runner.go Show resolved Hide resolved
src/cmd/run.go Outdated Show resolved Hide resolved
src/types/process.go Outdated Show resolved Hide resolved
src/types/process.go Outdated Show resolved Hide resolved
src/types/validators.go Show resolved Hide resolved
} else {
message := fmt.Sprintf("Either command or entrypoint need to be non-empty (procces: %s)", name)
fmt.Println(message)
log.Fatal().Msg(message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just realised that this is a breaking change, since previously empty command was allowed

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, ignore the empty command for now. I will fix it in the Strict mode.

@F1bonacc1
Copy link
Owner

Everything looks great @adrian-gierakowski!
I will wait for the documentation before merging.
I will need to move it to the new location that I plan to publish after the merge.
Spoiler: https://f1bonacc1.github.io/

this would be a breaking change as empty command was previously
allowed

also: log warning about both Command and Entrypoint being set
to stderr to not interfere with downstream consumers of stdout
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
2.0% 2.0% Duplication

p.command = command.BuildCommandShellArg(p.shellConfig, p.getCommand())
p.command = command.BuildCommand(
p.procConf.Executable,
append(p.procConf.Args, p.extraArgs...),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If p.procConf.Executable is bash and p.procConf.Args are []string{"-c", "echo Hi"}, p.extraArgs will be ignored.

Instead of that line, I call p.mergeExtraArgs():

func (p *Process) mergeExtraArgs() []string {
	if len(p.extraArgs) == 0 {
		return p.procConf.Args
	}
	tmp := make([]string, len(p.procConf.Args))
	copy(tmp, p.procConf.Args)
	if isStringDefined(p.procConf.Command) {
		lastArg := p.procConf.Args[len(p.procConf.Args)-1]
		lastArg += " " + strings.Join(p.extraArgs, " ")
		return append(tmp[:len(tmp)-1], lastArg)
	} else if len(p.procConf.Entrypoint) > 0 {
		return append(tmp, p.extraArgs...)
	}
	return p.procConf.Args
}

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give an example of the final command you’d like executed?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processes:
  ls:
    command: "ls"
process-compose run ls -- /tmp

run ls will ignore the extraArg /tmp
It worked well with entrypoint instead of command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prints: args: 0 1 2

bash -c 'echo args: $0 $1 $2' 0 1 2 

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try:

bash -c "ls" /tmp

vs.

bash -c "ls /tmp"

@F1bonacc1 F1bonacc1 merged commit 48e7711 into F1bonacc1:main Nov 18, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants