Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Add support to get config variable from CLI #549

Closed
hpcsc opened this issue Jun 3, 2020 · 11 comments
Closed

Add support to get config variable from CLI #549

hpcsc opened this issue Jun 3, 2020 · 11 comments

Comments

@hpcsc
Copy link
Contributor

hpcsc commented Jun 3, 2020

It would be nice if batect can provide a CLI command to get config variable by name (with consideration of config variable files, override variables etc)

Scenario:
Currently we use batect config variables to keep repo-wide variables in a central place (.e.g. component name to be used in the code, infra code etc). There are a few exceptional cases where we want to get the same variable names to be used outside of batect like:

  • display in git commit hooks
  • docker build and push (which we do it from the host instead of using batect for simplicity)

we can do some scripting like using grep and sed but feel hacky. It would be much nicer to have it supported directly from batect like:

./batect --config-var=component_name
@charleskorn
Copy link
Collaborator

@hpcsc
Copy link
Contributor Author

hpcsc commented Jun 3, 2020

hey @charleskorn

No, I'm looking for way to get the value of config var to use outside of batect, not to set it

@charleskorn
Copy link
Collaborator

Ah sorry, I misread your question. There's no built-in way to do that at the moment, but as a workaround, you could achieve the same thing by creating a task that prints the value to the console, and then running the task in quiet mode (--output=quiet):

print-git-sha:
  run:
    container: # anything with a shell
    command: sh -c "echo $GIT_SHA"
    environment:
      GIT_SHA: <{GIT_SHA}
$ ./batect --config-var GIT_SHA=abc123 --output=quiet print-git-sha
abc123

@hpcsc
Copy link
Contributor Author

hpcsc commented Jun 4, 2020

thanks @charleskorn
that's a good work around for us for now

@hpcsc
Copy link
Contributor Author

hpcsc commented Oct 1, 2020

hey @charleskorn , could I check with you one more thing related to this issue: so far we have used your workaround above in our pipeline like this:

NAME=$(./batect  --output=quiet --no-update-notification get-name)

This works fine when batect is already cached in build agents. When it's not, the command above will download batect and the variable NAME contains the log as the result of downloading.

I take a brief look at the wrapper and there's a variable BATECT_QUIET_DOWNLOAD but it doesn't suppress the curl output. Is that something intended? Is there any way to suppress all the download log?

@charleskorn
Copy link
Collaborator

That looks like a bug - the wrapper should be passing --silent to curl to suppress the output when BATECT_QUIET_DOWNLOAD is set. For the time being, you could modify your wrapper script to include this.

charleskorn added a commit that referenced this issue Oct 1, 2020
@hpcsc
Copy link
Contributor Author

hpcsc commented Oct 1, 2020

awesome, thanks for the fast reply (and commit). Will do some workaround for now and wait for the next version with this change

@stale
Copy link

stale bot commented Feb 28, 2021

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues.
If this issue is still affecting you, please comment below within the next seven days.
Thank you for your contributions.

@stale stale bot added the stale label Feb 28, 2021
@stale
Copy link

stale bot commented Mar 7, 2021

This issue has been automatically closed because it has not had any recent activity.

@stale stale bot closed this as completed Mar 7, 2021
@davified
Copy link

davified commented Aug 4, 2021

Hi @charleskorn , thanks for the great work on batect!

I have a question related to this issue. If I should open a new issue instead, please let me know.

Our scenario:

  • While some of our env vars are static values, some are dynamic (see GIT_BRANCH, GIT_COMMIT and USERNAME)
my-task:
    build_directory: .
    build_target: dev
    volumes:
      - local: .
        container: /app
    working_directory: /app
    environment:
      GIT_BRANCH: ${CI_GIT_BRANCH:-<computed git branch>}
      GIT_COMMIT: ${CI_GIT_COMMIT:-<computed git commit>}
      USERNAME: $(echo ${USER} | sed 's/[\.\_]//g') # USER without punctuations
      <<: *common-static-vars

May I know if there's a way to define these dynamic config vars so that it's computed at the time of running the batect tasks?

Thank you!

@charleskorn
Copy link
Collaborator

Hey @davified, I've moved this over to a new issue: #950 - let's discuss this there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants