diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 70d73a0ffc..71a6f296e8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -48,9 +48,12 @@ env: # if running on RMG-Py but requiring changes on an un-merged branch of RMG-database, replace # main with the name of the branch RMG_DATABASE_BRANCH: main + # RMS branch to use for ReactionMechanismSimulator installation + RMS_BRANCH: for_rmg # julia parallel pre-compilation leads to race conditions and hangs, so we limit it to run in serial JULIA_NUM_PRECOMPILE_TASKS: 1 + jobs: build-and-test: strategy: @@ -400,7 +403,10 @@ jobs: # taken from https://github.com/docker/build-push-action needs: [build-and-test, regression-test] runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' && github.repository == 'ReactionMechanismGenerator/RMG-Py' + # Run on push to main or on pull requests from official fork. + if: | + (github.ref == 'refs/heads/main' && github.repository == 'ReactionMechanismGenerator/RMG-Py') || + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'ReactionMechanismGenerator/RMG-Py') steps: - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -409,15 +415,20 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub + if: github.ref == 'refs/heads/main' && github.repository == 'ReactionMechanismGenerator/RMG-Py' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and Push + - name: Build (and Push if on main) uses: docker/build-push-action@v6 + env: + BUILDKIT_PROGRESS: plain with: - push: true + push: ${{ github.ref == 'refs/heads/main' && github.repository == 'ReactionMechanismGenerator/RMG-Py' }} tags: reactionmechanismgenerator/rmg:latest build-args: | - RMS_Branch=for_rmg + RMG_Py_Branch=${{ github.head_ref || github.ref_name }} + RMG_Database_Branch=${{ env.RMG_DATABASE_BRANCH }} + RMS_Branch=${{ env.RMS_BRANCH }} diff --git a/Dockerfile b/Dockerfile index 253304f5df..9f63298725 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN ln -snf /bin/bash /bin/sh # - git for downloading RMG respoitories # - wget for downloading conda install script # - libxrender1 required by RDKit +# - ca-certificates added for HTTPS downloads RUN apt-get update && \ apt-get install -y \ make \ @@ -18,24 +19,35 @@ RUN apt-get update && \ wget \ git \ g++ \ - libxrender1 && \ + libxrender1 \ + ca-certificates && \ apt-get autoremove -y && \ apt-get clean -y + +# Install Julia 1.10 using juliaup +RUN wget -qO- https://install.julialang.org | sh -s -- --yes --default-channel 1.10 && \ + /root/.juliaup/bin/juliaup add 1.10 && \ + /root/.juliaup/bin/juliaup default 1.10 && \ + /root/.juliaup/bin/juliaup list && \ + rm -rf /root/.juliaup/downloads /root/.juliaup/tmp +ENV PATH="/root/.juliaup/bin:$PATH" + # Install conda RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ bash Miniconda3-latest-Linux-x86_64.sh -b -p /miniconda && \ rm Miniconda3-latest-Linux-x86_64.sh -ENV PATH="$PATH:/miniconda/bin" +ENV PATH="/miniconda/bin:$PATH" # Set Bash as the default shell for following commands SHELL ["/bin/bash", "-c"] # Add build arguments for RMG-Py, RMG-database, and RMS branches. +# The defaults are set here, but they can be overridden at build time +# using the --build-arg option, or in the continous integration CI.yml file. ARG RMG_Py_Branch=main ARG RMG_Database_Branch=main -ARG RMS_Branch=main -ENV rmsbranch=${RMS_Branch} +ARG RMS_Branch=for_rmg # cd WORKDIR /rmg @@ -45,8 +57,11 @@ RUN git clone --single-branch --branch ${RMG_Py_Branch} --depth 1 https://github git clone --single-branch --branch ${RMG_Database_Branch} --depth 1 https://github.com/ReactionMechanismGenerator/RMG-database.git WORKDIR /rmg/RMG-Py + # build the conda environment RUN conda env create --file environment.yml +# Remove conda package cache to reduce image size +RUN rm -rf /miniconda/pkgs # This runs all subsequent commands inside the rmg_env conda environment # @@ -61,19 +76,25 @@ RUN conda clean --all --yes ENV RUNNER_CWD=/rmg ENV PATH="$RUNNER_CWD/RMG-Py:$PATH" -# 1. Build RMG -# 2. Install and link Julia dependencies for RMS +# Build RMG +RUN make + +# Install and link Julia dependencies for RMS # setting this env variable fixes an issue with Julia precompilation on Windows ENV JULIA_CPU_TARGET="x86-64,haswell,skylake,broadwell,znver1,znver2,znver3,cascadelake,icelake-client,cooperlake,generic" +ENV RMS_BRANCH=${RMS_Branch} +# Usually this is set automatically, but we're not actually running +# in an active conda environment when building the Docker so we need to set it manually +ENV PYTHON_JULIAPKG_PROJECT="/miniconda/envs/rmg_env/julia_env" RUN source install_rms.sh # RMG-Py should now be installed and ready - trigger precompilation and test run -RUN python rmg.py examples/rmg/minimal/input.py -# delete the results, preserve input.py -RUN mv examples/rmg/minimal/input.py . && \ - rm -rf examples/rmg/minimal/* && \ - mv input.py examples/rmg/minimal/ +RUN python rmg.py examples/rmg/rms_constant_V/input.py +# delete the results, restore input.py from git +RUN rm -rf examples/rmg/rms_constant_V/* && \ + git checkout -- examples/rmg/rms_constant_V/ # when running this image, open an interactive bash terminal inside the conda environment -RUN echo "source activate rmg_env" >~/.bashrc +RUN conda init +RUN echo "conda activate rmg_env" >> ~/.bashrc ENTRYPOINT ["/bin/bash", "--login"] diff --git a/install_rms.sh b/install_rms.sh index 2870e263ab..9996cc694e 100644 --- a/install_rms.sh +++ b/install_rms.sh @@ -41,18 +41,28 @@ echo "Julia 1.10 binary path: $julia_path" current_env=$(conda info --envs | grep '\*' | awk '{print $1}') echo "Current conda environment: $current_env" -# Set environment variables for the current environment +# Set environment variables for the current environment, for future uses # https://juliapy.github.io/PythonCall.jl/stable/pythoncall/#If-you-already-have-Python-and-required-Python-packages-installed conda env config vars set JULIA_CONDAPKG_BACKEND=Null conda env config vars set JULIA_PYTHONCALL_EXE=$CONDA_PREFIX/bin/python conda env config vars set PYTHON_JULIAPKG_EXE=$(which julia) - -# Reactivate the current environment to apply the new variables -conda deactivate -conda activate $current_env +conda env config vars set PYTHON_JULIAPKG_PROJECT=$CONDA_PREFIX/julia_env +# Also export for current shell/session (needed for Docker/non-interactive use) +export JULIA_CONDAPKG_BACKEND=Null +export JULIA_PYTHONCALL_EXE="$CONDA_PREFIX/bin/python" +export PYTHON_JULIAPKG_EXE="$(which julia)" +export PYTHON_JULIAPKG_PROJECT="$CONDA_PREFIX/julia_env" conda install -y conda-forge::pyjuliacall -julia -e 'using Pkg; Pkg.add(Pkg.PackageSpec(name="ReactionMechanismSimulator", url="https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl.git", rev="for_rmg")); using ReactionMechanismSimulator; Pkg.instantiate()' || echo "RMS install error - continuing anyway ¯\_(ツ)_/¯" +echo "Environment variables referencing JULIA:" +env | grep JULIA + +# Use RMS_BRANCH environment variable if set, otherwise default to for_rmg +RMS_BRANCH=${RMS_BRANCH:-for_rmg} +echo "Installing ReactionMechanismSimulator from branch: $RMS_BRANCH" + +julia -e "using Pkg; Pkg.add(Pkg.PackageSpec(name=\"ReactionMechanismSimulator\", url=\"https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl.git\", rev=\"$RMS_BRANCH\")); using ReactionMechanismSimulator; Pkg.instantiate()" || echo "RMS install error - continuing anyway ¯\_(ツ)_/¯" +echo "Checking if ReactionMechanismSimulator is installed in the current conda environment for Python usage..." python -c "from juliacall import Main; import sys; sys.exit(0 if Main.seval('Base.identify_package(\"ReactionMechanismSimulator\") !== nothing') and print('ReactionMechanismSimulator is installed in $current_env') is None else 1)"