Execute python code while container is creating

me again

I’m have problem to execute a python file while the container is creating. I don’t know if is possible, maybe i’m wrong. Is for that reasson that i’m here to ask for help

this is my Dockerfile

FROM juliovg/oracle-oci-19
ENV HOME_DIR=/ 
    CODE_DIR=/root/sample/code 
    BUCKET_NAME=Code 
    LC_ALL=en_US.utf-8 
    LANG=en_US.utf-8 
    KEY_NAME="key.tar.gz" 
    KEY_URL="https://objectstorage/key.tar.gz" 
    PYTHON_ENV="https://objectstorage/test_1.py" 
    SCRIPT_SH="https://objectstorage/script.sh"
WORKDIR $HOME_DIR
RUN rm -rf $HOME_DIR/.oci
RUN wget $KEY_URL
RUN tar -xvf $KEY_NAME && rm -rf $KEY_NAME
RUN mkdir -p $CODE_DIR

WORKDIR $CODE_DIR
RUN wget $PYTHON_ENV
RUN wget $SCRIPT_SH

#RUN python3 /root/sample/code/test_1.py
#CMD ["python3 test_1.py"]
CMD [ "python3", "./test_1.py" ]
#ENTRYPOINT [ "python3", "test_1.py" ]
#RUN chmod +x script.sh
#CMD ["sh", "./script.sh"]

this is my python file

import oci
import sys
import os
import time
from base64 import b64encode, b64decode

config = oci.config.from_file()

compartment_code = config["tenancy"]
user_code = config["user"]
fingerprint_code = config["fingerprint"]



def write_env(environment_name):

    with open(os.path.expanduser("~/.bashrc"), "a") as outfile:

        if environment_name is "COMP_ID":
            outfile.write("export COMP_ID={} n".format(compartment_code)),
        elif environment_name is "USER_ID":
            outfile.write("export USER_ID={} n".format(user_code)),
        elif environment_name is "FINGER_CODE":
            outfile.write("export FINGER_CODE={} n".format(fingerprint_code))
        else:
            print("Variable unknow")
    outfile.closed


def set_environment():
    MANDATORY_ENV_VARS = ["COMP_ID", "USER_ID", "FINGER_CODE"]

    for var in MANDATORY_ENV_VARS:
        if var not in os.environ:
            print("Set environment variable {}.".format(var))
            write_env(var)
        else:
            print("estan")

    refresh_env = "exec -l $SHELL"
    os.system(refresh_env)


set_environment()

And my script.sh is:

#!/bin/bash -x

python3 /root/sample/code/test_1.py

all the construction is ok, i don’t see error

enter image description here

But when i enter to my image , the environment are not setted, the .bashrc file doesn’t contain the new 3 export

Can somebody help me ?

Beste regards

Source: StackOverflow