diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9f05f9a..ab35682 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: smartredis +name: tests_ubuntu defaults: run: shell: bash -o pipefail -i {0} @@ -6,10 +6,11 @@ on: push: branches: - main + - ci - 'bugfix*' - 'releases/**' pull_request: - types: [opened, reopened] + types: [opened, reopened, synchronize] workflow_dispatch: inputs: debug_enabled: @@ -20,23 +21,32 @@ on: jobs: build: + strategy: + fail-fast: false + matrix: + openfoam_version: ['2312', '2212'] + smartsim_version: ['0.7.0', '0.6.2'] + database_backend: ['redis'] + ubuntu_version: ['22.04', '20.04'] ## SmartSim not available yet for Python 3.12 on Ubuntu 24 + exclude: + - ubuntu_version: '20.04' ## SmartSim 0.7.0 not released on ubuntu 20.04 + smartsim_version: '0.7.0' runs-on: ubuntu-22.04 container: - image: ghcr.io/foamscience/openfoam-smartsim:cpu-2312 - options: --user openfoam + image: ghcr.io/ofdatacommittee/openfoam-smartsim:of-${{ matrix.openfoam_version }}-smart-${{ matrix.smartsim_version }}-${{ matrix.database_backend }}-ubuntu-${{ matrix.ubuntu_version }} env: CATCH_TIMEOUT: 20 FOAM_FOAMUT: "/tmp/foamUT" - SSDB: "redis:6379" + SSDB: "smartdb:6379" services: - redis: - image: redislabs/redisai + smartdb: + image: ${{ matrix.database_backend == 'redis' && 'redislabs/redisai' || 'eqalpha/keydb' }} steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup tmate session uses: mxschmitt/action-tmate@v3 @@ -46,15 +56,15 @@ jobs: - name: Compile run: | - source /usr/lib/openfoam/openfoam2312/etc/bashrc + source /usr/lib/openfoam/openfoam${{ matrix.openfoam_version }}/etc/bashrc mkdir -p $FOAM_USER_LIBBIN ./Allwmake - name: Compile Tests and Run run: | - source /usr/lib/openfoam/openfoam2312/etc/bashrc + source /usr/lib/openfoam/openfoam${{ matrix.openfoam_version }}/etc/bashrc ./Allwmake - export SSDB="redis:6379" + export SSDB="smartdb:6379" git clone https://github.com/FoamScience/foamUT $FOAM_FOAMUT sed -i 's/mpirun/mpirun --oversubscribe/g' $FOAM_FOAMUT/Alltest ln -s "$PWD"/tests "$FOAM_FOAMUT"/tests/smartSimFOTests diff --git a/.github/workflows/todos.yaml b/.github/workflows/todos.yaml deleted file mode 100644 index e722eb9..0000000 --- a/.github/workflows/todos.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Create issues from TODOs - -on: - workflow_dispatch: - inputs: - importAll: - default: 'false' - required: false - type: boolean - description: Enable, if you want to import all TODOs. Runs on checked out branch! Only use if you're sure what you are doing. - push: - branches: - - main - -permissions: - issues: write - repository-projects: read - contents: read - -jobs: - todos: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Run Issue Bot - uses: derjuulsn/todo-issue@main - with: - excludePattern: '^(.github/)' - keywords: - "@todo" - bodyKeywords: - "@body" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..45a3c71 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,39 @@ +ARG UBUNTU_VERSION # Eg. 22.04 +FROM ubuntu:${UBUNTU_VERSION} +# To build this image from this folder with OpenFOAM v2206: +# docker build --build-arg OPENFOAM_VERSION=2206 --build-tag SMARTSIM_VERSION=0.7.0 -t openfoam-smartsim:latest . + +ARG SMARTSIM_VERSION # Eg. 0.6.2 +ARG OPENFOAM_VERSION # Eg. 2206 +ARG DATABASE_BACKEND=redis # redis or keydb +LABEL maintainer="Mohammed Elwardi Fadeli " +LABEL source="https://github.com/OFDataCommittee/openfoam-smartsim" + +# Install and setup +ENV DEBIAN_FRONTEND=noninteractive +ENV SHELL=/usr/bin/bash +RUN apt update -y && \ + apt install -y --no-install-recommends git-lfs libpython3-dev pip cmake \ + sudo apt-utils vim curl wget software-properties-common \ + git-core cmake openssh-server gcc g++ \ + binutils libopenmpi-dev openmpi-bin openmpi-common openmpi-doc + +# Set up OpenFOAM repositories +RUN sh -c "curl https://dl.openfoam.com/add-debian-repo.sh | bash" +RUN apt update -y && \ + apt install -y --no-install-recommends openfoam${OPENFOAM_VERSION}-default +RUN apt clean && apt purge && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# Set up smartsim +RUN pip install smartsim==${SMARTSIM_VERSION} && \ + if [ "${DATABASE_BACKEND}" = "keydb" ]; then smart build --device cpu --no_tf --no_pt; else smart build --device cpu --no_tf --no_pt --keydb; fi +ENV USER openfoam +ENV HOME=/home/${USER} +RUN adduser --disabled-password --gecos "" ${USER} -u 1001 && \ + echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +USER openfoam +RUN echo "source /usr/lib/openfoam/openfoam${OPENFOAM_VERSION}/etc/bashrc" >> ${HOME}/.bashrc +RUN . "/usr/lib/openfoam/openfoam${OPENFOAM_VERSION}/etc/bashrc" && mkdir -p $FOAM_USER_LIBBIN && mkdir -p $FOAM_USER_APPBIN + + +#COPY bin/uid_entrypoint /usr/local/bin/uid_entrypoint +#ENTRYPOINT ["uid_entrypoint"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..6594d71 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,44 @@ +# Continuous Integration + +## Overview + +We continuously test against recent versions of the following software pieces: +- Ubuntu +- OpenFOAM +- SmartSim +- Database backend (redis, or keydb) + +In particular, by testing on multiple versions of Ubuntu distribution, we make sure +things work on the default toolchain versions (Compilers, system OpenMPI, ..., etc) + +We use [Github Container Registry](https://ghcr.io/) to store the Docker images necessary for +CI workflows. + +## Instructions for automated image builds + +> [!NOTE] +> You will want to install ansible (locally) to build the images easily: `pip install ansible`. +> Each image is a little than 2GB so make sure you have enough disk space. + +1. In [docker/build.yml](docker/build.yml) file, add the new version in the relevant fact task. + - For example, to add a new version of OpenFOAM, add the version to `openfoam_versions` + - Then run `ansible-playbook build.yml --extra-vars "username=github_user token=$GITHUB_TOKEN` + to build the corresponding image and push it. + - When building the images locally, you can speed the process by removing other software versions + and keeping only the new one +2. In [.github/workflows/ci.yaml](.github/workflows/ci.yaml) file, add the new version in the relevant + `strategy` section. + - For example, to add a new version of OpenFOAM, add the version to `jobs.build.strategy.matrix.openfoam_version` + - Then commit the changes to the repository. + +## Instructions for manual image builds + +```sh +cd docker +docker build \ + --build-arg OPENFOAM_VERSION=2312 \ + --build-arg UBUNTU_VERSION=22.04 \ + --build-arg DATABASE_BACKEND=redis \ + --build-arg SMARTSIM_VERSION=0.7.0 \ + -t ghcr.io//openfoam-smartsim:of-2312-smartsim-0.7.0-redis-ubuntu-22.04 . +``` diff --git a/docker/build.yml b/docker/build.yml new file mode 100644 index 0000000..546cc71 --- /dev/null +++ b/docker/build.yml @@ -0,0 +1,80 @@ +# ansible-playbook build.yml --extra-vars "username=user token=token" +--- +- name: Build openfoam-smartsim CI infrastructure + hosts: localhost + gather_facts: false + vars: + ansible_python_interpreter: /usr/bin/python3 + + tasks: + - name: Install docker python support for ansible + pip: + name: docker + state: present + + - name: Define list of OpenFOAM versions + set_fact: + openfoam_versions: + - "2312" + - "2212" + + - name: Define list of SmartSim versions + set_fact: + smartsim_versions: + - "0.7.0" + - "0.6.2" + + - name: Define list of DB backends + set_fact: + database_backends: + - "redis" + + - name: Define list of Ubuntu versions + set_fact: + ubuntu_versions: + #- "24.04" ## SmartSim not available for Python 3.12 + - "22.04" + - "20.04" + + - name: Login to GitHub Container Registry + docker_login: + username: "{{ username }}" + password: "{{ token }}" + registry_url: "https://ghcr.io" + + - name: Build Docker images + docker_image: + name: "ghcr.io/{{ username }}/openfoam-smartsim:of-{{ item.0 }}-smart-{{ item.1 }}-{{ item.2 }}-ubuntu-{{ item.3 }}" + source: "build" + build: + path: "." + dockerfile: "Dockerfile" + pull: yes + args: + OPENFOAM_VERSION: "{{ item.0 }}" + SMARTSIM_VERSION: "{{ item.1 }}" + DATABASE_BACKEND: "{{ item.2 }}" + UBUNTU_VERSION: "{{ item.3 }}" + loop: "{{ openfoam_versions|product(smartsim_versions, database_backends, ubuntu_versions)|list }}" + when: "not (item.1 == '0.7.0' and item.3 == '20.04')" + async: 1200 + poll: 0 + register: async_result + + - name: Wait for all build tasks to complete + async_status: + jid: "{{ item.ansible_job_id }}" + loop: "{{ async_result.results }}" + when: item.changed + register: async_status_result + until: async_status_result.finished + retries: 20 + delay: 60 + + - name: Push Docker images to GitHub Container Registry + docker_image: + name: "ghcr.io/ofdatacommittee/openfoam-smartsim:of-{{ item.0 }}-smart-{{ item.1 }}-{{ item.2 }}-ubuntu-{{ item.3 }}" + source: local + push: yes + loop: "{{ openfoam_versions|product(smartsim_versions, database_backends, ubuntu_versions)|list }}" + when: "not (item.1 == '0.7.0' and item.3 == '20.04')"