How to correctly set env variables in oh-my-zsh - oh-my-zsh

I am new to use oh-my-zsh and couldnt figure out where can I add a new env variable which we usually add in .zshrc file. Now the new zshrc file(after installing oh-my-zsh) does not show any of my already added env variables also.
I am using macbook(m1/apple) chip with oh-my-zsh. How or where can I add a new env variable. For example before using oh-my-zsh, I used to add the following lines in ~./zshrc and source the file/open a new terminal to reflect the changes.
eval "$(~/.rbenv/bin/rbenv init - zsh)"
export PATH="$HOME:/.rbenv/versions/3.1.3/bin

Related

System.getenv() not showing last added environment variables

I want to access to some environment variables that I set on .bashrc but i cannot get it using System.getenv(), I am using Intellij-idea ultimate on Ubuntu Linux.
On .bashrc i have:
export TWILIO_SMS_SERVICE_SID="XXXXXXXXXX"
export TWILIO_ACCOUNT_SID="XXXXXXXXXX"
export TWILIO_AUTH_TOKEN="XXXXXXXXXX"
Running on command line $ echo $TWILIO_SMS_SERVICE_SID i got the correct value XXXXXXXXXX.
But this System.getenv("TWILIO_SMS_SERVICE_SID") returns null.
When i run this, i got all the environment variables but not the last that i added:
println("Environment variables: ")
System.getenv().forEach { (key, value) -> println("$key: $value") }
Do you know what the causes might be or how to fix it?
p.s: sorry, I have no idea how to do a POC about this, I am open to any suggestion.
Did you start the Java program directly from IntelliJ IDEA? Depending on how you started it, it might not have the environment variables set, as ~/.bashrc might only be evaluated when you start a bash shell. It should work if you start IntelliJ IDEA (or just your Java program) from the bash shell that has the environment variables set.

How to dynamically set an ENV variable using a Dockerfile

I have a Dockerfile that has access to a variable that indicates the environment it is being targeted to. Our CICD pipeline makes this environment variable available to the Dockerfile and I can test for a particular environment using "Run if $Environment =".
When I detect a "test" environment, I need to create another environment variable on-the-fly. However, code like this doesn't seem to work:
RUN if $Environment="test" ; then ; /
ENV NewEnvironmentVariable = "test" ; /
fi
The get "ENV" not found when it runs. So obviously, you can't use ENV this way within a RUN .. if.
I CAN however, use bash commands to export the variable, but it's probably creating this export in a different context, so, the Dockerfile doesn't have access to it. I would have thought that exporting it would make the new environment variable to the Docker file (when it returns from the "if" block.
In short, I simply need to evaluate and existing environment variable and if it contains the value I'm looking for it will create a new ENV variable just as if I have done "ENV MyNewVar=1".
Is this possible?
Thanks

How is NODE_ENV set in OpenShift?

I've read of the dangers of not having NODE_ENV properly set in Express. In my OpenShift app, I can display NODE_ENV through a simple Express route and a console.log statement, but I can't see it anywhere else, e.g. with the env command at the SSH prompy. How/where is it set?
In mine (and this differs from what you might find in the documentation), it's set in a file at nodejs/configuration/node.env in the gear. To reach it, you can use the cloud console tools - rhc ssh -a your-app-name. In that file, you should see something like
#This file specifies the environment to setup prior to running Node.
...
# Default script name used is server.js
export node_app=server.js
#Any arguments to pass to the application or script.
export node_app_args=""
#Any command line options to pass to Node.
#E.g. export node_opts="--stack-size=2048 --trace_gc"
export node_opts=""
...
#Node production mode turned on by default
export NODE_ENV=${NODE_ENV:-"production"}
...which also lets you set up other configuration options. Hope that helps, it took a bit of searching when I first had to do it.

How to define a variable in a Dockerfile?

In my Dockerfile, I would like to define variables that I can use later in the Dockerfile.
I am aware of the ENV instruction, but I do no want these variables to be environment variables.
Is there a way to declare variables at Dockerfile scope?
You can use ARG - see https://docs.docker.com/engine/reference/builder/#arg
The ARG instruction defines a variable that users can pass at
build-time to the builder with the docker build command using the
--build-arg <varname>=<value> flag. If a user specifies a build
argument that was not defined in the Dockerfile, the build outputs an
error.
Can be useful with COPY during build time (e.g. copying tag specific content like specific folders)
For example:
ARG MODEL_TO_COPY
COPY application ./application
COPY $MODEL_TO_COPY ./application/$MODEL_TO_COPY
While building the container:
docker build --build-arg MODEL_TO_COPY=model_name -t <container>:<model_name specific tag> .
To answer your question:
In my Dockerfile, I would like to define variables that I can use later in the Dockerfile.
You can define a variable with:
ARG myvalue=3
Spaces around the equal character are not allowed.
And use it later with:
RUN echo $myvalue > /test
To my knowledge, only ENV allows that, as mentioned in "Environment replacement"
Environment variables (declared with the ENV statement) can also be used in certain instructions as variables to be interpreted by the Dockerfile.
They have to be environment variables in order to be redeclared in each new containers created for each line of the Dockerfile by docker build.
In other words, those variables aren't interpreted directly in a Dockerfile, but in a container created for a Dockerfile line, hence the use of environment variable.
This day, I use both ARG (docker 1.10+, and docker build --build-arg var=value) and ENV.
Using ARG alone means your variable is visible at build time, not at runtime.
My Dockerfile usually has:
ARG var
ENV var=${var}
In your case, ARG is enough: I use it typically for setting http_proxy variable, that docker build needs for accessing internet at build time.
Christopher King adds in the comments:
Watch out!
The ARG variable is only in scope for the "stage that it is used" and needs to be redeclared for each stage.
He points out to Dockerfile / scope
An ARG variable definition comes into effect from the line on which it is defined in the Dockerfile not from the argument’s use on the command-line or elsewhere.
For example, consider this Dockerfile:
FROM busybox
USER ${user:-some_user}
ARG user
USER $user
# ...
A user builds this file by calling:
docker build --build-arg user=what_user .
The USER at line 2 evaluates to some_user as the user variable is defined on the subsequent line 3.
The USER at line 4 evaluates to what_user as user is defined and the what_user value was passed on the command line.
Prior to its definition by an ARG instruction, any use of a variable results in an empty string.
An ARG instruction goes out of scope at the end of the build stage where it was defined.
To use an arg in multiple stages, each stage must include the ARG instruction.
If the variable is re-used within the same RUN instruction, one could simply set a shell variable. I really like how they approached this with the official Ruby Dockerfile.
You can use ARG variable defaultValue and during the run command you can even update this value using --build-arg variable=value. To use these variables in the docker file you can refer them as $variable in run command.
Note: These variables would be available for Linux commands like RUN echo $variable and they wouldn't persist in the image.
Late to the party, but if you don't want to expose environment variables, I guess it's easier to do something like this:
RUN echo 1 > /tmp/__var_1
RUN echo `cat /tmp/__var_1`
RUN rm -f /tmp/__var_1
I ended up doing it because we host private npm packages in aws codeartifact:
RUN aws codeartifact get-authorization-token --output text > /tmp/codeartifact.token
RUN npm config set //company-123456.d.codeartifact.us-east-2.amazonaws.com/npm/internal/:_authToken=`cat /tmp/codeartifact.token`
RUN rm -f /tmp/codeartifact.token
And here ARG cannot work and i don't want to use ENV because i don't want to expose this token to anything else

ansible playbooks get which variable file by default if not defined

I have a devop directory containing ansible's varible directroy , plabooks and inventory directory
The directory looks like this
|groups_vars
-all.yml
-development.yml
-staging.yml
|inventroy
- staging
- development
configure.yml
deploy.yml
configure.yml and deploy.yml contains task that are applied to either staging or development machines using variable in groups_vars
Know if i call ansible-playbook command with staging inventory. How will it know which variable file to use. The varfile task in not added to configure.yml and deploy.yml
By the way am using an example from the company i work and the example is working I just want to know the magic that is happening it is using the right variable file though the var file is not incuded in the configure.yml nor deploy.yml
Ansible uses a few conventions to load vars files:
group_vars/[group]
host_vars/[host]
So if you have an inventory file that looks like this:
[staging]
some-host.name.com
Then These files will be included (optional extension .yml or .yaml also):
/group_vars/all
/group_vars/staging
/host_vars/some-host.name.com
I think this is the "magic" you are referring to.
You can find more on the subject here: http://docs.ansible.com/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
And here: http://docs.ansible.com/playbooks_best_practices.html