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

Exporting environment variables in CMD do not persist in next command #696

Open
marschro opened this issue Apr 21, 2024 · 6 comments
Open

Comments

@marschro
Copy link

marschro commented Apr 21, 2024

[MANDATORY] Describe the bug [MANDATORY]
I have the following Bastillefile:

ARG ENV_FOO
ARG ENV_BAR

CMD export FOO=${ENV_FOO}
CMD export BAR=${ENV_BAR}

CMD echo $FOO
CMD echo "expected output should be 'Foo' - but is empty. env variable is not set in consecutive commands"
  • Setting environment variables is not possible with this approach.
  • I currently set environment variables with the following workaround:
    CMD env APP_PHX_SERVER=${app_phx_server} env APP_DATABASE_URL=${app_database_url} env APP_SECRET_KEY_BASE=${app_secret_key_base} boot_my_app"

... which is working but is not readable and not well maintainable as along long one-liner (there are much more variables to set in my real project)

[MANDATORY] Bastille and FreeBSD version (paste bastille -v && freebsd-version -kru output)

  • 0.10.20231125
  • 14.0-RELEASE-p6
  • shell is posix compliant (sh)

[MANDATORY] How did you install bastille? (port/pkg/git)

  • pkg

[optional] Steps to reproduce?

  • none

[optional] Expected behavior

  • Environment variables that are exported in a CMD should be accessible in the following CMDs

[optional] Screenshots

  • none

[optional] Additional context

  • I checked multiple things, also sourcing a rendered .env file. These sourced variables also do not persist...
  • I generally do not understand, why that happens.
  • I guess, the process, that "terraforms" the jail is different from those, executing the commands...?
  • It might be, that I completely lack the knowledge and doing sth obviously wrong...
@marschro marschro added the bug Something isn't working label Apr 21, 2024
@michael-o
Copy link
Contributor

I don't consider this is a bug. Each CMD is completely standalone. That would require a new ENV section.

@marschro
Copy link
Author

Thanks, @michael-o - I guessed that already.
An ENV section for the future would probably be nice. For now it works.

I would also be interested, how other people solve this.
Another way to do that is, a script, that is rendered with the variables, by Bastille, then is executed, and right after deleted... as one does not want to values to be somewhere readable in a file on the server.
Or would you say, that this is fine, or what would be best practice here?

I guess I can close this then - or is that something to keep?
Kind regards,
Martin

@yaazkal yaazkal removed the bug Something isn't working label Jul 18, 2024
@yaazkal
Copy link
Collaborator

yaazkal commented Jul 18, 2024

A script is usually the way to go. You can check something like the wordpress template as an example.

@yaazkal yaazkal changed the title [BUG] - Exporting environment variables in CMD do not persist in next command Exporting environment variables in CMD do not persist in next command Jul 18, 2024
@marschro
Copy link
Author

marschro commented Aug 9, 2024

A script is usually the way to go. You can check something like the wordpress template as an example.

Hi @yaazkal - yes. I had that also first. But that means that I have to write the secure credentials into that script file.
Alternatively, could RENDER the credentials, provided by the CI/CD system to that script file.
But... then I still have the credentials written to a file in the system what I want to avoid.
I could then after starting the system, delete the file again... but that all feels like "von hinten durch die Brust".

Does anyone know if I could at least write multiline in the Bastillefile ? like so...

CMD do this \
 do one thing \
 and then another \
 and so on

@michael-o
Copy link
Contributor

@marschro ...durch die Brust in die Anus

@tschettervictor
Copy link
Collaborator

I’ve resolved to just use simple sh scripts as opposed to templates for this reason. It’s just easier to work with, especially when doing conditional commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants