butido icon indicating copy to clipboard operation
butido copied to clipboard

/script does not contain every information it uses (environment variable, complete submit line, ...)

Open christophprokop opened this issue 2 years ago • 1 comments

/script is still missing some information

christophprokop avatar Mar 14 '23 15:03 christophprokop

I just had a look at this and it should be possible to better support this via the butido db job command:

$ butido db job -h
Show a specific job from the DB

Usage: butido db job [OPTIONS] <UUID>

Arguments:
  <UUID>  The job to show

Options:
      --csv              Format output as CSV
  -L, --log              Show the log
  -s, --script           Show the script
  -E, --env              Show the environment of the job
      --line-numbers     Print script with line numbers (default)
      --no-line-numbers  Print script without line numbers
      --highlighting     Print script with highlighting (default)
      --no-highlighting  Print script without highlighting
  -h, --help             Print help

The --env and --script options can already be combined to output the relevant information, e.g.:

$ butido db job -Es eb5c3981-9911-4c6e-9e84-aa20ccba6723
Job:        eb5c3981-9911-4c6e-9e84-aa20ccba6723
Submit:     4d88dc63-7c6f-4b5d-99fb-230134765aec
Succeeded:  yes
Package:    tree 1.8.0

Ran on:     bonnie
Image:      local:rh8-default
Container:  af8b07b356bd2f6ab636aebc382def0aee8318e4b8b41a68cba38048f53f5c51

Script:     1276 lines
Log:        286  lines


---

          0. MAKE_INSTALL_PARALLEL=1
          1. BUILD_ROOT=/build
          2. MAKE_PARALLEL=2
          3. BUILD_DIR=/build
          4. ADDITIONAL_MAKE_FLAGS=
          5. GIT_AUTHOR_INFO=Michael Weiss
          6. PACKAGE_RELEASE=2
          7. ADDITIONAL_MAKE_TEST_FLAGS=
          8. GIT_COMMIT_HASH=d587fbb97ab2e84fdc7470b6ea447d0147bdc268


---

   1 | #!/bin/bash
   2 | ### phase framework-pre
[...]

@christophprokop: My proposal would be to make --no-line-numbers also apply to the environment variables and print export before each environment variable (optionally only when using --no-line-numbers) so that we can produce the following output that would be easy to copy and paste:

$ butido db job --script --env --no-line-numbers --no-highlighting eb5c3981-9911-4c6e-9e84-aa20ccba6723
Job:        eb5c3981-9911-4c6e-9e84-aa20ccba6723
Submit:     4d88dc63-7c6f-4b5d-99fb-230134765aec
Succeeded:  yes
Package:    tree 1.8.0

Ran on:     bonnie
Image:      local:rh8-default
Container:  af8b07b356bd2f6ab636aebc382def0aee8318e4b8b41a68cba38048f53f5c51

Script:     1276 lines
Log:        286  lines


---

export MAKE_INSTALL_PARALLEL=1
export BUILD_ROOT=/build
export MAKE_PARALLEL=2
export BUILD_DIR=/build
export ADDITIONAL_MAKE_FLAGS=
export GIT_AUTHOR_INFO=Michael Weiss
export PACKAGE_RELEASE=2
export ADDITIONAL_MAKE_TEST_FLAGS=
export GIT_COMMIT_HASH=d587fbb97ab2e84fdc7470b6ea447d0147bdc268


---

#!/bin/bash
### phase framework-pre

What do you think? Is there anything else that we need?

And I just realized that IIRC the goal was also to "debug" scripts by running /script inside the containers (e.g., docker exec af8b07b356bd /script)? That should already be possible as the environment variables are set through the container configuration ($PATH isn't included in the db job --env output as it comes from the base image):

$ docker container inspect --format='{{.Config.Env}}' af8b07b356bd
[GIT_AUTHOR_INFO=Michael Weiss GIT_COMMIT_HASH=d587fbb97ab2e84fdc7470b6ea447d0147bdc268 ADDITIONAL_MAKE_FLAGS= MAKE_PARALLEL=2 PACKAGE_RELEASE=2 MAKE_INSTALL_PARALLEL=1 BUILD_DIR=/build BUILD_ROOT=/build ADDITIONAL_MAKE_TEST_FLAGS= PATH=[...]]

I also noticed that /script isn't executable and I'd say that we should set the exec file mode bit (to avoid having to use bash /script):

$ docker exec af8b07b356bd /script
OCI runtime exec failed: exec failed: unable to start container process: exec: "/script": permission denied: unknown
$ docker exec af8b07b356bd ls -l /script
-rw-r--r-- 1 root root 37446 Jan  1  1970 /script

primeos-work avatar Dec 04 '23 13:12 primeos-work