cirruslabs / gitlab-tart-executor

GitLab Runner executor to run jobs in Tart VMs
MIT License
60 stars 5 forks source link

using TART_EXECUTOR_SHELL does not initialize the environment #45

Closed umlaeute closed 11 months ago

umlaeute commented 11 months ago

we are using tart for running gitlab-ci pipelines (great project btw, it's really the thing i've been looking for)

now, a couple of our pipelines have code like this:

FLAGS="--foo --bar"
./somecmd ${FLAGS}

under bash (which used to be the default shell for all our cross-platform pipelines until now) this will run ./somecmd --foo --bar.

however, the tart executor defaults to using zsh, which does not do word-splitting for non-quoted variables, and the command excuted is effectively ./somecmd "--foo --bar", which of course is something completely different.

now seeing that there is a TART_EXECUTOR_SHELL variable that i can set to bash, i figured that this would solve my problems... only to discover, that the bash-environment significantly differs from the default environment.

for me the difference is most prominently the lack of the brew, which stems from paths not being initialized.

so here's a test-pipeline to examine the current behaviour

sonoma:
  tags:
    - tart
  image: ghcr.io/cirruslabs/macos-sonoma-xcode:latest
  script:
    - echo $PATH
    - which brew

sonoma-matrix:
  extends: sonoma
  parallel:
    matrix:
      - TART_EXECUTOR_SHELL:
        - bash
        - zsh

which gives me one successful job (where TART_EXECUTOR_SHELL is unset) and two failing ones (where it is set):

TART_EXECUTOR_SHELL brew available? $PATH
-- :tada: /Users/admin/flutter:/Users/admin/flutter/bin/:/Users/admin/flutter/bin/cache/dart-sdk/bin:/usr/local/bin/:/Users/admin/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/admin/android-sdk/cmdline-tools/latest/bin:/Users/admin/android-sdk/platform-tools:/Users/admin/android-sdk/emulator
bash :boom: /usr/bin:/bin:/usr/sbin:/sbin
zsh :boom: /usr/bin:/bin:/usr/sbin:/sbin

is this expected behaviour?

umlaeute commented 11 months ago

just for completeness sake: the original problem i'was trying to solve with using TART_EXECUTOR_SHELL (that zsh does not do word-splitting on unquoted variables), can be worked around by adding something like this to the pipeline:

set -o shwordsplit || true

but it nevertheless seems that the TART_EXECUTOR_SHELL's usefulness is severely lessened if many tools cannot be used when it is set.

edigaryev commented 11 months ago

I think this can be accomplished by simply starting a login shell (the one that reads .profile and other files).

For example, if you need Bash, use TART_EXECUTOR_SHELL="bash -l".

I've created https://github.com/cirruslabs/gitlab-tart-executor/pull/46 to better document this.

umlaeute commented 11 months ago

indeed that seems to do the trick.

i didn't check the code, so I assumed that TART_EXECUTOR_SHELL could have exactly three values (bash, zsh and none), rather than some arbitrary value.

thanks for the documentation update.