Webhook: Misunderstanding of `command-working-directory` and `execute-command` aka MAYBE a weird behavior

Created on 30 Oct 2020  路  10Comments  路  Source: adnanh/webhook

Hi!

I've explored something that should work and found out a weird behavior 馃槃

Let's take a simple echo example to see where I may messed up!

Working example:

- id: ping
  execute-command: ./webhooks/ping/trigger.sh
  command-working-directory: ./
  response-message: Ping it
#!/bin/sh
echo "Pong"
ls

It's perfect, it's working as intended.

webhook] 2020/10/30 11:04:46 [b60587] executing ./webhooks/ping/trigger.sh (./webhooks/ping/trigger.sh) with arguments ["./webhooks/ping/trigger.sh"] and environment [] using ./ as cwd
[webhook] 2020/10/30 11:04:46 [b60587] command output: Pong
Makefile
bash
cmd
docker
docs
envs
go.mod
go.sum
kubernetes
makefiles
readme.md
templates
tmp
webhooks

[webhook] 2020/10/30 11:04:46 [b60587] finished handling ping

Now let's spice it a little bit, I've read on the Hook Definition that execute-command is for the path of the script and command-working-directory is what the script will have as a root folder when it's triggered.

So, normally, if I keep the same execute-command but put the path of the webhooks as a command-working-directory it should work the same way, right?

Let's do an intermediate example before getting to the point, let's replace the execute-command with a simple ls and replace the command-working-directory with the path to the hook folder.

- id: ping
  execute-command: ls
  command-working-directory: ./webhooks/ping
  response-message: Ping it
[webhook] 2020/10/30 11:08:59 [a4f1c9] executing ls (/usr/bin/ls) with arguments ["ls"] and environment [] using ./webhooks/ping as cwd
[webhook] 2020/10/30 11:08:59 [a4f1c9] command output: hook.yaml
lib
trigger.sh

[webhook] 2020/10/30 11:08:59 [a4f1c9] finished handling ping

It's working, I see my files, BUT what if now I change the execute-command to the path to trigger.sh ?

- id: ping
  execute-command: ./webhooks/ping/trigger.sh
  command-working-directory: ./webhooks/ping
  response-message: Ping it

Nothing changes here

#!/bin/sh
echo "Pong"
ls
[webhook] 2020/10/30 11:10:30 Started GET /hooks/ping
[webhook] 2020/10/30 11:10:30 [177999] incoming HTTP request from [::1]:55064
[webhook] 2020/10/30 11:10:30 [177999] ping got matched
[webhook] 2020/10/30 11:10:30 [177999] ping hook triggered successfully
[webhook] 2020/10/30 11:10:30 Completed 200 OK in 180.8碌s
[webhook] 2020/10/30 11:10:30 [177999] executing ./webhooks/ping/trigger.sh (./webhooks/ping/trigger.sh) with arguments ["./webhooks/ping/trigger.sh"] and environment [] using ./webhooks/ping as cwd
[webhook] 2020/10/30 11:10:30 [177999] command output:
[webhook] 2020/10/30 11:10:30 [177999] error occurred: fork/exec ./webhooks/ping/trigger.sh: no such file or directory
[webhook] 2020/10/30 11:10:30 [177999] finished handling ping

I got an error that should found the file since with ls it can deplay it as a command-working-directory but still not find it...

Did I miss something? It is an unwanted behavior? I don't know! 馃槃

question

Most helpful comment

Official binary releases are available at https://github.com/adnanh/webhook/releases. The only package we maintain is the snap package. Whatever else is out there is maintained by 3rd parties.

Noted! I've installed the 2.7.0

So, I have the same behavior with the command-working-directory and execute-command, the logs show the correct paths but failed to find the sh.

BUT you were right on the absolute path! It's working with it so I will generate them dynamically from now 馃槃

Thx for the help! I'm closing the issue!

All 10 comments

Two things. One, clarification: it does not affect the "root" directory - that sounds like a chroot call, which is not performed. It affects the WORKING directory. The difference is crucial, and if it doesn't make sense then I'd suggest looking up what chroot does to see why.

Two, an answer: what you're saying with your definition, translated into english, is "go into this directory, and call this command". For commands on your $PATH, the cwd won't affect finding them. For the case of command with a relative path (like ./webhooks/ping/trigger.sh) however, it will. What the handler is trying to do is go into the directory ./webhooks/ping/ and _then_ look for a ./webhooks/ping/trigger.sh file _in there_. In essence, from the "origin point" of whatever webhook has for a cwd, it's looking for ./webhooks/ping/webhooks/ping/trigger.sh to run within ./webhooks/ping/.

Yes, it might be a little counterintuitive. It's changing the cwd, _then_ looking for the command _within_ that cwd, not just launching the command within the specified directory. But if you treat it like a shell, it'll make sense: "go here, then run this command".

Sorry if this isn't very clear, I just woke up. Brain's stil a little laggy.

Sorry if this isn't very clear, I just woke up. Brain's stil a little laggy.

Do not worry about that ahah Good morning!

So, if I understood correctly what you said, this should works:

- id: ping
  execute-command: ./trigger.sh
  command-working-directory: ./webhooks/ping
  response-message: Ping it

But it doesn't works the way I understood what you're describing:

[webhook] 2020/10/30 14:52:53 Started GET /hooks/ping
[webhook] 2020/10/30 14:52:53 [634aa4] incoming HTTP request from [::1]:57784
[webhook] 2020/10/30 14:52:53 [634aa4] ping got matched
[webhook] 2020/10/30 14:52:53 [634aa4] ping hook triggered successfully
[webhook] 2020/10/30 14:52:53 Completed 200 OK in 270.6碌s
[webhook] 2020/10/30 14:52:53 unable to locate command: './trigger.sh'

What version of webhook?

On a side note: I don't know how you're running webhook, but I would recommend using an absolute path for command-working-directory. I like to be absolutely sure of what I'm executing as opposed to being relatively sure. :smiley:

What version of webhook?

This one: webhook version 2.6.9

On a side note: I don't know how you're running webhook, but I would recommend using an absolute path for command-working-directory. I like to be absolutely sure of what I'm executing as opposed to being relatively sure. 馃槂

I'll try!!

On a side note: I don't know how you're running webhook, but I would recommend using an absolute path for command-working-directory. I like to be absolutely sure of what I'm executing as opposed to being relatively sure. 馃槂

Even with an absolute path, doesn't reach the file!

I tried sooo many combinaison xD

This issue was previously reported in #316 which was fixed in 2.6.10. Try a newer version, and you should be good to go.

This issue was previously reported in #316 which was fixed in 2.6.10. Try a newer version, and you should be good to go.

Alriiight ! I'll update everything and I'll close the issue when if it's fixed! 馃槃

This issue was previously reported in #316 which was fixed in 2.6.10. Try a newer version, and you should be good to go.

Is the 2.6.10 is updated on the linux repositories? It seems I'm commands doesn't find 2.6.10 but only 2.6.9

Official binary releases are available at https://github.com/adnanh/webhook/releases. The only package we maintain is the snap package. Whatever else is out there is maintained by 3rd parties.

Official binary releases are available at https://github.com/adnanh/webhook/releases. The only package we maintain is the snap package. Whatever else is out there is maintained by 3rd parties.

Noted! I've installed the 2.7.0

So, I have the same behavior with the command-working-directory and execute-command, the logs show the correct paths but failed to find the sh.

BUT you were right on the absolute path! It's working with it so I will generate them dynamically from now 馃槃

Thx for the help! I'm closing the issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wranitzky picture wranitzky  路  6Comments

macau23 picture macau23  路  6Comments

scalp42 picture scalp42  路  4Comments

zoenglinghou picture zoenglinghou  路  4Comments

foosinn picture foosinn  路  5Comments