Skip to content

Commit

Permalink
Updating Dockerfile (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinp0 authored Feb 2, 2024
2 parents 061cdc8 + e981041 commit 0262509
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cont_int.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 29 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions devtools/install_autotst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions dockerfiles/alias_print.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
62 changes: 62 additions & 0 deletions dockerfiles/entrywrapper.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0262509

Please sign in to comment.