From cd3d5e6567c04f170b2c4af4a8819e96c505b5b4 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 30 Jan 2024 17:00:11 +0200 Subject: [PATCH 1/3] Created bash scripts Created a new folder called dockerfiles where it will contain relevant files for Dockerfile alias_print will print the current aliases in the Docker Image when run in interactive mode entrywrapper is a bash script that checks if the user runs in interactive or non-interactive mode. if interactive, it will run alias_print and then exec bash if non interactive, it will check if the user is running rmg or arc and use the inputf.py file the user provided in the terminal command --- dockerfiles/alias_print.sh | 34 ++++++++++++++++++++ dockerfiles/entrywrapper.sh | 62 +++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100755 dockerfiles/alias_print.sh create mode 100644 dockerfiles/entrywrapper.sh diff --git a/dockerfiles/alias_print.sh b/dockerfiles/alias_print.sh new file mode 100755 index 0000000000..cb51484cea --- /dev/null +++ b/dockerfiles/alias_print.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Source .bashrc to load aliases +if [ -f ~/.bashrc ]; then + source ~/.bashrc +fi + +# Print the aliases +echo "Alias List with Descriptions:" +echo "" +echo "1. rmge ='micromamba activate rmg_env'" +echo " - Activates the 'rmg_env' environment using Conda." +echo "" +echo "2. arce ='micromamba activate arc_env'" +echo " - Activates the 'arc_env' environment using Conda." +echo "" +echo "3. rmg ='python-jl /home/rmguser/Code/RMG-Py/rmg.py input.py'" +echo " - Runs the RMG program with 'input.py' using Python in the Julia environment." +echo "" +echo "4. deact ='micromamba deactivate'" +echo " - Deactivates the current Micromamba environment." +echo "" +echo "5. rmgcode='cd /home/rmguser/Code/RMG-Py/'" +echo " - Changes the current directory to the RMG-Py code directory." +echo "" +echo "6. rmgdb ='cd /home/rmguser/Code/RMG-database/" +echo " - Changes the current directory to the RMG database directory." +echo "" +echo "7. arcode ='cd /home/rmguser/Code/ARC'" +echo " - Changes the current directory to the ARC code directory." +echo "" + +# Execute the command specified as CMD in Dockerfile, or the command passed to docker run +exec "$@" diff --git a/dockerfiles/entrywrapper.sh b/dockerfiles/entrywrapper.sh new file mode 100644 index 0000000000..7ba2e0313b --- /dev/null +++ b/dockerfiles/entrywrapper.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Function to initialize Micromamba +initialize_micromamba() { + eval "$(micromamba shell hook --shell bash)" +} + + +# Function to check and adjust permissions for mounted directories +check_and_adjust_permissions() { + # Loop through all mounted directories + for dir in /home/rmguser/*; do + # Check if it's a directory + if [ -d "$dir" ]; then + # Adjust permissions for the directory + chown -R rmguser:rmguser "$dir" + fi + done +} + +# Function to run for interactive mode +run_interactive() { + check_and_adjust_permissions + echo "Container started in interactive mode" + + /home/rmguser/alias_print.sh + + /bin/bash +} + +# Function to run for non-interactive mode +run_non_interactive() { + check_and_adjust_permissions + echo "Container started in non-interactive mode" + initialize_micromamba + + case "$1" in + rmg) + # Activate rmg_env and run RMG with python-jl + echo "Running with RMG environment..." + micromamba activate rmg_env + python-jl /home/rmguser/Code/RMG-Py/rmg.py "$2" + ;; + arc) + # Activate arc_env and run ARC + echo "Running with ARC environment..." + micromamba activate arc_env + python /home/rmguser/Code/ARC/ARC.py "$2" + ;; + *) + echo "Invalid option. Please specify 'rmg' or 'arc' as the first argument." + exit 1 + ;; + esac +} + +# Check if the container is run in interactive mode +if [ -t 0 ] && [ -t 1 ]; then + run_interactive +else + run_non_interactive "$@" +fi From e39fc555e1696465c6b5a5d806deda5e333492b1 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 30 Jan 2024 17:01:02 +0200 Subject: [PATCH 2/3] Updated Dockerfile Now comes with nano User can utilise sudo Compiled RMS Now has an entrypoint script that is run --- Dockerfile | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index a2cf98dd66..75ced8c167 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,7 @@ RUN apt-get update && apt-get install -y \ libgomp1\ libxrender1 \ sudo \ + nano \ && apt-get clean \ && apt-get autoclean \ && apt-get autoremove -y \ @@ -88,23 +89,27 @@ RUN make \ # Final command is to compile the RMS during Docker build - This will reduce the time it takes to run RMS for the first time RUN touch /opt/conda/envs/rmg_env/condarc-julia.yml RUN CONDA_JL_CONDA_EXE=/bin/micromamba julia -e 'ENV["CONDA_JL_CONDA_EXE"]="/opt/conda/envs/rmg_env/bin/conda";using Pkg;Pkg.add(PackageSpec(name="PyCall", rev="master")); Pkg.build("PyCall"); Pkg.add(PackageSpec(name="ReactionMechanismSimulator", rev="main"))' \ - && python -c "import julia; julia.install(); import diffeqpy; diffeqpy.install()" \ - && python-jl -c "from pyrms import rms" + && python -c "import julia; julia.install(); import diffeqpy; diffeqpy.install()" + +RUN python-jl /home/rmguser/Code/RMG-Py/rmg.py /home/rmguser/Code/RMG-Py/examples/rmg/minimal/input.py \ + # delete the results, preserve input.py×– + && mv /home/rmguser/Code/RMG-Py/examples/rmg/minimal/input.py /home/rmguser/Code/RMG-Py/examples/input.py \ + && rm -rf /home/rmguser/Code/RMG-Py/examples/rmg/minimal/* \ + && mv /home/rmguser/Code/RMG-Py/examples/input.py /home/rmguser/Code/RMG-Py/examples/rmg/minimal/input.py # Add alias to bashrc - rmge to activate the environment # These commands are not necessary for the Docker image to run, but they are useful for the user RUN echo "alias rmge='micromamba activate rmg_env'" >> ~/.bashrc \ - && echo "alias rmg='python-jl /home/rmguser/Code/RMG/rmg.py input.py'" >> ~/.bashrc \ + && echo "alias arce='micromamba activate arc_env'" >> ~/.bashrc \ + && echo "alias rmg='python-jl /home/rmguser/Code/RMG-Py/rmg.py input.py'" >> ~/.bashrc \ && echo "alias deact='micromamba deactivate'" >> ~/.bashrc \ && echo "export rmgpy_path='/home/rmguser/Code/RMG-Py/'" >> ~/.bashrc \ && echo "export rmgdb_path='/home/rmguser/Code/RMG-database/'" >> ~/.bashrc \ && echo "alias rmgcode='cd \$rmgpy_path'" >> ~/.bashrc \ && echo "alias rmgdb='cd \$rmgdb_path'" >> ~/.bashrc \ + && echo "alias arcode='cd /home/rmguser/Code/ARC'" >> ~/.bashrc \ && echo "alias conda='micromamba'" >> ~/.bashrc \ - && echo "alias mamba='micromamba'" >> ~/.bashrc - -# Set the entrypoint to bash -ENTRYPOINT ["/bin/bash", "--login"] + && echo "alias mamba='micromamba'" >> ~/.bashrc FROM rmg-stage AS arc-stage @@ -141,6 +146,23 @@ RUN micromamba create -y -f environment.yml && \ rm -rf /opt/conda/envs/arc_env/lib/python3.7/site-packages/uvloop/loop.c &&\ make clean +WORKDIR /home/rmguser/ + +RUN mkdir -p /home/rmguser/.arc && \ + cp /home/rmguser/Code/ARC/arc/settings/settings.py /home/rmguser/.arc/settings.py && \ + cp /home/rmguser/Code/ARC/arc/settings/submit.py /home/rmguser/.arc/submit.py + +# Copy alias_print.sh and entrywrapper.sh to the container +COPY --chown=rmguser:rmguser ./dockerfiles/alias_print.sh /home/rmguser/alias_print.sh +COPY --chown=rmguser:rmguser ./dockerfiles/entrywrapper.sh /home/rmguser/entrywrapper.sh + +# Make the scripts executable +RUN chmod +x /home/rmguser/alias_print.sh \ + && chmod +x /home/rmguser/entrywrapper.sh + +# Set the wrapper script as the entrypoint +ENTRYPOINT ["/home/rmguser/entrywrapper.sh"] + # Activate the ARC environment ARG MAMBA_DOCKERFILE_ACTIVATE=1 ENV ENV_NAME=arc_env From e9810412ab6936a550f24c39d9d6220ab155086d Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 31 Jan 2024 20:43:51 +0200 Subject: [PATCH 3/3] Updated AutoTST Install --- .github/workflows/cont_int.yml | 3 ++- devtools/install_autotst.sh | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cont_int.yml b/.github/workflows/cont_int.yml index d34a759a45..b2bf8fc22a 100644 --- a/.github/workflows/cont_int.yml +++ b/.github/workflows/cont_int.yml @@ -178,7 +178,8 @@ jobs: echo 'export PYTHONPATH=$PYTHONPATH:'"$(pwd)" >> ~/.bashrc echo 'export PATH=$PATH:'"$(pwd)" >> ~/.bashrc mamba env create -f environment.yml - mamba install -n tst_env -c anaconda yaml -y + # install pyaml + mamba install -n tst_env -c conda-forge -y pyyaml cd .. - name: Install TS-GCN diff --git a/devtools/install_autotst.sh b/devtools/install_autotst.sh index 6e5302202a..1fb578efd1 100644 --- a/devtools/install_autotst.sh +++ b/devtools/install_autotst.sh @@ -18,16 +18,16 @@ else fi # Set up Conda/Micromamba environment -if [ "$COMMAND_PKG" == "micromamba" ]; then +if [ "$COMMAND_PKG" = "micromamba" ]; then eval "$(micromamba shell hook --shell=bash)" micromamba activate base BASE=$MAMBA_ROOT_PREFIX # shellcheck source=/dev/null - source "$BASE/etc/profile.d/micromamba.sh" + . "$BASE/etc/profile.d/micromamba.sh" else BASE=$(conda info --base) # shellcheck source=/dev/null - source "$BASE/etc/profile.d/conda.sh" + . "$BASE/etc/profile.d/conda.sh" fi # temporarily change directory to install software, and move one directory up in the tree @@ -62,7 +62,7 @@ else conda activate tst_env fi -$COMMAND_PKG install -c anaconda yaml -y +$COMMAND_PKG install -c conda-forge pyyaml # Restore the original directory cd ../ARC || exit