Skip to content

Commit 9171403

Browse files
committed
ci: Edit Dockerfile.petsc, add docker-petsc.yml and clean up pytest-petsc.yml
1 parent 501e1f9 commit 9171403

File tree

8 files changed

+90
-29
lines changed

8 files changed

+90
-29
lines changed

.github/workflows/docker-petsc.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Publish devito-petsc docker image
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- petsc # Push events on petsc branch
10+
11+
jobs:
12+
build-and-push:
13+
name: Build and push devito-petsc image
14+
runs-on: ubuntu-latest
15+
env:
16+
# Use buildkit
17+
DOCKER_BUILDKIT: "1"
18+
19+
steps:
20+
- name: Checkout devito
21+
uses: actions/checkout@v5
22+
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Log in to DockerHub
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ secrets.DOCKER_USERNAME }}
33+
password: ${{ secrets.DOCKER_PASSWORD }}
34+
35+
- name: Build & push petsc image
36+
uses: docker/build-push-action@v6
37+
with:
38+
context: .
39+
file: docker/Dockerfile.petsc
40+
push: true
41+
tags: |
42+
devitocodes/devito-petsc:latest
43+
build-args: base=devitocodes/devito:gcc-dev-amd64
44+
platforms: linux/amd64
45+
46+
- name: Remove dangling layers
47+
run: docker system prune -f

.github/workflows/pytest-petsc.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818

1919
jobs:
2020
pytest:
21-
name: ${{ matrix.name }}-${{ matrix.set }}
21+
name: ${{ matrix.name }}
2222
runs-on: "${{ matrix.os }}"
2323

2424
env:
@@ -30,17 +30,13 @@ jobs:
3030
# Prevent all build to stop if a single one fails
3131
fail-fast: false
3232

33+
# To be extended
3334
matrix:
34-
name: [
35-
pytest-docker-py39-gcc-noomp
36-
]
3735
include:
38-
- name: pytest-docker-py39-gcc-noomp
39-
python-version: '3.9'
36+
- name: pytest-petsc
4037
os: ubuntu-latest
4138
arch: "gcc"
4239
language: "C"
43-
sympy: "1.12"
4440

4541
steps:
4642
- name: Checkout devito
@@ -54,11 +50,11 @@ jobs:
5450

5551
- name: Build docker image
5652
run: |
57-
docker build -f docker/Dockerfile.devito --build-arg base=zoeleibowitz/petsc_image:latest --tag zoeleibowitz/petsc_devito_image:latest .
53+
docker build -f docker/Dockerfile.petsc --tag devito_petsc_image:test .
5854
5955
- name: Set run prefix
6056
run: |
61-
echo "RUN_CMD=docker run --rm -t -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} --name testrun zoeleibowitz/petsc_devito_image:latest" >> $GITHUB_ENV
57+
echo "RUN_CMD=docker run --rm -t -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} --name testrun devito_petsc_image:test" >> $GITHUB_ENV
6258
id: set-run
6359

6460
- name: Set tests

devito/petsc/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
import ctypes
33
from pathlib import Path
44

5-
from petsctools import get_petscvariables, MissingPetscException
5+
try:
6+
from petsctools import get_petscvariables, MissingPetscException
7+
petsc_variables = get_petscvariables()
8+
except ImportError:
9+
petsc_variables = {}
10+
except MissingPetscException:
11+
petsc_variables = {}
612

713
from devito.tools import memoized_func
814

@@ -46,12 +52,6 @@ def core_metadata():
4652
}
4753

4854

49-
try:
50-
petsc_variables = get_petscvariables()
51-
except MissingPetscException:
52-
petsc_variables = {}
53-
54-
5555
def get_petsc_type_mappings():
5656
try:
5757
petsc_precision = petsc_variables['PETSC_PRECISION']

devito/petsc/solver_parameters.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import itertools
22

3-
from petsctools import flatten_parameters
4-
3+
try:
4+
from petsctools import flatten_parameters
5+
except ImportError:
6+
# TODO: drop
7+
def flatten_parameters():
8+
raise ImportError("petsctools is not installed")
59

610
# NOTE: Will be extended, the default preconditioner is not going to be 'none'
711
base_solve_defaults = {

docker/Dockerfile.petsc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,40 @@
22
# Dockerfile.petsc: Installs PETSc
33
##############################################################
44

5-
# Base image with compilers
6-
# TODO: to be updated, but made some additions to Dockerfile.cpu so need to
7-
# use the one from my dockerhub
8-
ARG base=zoeleibowitz/bases:cpu-gcc
5+
ARG base=devitocodes/devito:gcc-dev-amd64
96

107
FROM $base
118

12-
RUN apt-get update && apt-get install -y \
13-
git gfortran pkgconf libopenblas-serial-dev && \
14-
python3 -m venv /venv && \
15-
/venv/bin/pip install --no-cache-dir --upgrade pip && \
16-
/venv/bin/pip install --no-cache-dir --no-binary numpy numpy && \
9+
USER root
10+
11+
RUN python3 -m venv /venv && \
1712
mkdir -p /opt/petsc && \
1813
cd /opt/petsc && \
19-
git clone -b v3.23.0 https://gitlab.com/petsc/petsc.git petsc && \
14+
git clone -b v3.24.0 https://gitlab.com/petsc/petsc.git petsc && \
2015
cd petsc && \
2116
./configure --with-fortran-bindings=0 --with-mpi-dir=/opt/openmpi \
2217
--with-openblas-include=$(pkg-config --variable=includedir openblas) \
2318
--with-openblas-lib=$(pkg-config --variable=libdir openblas)/libopenblas.so \
2419
PETSC_ARCH=devito_build && \
2520
make all
2621

22+
# Remove existing devito
23+
RUN rm -rf /app/devito/.git
24+
25+
# Copy Devito from petsc branch
26+
ADD . /app/devito
27+
28+
# Remove git files
29+
RUN rm -rf /app/devito/.git
30+
31+
# Mpi4py
32+
RUN eval "$MPI4PY_FLAGS /venv/bin/pip install --no-cache-dir --verbose -r /app/devito/requirements-mpi.txt"
33+
34+
# Install Devito with petsc requirements
35+
RUN /venv/bin/pip install --no-cache-dir -e /app/devito[extras,tests,petsc] && rm -rf ~/.cache/pip
36+
2737
ENV PETSC_DIR="/opt/petsc/petsc"
2838
ENV PETSC_ARCH="devito_build"
39+
40+
# Switch back to non-root user
41+
USER app

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ mpi = { file = ["requirements-mpi.txt"] }
6161
nvidia = { file = ["requirements-nvidia.txt"] }
6262
tests = { file = ["requirements-testing.txt"] }
6363
extras = { file = ["requirements-optional.txt"] }
64+
petsc = { file = ["requirements-petsc.txt"] }
6465

6566
[tool.setuptools.packages.find]
6667
where = ["."]

requirements-petsc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
petsctools<=2025.1

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ codepy>=2019.1,<2025
88
multidict<6.3
99
anytree>=2.4.3,<=2.13.0
1010
packaging<25.1
11-
petsctools<=2025.1

0 commit comments

Comments
 (0)