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

Unable to run arbitrary code snippets using the "script" directive #510

Open
ohourcard opened this issue Dec 30, 2023 · 6 comments
Open
Labels
accepted feature request New feature or request good first issue Good for newcomers

Comments

@ohourcard
Copy link

Hello,

I'm unable to run arbitrary code snippets using the "script" directive.

Sample (simple) DAG:

steps:
  - name: step 1
    command: bash
    script: |
      echo "hello world"

Encountered error (whatever shell or other command is declared in "command"):

+---+--------+---------------------+---------------------+--------+---------+------------------+
| # | STEP | STARTED AT | FINISHED AT | STATUS | COMMAND | ERROR |
+---+--------+---------------------+---------------------+--------+---------+------------------+
| 1 | step 1 | 2023-12-30 15:07:44 | 2023-12-30 15:07:44 | failed | bash | invalid argument |
+---+--------+---------------------+---------------------+--------+---------+------------------+

Any clue of what's going wrong?

Thanks,
Oliver

@yohamta
Copy link
Collaborator

yohamta commented Dec 30, 2023

Hello, thanks for the question.
I tried the same DAG on my local computer and it seems working fine.
Would you mind share the Dagu version are you using?

image

@ohourcard
Copy link
Author

Thanks for your answer!
I'm using dagu v1.12.7

@yohamta
Copy link
Collaborator

yohamta commented Dec 30, 2023

Thanks for letting me know!
Internally, Dagu works this way:

  1. write the script to an arbitrary temp file.
  2. execute the command passing the temp file as the single parameter to the command.

So, I think one possible cause could be the bash command setting in your environment.
Could you please check if bash command works by running the command bash hello_world.sh in your computer.

@ohourcard
Copy link
Author

Yohamta,

I don't think the issue is related to the interpreter or any other command (I've tried many combination of bash/zsh or any command): in fact, since I use the "script" directive I've got this error (the "command" directive works fine unitarily).

Is there any chance that the temp file may be deleted before being executed?

The detail of my environment follows:

DEBIAN:
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm

BASH:
debian@dagu ➜ ~ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
Licence GPLv3+ : GNU GPL version 3 ou ultérieure http://gnu.org/licenses/gpl.html

Running a sample bash script from the host

Sample script

#/bin/bash
echo "hello world"

dagu@dagu$ bash test.sh
hello world

dagu@dagu$ bash | echo test
test

Can you lead me to the part of the code handling that temp file creation ? I'm not pretty familiar with Go...

Regards,
Oliver

@ohourcard
Copy link
Author

After further investigations, this seems to be related to permissions on my environment.

When I force the working dir on the DAG's step (e.g. /tmp), the task is perfectly executed:

image

image

As I can see in the repository, the module in charge of generating the tempfile is "internal/schedule/node" and expecially the function "setupScript". Maybe it will be a good idea to add/perform addtional checks on the generated temporary file?

I'll invetigate further to identify those permissions issues.

Regards,
Oliver

@yohamta
Copy link
Collaborator

yohamta commented Dec 31, 2023

Hi Oliver, thanks for your thorough investigation and the great suggestion!

You're right about the "internal/schedule/node", it is responsible for creating a tempfile.

Maybe it will be a good idea to add/perform addtional checks on the generated temporary file?

I agree, it seems definitely better and we can make the error message to be more user-friendly.

@yohamta yohamta added feature request New feature or request good first issue Good for newcomers labels Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted feature request New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants