Skip to content

Commit

Permalink
Merge pull request #24 from FoamScience/ci
Browse files Browse the repository at this point in the history
[ci] build matrix on ubuntu, openfoam, database, and smartsim versions
  • Loading branch information
AndreWeiner authored May 24, 2024
2 parents 5d39ca7 + 152d379 commit 760edc4
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 47 deletions.
32 changes: 21 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
name: smartredis
name: tests_ubuntu
defaults:
run:
shell: bash -o pipefail -i {0}
on:
push:
branches:
- main
- ci
- 'bugfix*'
- 'releases/**'
pull_request:
types: [opened, reopened]
types: [opened, reopened, synchronize]
workflow_dispatch:
inputs:
debug_enabled:
Expand All @@ -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
Expand All @@ -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
Expand Down
36 changes: 0 additions & 36 deletions .github/workflows/todos.yaml

This file was deleted.

39 changes: 39 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"
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"]
44 changes: 44 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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/<github_user>/openfoam-smartsim:of-2312-smartsim-0.7.0-redis-ubuntu-22.04 .
```
80 changes: 80 additions & 0 deletions docker/build.yml
Original file line number Diff line number Diff line change
@@ -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')"

0 comments on commit 760edc4

Please sign in to comment.