Hello all, I am trying to set an environment variable on the fly in a docker build. This is my Dockerfile
FROM atlassian/default-image:3
ARG CACHEBUST=1
WORKDIR /tmp
COPY ./build /tmp/build
RUN chmod -R +x /tmp/build
CMD source /tmp/build/scriptenv.sh
ENV PYTHONV $(python3 -c "exec(\"import sys\nprint(f'{sys.version_info.major}.{sys.version_info.minor}')\")")
#RUN python3 /tmp/build/setenv.py
RUN echo $PYTHONV
And the PYTHONV echoed the string, kinda expected. So I tried
FROM atlassian/default-image:3
ARG CACHEBUST=1
WORKDIR /tmp
COPY ./build /tmp/build
RUN chmod -R +x /tmp/build
RUN source /tmp/build/scriptenv.sh
#ENV PYTHONV $(python3 -c "exec(\"import sys\nprint(f'{sys.version_info.major}.{sys.version_info.minor}')\")")
#RUN python3 /tmp/build/setenv.py
RUN echo $PYTHONV
With scriptenv.sh being:
export PYTHONV=$(python3 -c "exec(\"import sys\nprint(f'{sys.version_info.major}.{sys.version_info.minor}')\")")
Yet it outputs a blank string.
For reference, this is what the string outputs:
user@user-VirtualBox:~$ python3 -c "exec(\"import sys\nprint(f'{sys.version_info.major}.{sys.version_info.minor}')\")"
3.8
I cannot specify the environment variable before. It has to be during runtime since its based on âatlassian/default-image:3â and the Python version could change.
I need to get the Python version so I can install the correct packages.
What can I do?