Skip to content

Commit 7e414c9

Browse files
committed
ci: Add composite actions and test in core-mpi
1 parent e147aaa commit 7e414c9

6 files changed

Lines changed: 228 additions & 85 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Docker build action
2+
description: Composite action for building Devito Docker containers
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
file:
8+
description: "Dockerfile containing build instructions"
9+
required: true
10+
default: Dockerfile
11+
tag:
12+
description: "Tag to add to the built image"
13+
required: true
14+
base:
15+
description: "Base docker image to build on top of"
16+
required: true
17+
# Update default if docker/Dockerfile.devito ever changes default
18+
default: "devitocodes/bases:cpu-gcc"
19+
20+
outputs:
21+
unique:
22+
description: "Unique identifier for the CI run"
23+
value: ${{ steps.uniquetag.outputs.unique }}
24+
25+
runs:
26+
using: "composite"
27+
steps:
28+
- id: uniquetag
29+
name: "Generate unique CI tag"
30+
shell: bash
31+
run: |
32+
UNIQUE=$(echo "${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}" | cksum | cut -f 1 -d " ")
33+
echo "Unique ID: ${UNIQUE}"
34+
echo "unique=${UNIQUE}" >> "$GITHUB_OUTPUT"
35+
36+
- id: dockerbuild
37+
name: "Build docker container"
38+
shell: bash
39+
run: |
40+
docker build \
41+
--pull \
42+
--file ${{ inputs.file }} \
43+
--tag ${{ inputs.tag }}_${{ steps.uniquetag.outputs.unique }} \
44+
--build-arg base=${{ inputs.base }} \
45+
.
46+
47+
# Do we need to be more specific?
48+
#~ docker buildx build . \
49+
#~ --builder "${RUNNER_NAME// /_}" \
50+
#~ --load \
51+
#~ --label ci-run="$GITHUB_RUN_ID" \
52+
#~ --rm --pull \
53+
#~ --file docker/Dockerfile.devito \
54+
#~ --tag "${DOCKER_IMAGE}" \
55+
#~ --build-arg base="${{ matrix.base }}"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Docker cleanup action
2+
description: Composite action for removing Docker images
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
uid:
8+
description: "Unique identifier output from docker-build action"
9+
required: true
10+
tag:
11+
description: "Tag of the built image to use"
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- id: dockerclean
18+
name: "Cleanup docker image"
19+
shell: bash
20+
run: |
21+
docker image rm -f "${{ inputs.tag }}_${{ inputs.uid }}"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Docker run action
2+
description: Composite action for running commands in Docker containers
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
uid:
8+
description: "Unique identifier output from docker-build action"
9+
required: true
10+
args:
11+
description: "Arguments to pass to `docker run`"
12+
required: true
13+
default: ""
14+
env:
15+
description: "Environment variables to set inside the docker container, one environment variable per line"
16+
required: true
17+
default: Dockerfile
18+
tag:
19+
description: "Tag of the built image to use"
20+
required: true
21+
command:
22+
description: "Command to execute inside of the docker container"
23+
required: true
24+
25+
runs:
26+
using: "composite"
27+
steps:
28+
- id: processenv
29+
name: Process environment variable list
30+
shell: bash
31+
env:
32+
ENV_INPUT: ${{ inputs.env }}
33+
run: |
34+
ENV_STRING=""
35+
# Read line by line with here string, safely handling spaces within the values
36+
while IFS= read -r LINE; do
37+
if [[ -n "$LINE" ]]; then
38+
ENV_STRING="$ENV_STRING --env $LINE"
39+
fi
40+
done <<< "$ENV_INPUT"
41+
# Remove the leading space from the first concatenation
42+
ENV_STRING="${ENV_STRING# }"
43+
echo "env=$ENV_STRING" >> "$GITHUB_OUTPUT"
44+
45+
- id: dockerrun
46+
name: "Run command ${{ inputs.command }} in ${{ inputs.tag }} docker container"
47+
shell: bash
48+
run: |
49+
docker run \
50+
--init -t --rm \
51+
${{ inputs.args }} \
52+
--name "ci-${{ inputs.name }}-${{ inputs.uid }}" \
53+
--env-file=docker/coverage.env \
54+
${{ steps.processenv.outputs.env }} \
55+
"${{ inputs.tag }}_${{ inputs.uid }}" \
56+
${{ inputs.command }}

.github/workflows/pytest-core-mpi.yaml

Lines changed: 72 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212
# but only for the main branch
1313
push:
1414
branches:
15-
- main
15+
- main
1616
pull_request:
1717
branches:
18-
- main
18+
- main
1919

2020
jobs:
2121
test-mpi-basic:
@@ -63,86 +63,73 @@ jobs:
6363
name: pytest-mpi
6464

6565
test-mpi-docker:
66-
name: pytest-mpi
67-
runs-on: ${{ matrix.os }}
68-
outputs:
69-
unique : ${{ steps.uniquetag.outputs.unique }}
70-
strategy:
71-
matrix:
72-
name: [gcc, gcc-arm, icx]
73-
include:
74-
- name: gcc
75-
arch: gcc
76-
os: ubuntu-latest
77-
mpiflag: ""
78-
79-
- name: gcc-arm
80-
arch: gcc
81-
os: ubuntu-24.04-arm
82-
mpiflag: ""
83-
84-
- name: icx
85-
arch: icx
86-
os: ubuntu-latest
87-
# Need safe math for icx due to inaccuracy with mpi+sinc interpolation
88-
mpiflag: "-e DEVITO_SAFE_MATH=1"
89-
90-
steps:
91-
- name: Checkout devito
92-
uses: actions/checkout@v6
93-
94-
- name: Generate unique CI tag
95-
id: uniquetag
96-
run: |
97-
UNIQUE=$(echo "${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}" | cksum | cut -f 1 -d " ")
98-
echo "Unique ID: ${UNIQUE}"
99-
echo "unique=${UNIQUE}" >> "$GITHUB_OUTPUT"
100-
101-
- name: Build docker image
102-
env:
103-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
104-
run: |
105-
docker build \
106-
--file docker/Dockerfile.devito \
107-
--tag "devito_img${UNIQUE}" \
108-
--build-arg base=devitocodes/bases:cpu-${{ matrix.arch }} \
109-
.
110-
111-
- name: Test with pytest
112-
env:
113-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
114-
run: |
115-
docker run \
116-
--init -t --rm \
117-
--env CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} \
118-
--env OMP_NUM_THREADS=1 \
119-
--name testrun \
120-
"devito_img${UNIQUE}" \
121-
pytest tests/test_mpi.py
122-
123-
- name: Test examples with MPI
124-
env:
125-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
126-
run: |
127-
docker run \
128-
--init -t --rm \
129-
${{ matrix.mpiflag }} \
130-
--env DEVITO_MPI=1 \
131-
--env OMP_NUM_THREADS=1 \
132-
--name examplerun \
133-
"devito_img${UNIQUE}" \
134-
mpiexec -n 2 pytest examples/seismic/acoustic
135-
#
136-
docker run \
137-
--init -t --rm \
138-
--env DEVITO_MPI=1 \
139-
--env OMP_NUM_THREADS=1 \
140-
--name examplerun \
141-
"devito_img${UNIQUE}" \
142-
mpiexec -n 2 pytest examples/seismic/tti
143-
144-
- name: Cleanup
145-
env:
146-
UNIQUE: ${{ steps.uniquetag.outputs.unique }}
147-
run: |
148-
docker image rm -f "devito_img${UNIQUE}"
66+
name: pytest-mpi
67+
runs-on: ${{ matrix.os }}
68+
strategy:
69+
matrix:
70+
name: [
71+
pytest-mpi-docker-gcc,
72+
pytest-mpi-docker-gcc-arm,
73+
pytest-mpi-docker-icx
74+
]
75+
include:
76+
- name: pytest-mpi-docker-gcc
77+
arch: gcc
78+
os: ubuntu-latest
79+
80+
- name: pytest-mpi-docker-gcc-arm
81+
arch: gcc
82+
os: ubuntu-24.04-arm
83+
84+
- name: pytest-mpi-docker-icx
85+
arch: icx
86+
os: ubuntu-latest
87+
88+
steps:
89+
- name: Checkout devito
90+
uses: actions/checkout@v6
91+
92+
- id: build
93+
name: Build docker image
94+
uses: ./.github/actions/docker-build
95+
with:
96+
file: docker/Dockerfile.devito
97+
tag: ${{ matrix.name }}
98+
base: devitocodes/bases:cpu-${{ matrix.arch }}
99+
100+
- name: Test with pytest
101+
uses: ./.github/actions/docker-run
102+
with:
103+
uid: ${{ steps.build.outputs.unique }}
104+
tag: ${{ matrix.name }}
105+
env: |
106+
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}
107+
OMP_NUM_THREADS=1
108+
command: "pytest tests/test_mpi.py"
109+
110+
- name: Test acoustic example with MPI
111+
uses: ./.github/actions/docker-run
112+
with:
113+
uid: ${{ steps.build.outputs.unique }}
114+
tag: ${{ matrix.name }}
115+
env: |
116+
DEVITO_MPI=1
117+
OMP_NUM_THREADS=1
118+
command: "mpiexec -n 2 pytest examples/seismic/acoustic"
119+
120+
- name: Test tti example with MPI
121+
uses: ./.github/actions/docker-run
122+
with:
123+
uid: ${{ steps.build.outputs.unique }}
124+
tag: ${{ matrix.name }}
125+
env: |
126+
DEVITO_MPI=1
127+
OMP_NUM_THREADS=1
128+
command: "mpiexec -n 2 pytest examples/seismic/tti"
129+
130+
- name: Cleanup docker image
131+
if: always()
132+
uses: ./.github/actions/docker-clean
133+
with:
134+
uid: ${{ steps.build.outputs.unique }}
135+
tag: ${{ matrix.name }}

docker/Dockerfile.devito

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
##############################################################
44

55
# Base image with compilers
6+
# Update default in .github/actions/docker-build if this value ever changes
67
ARG base=devitocodes/bases:cpu-gcc
78

89
FROM $base AS builder

docker/coverage.env

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generic code coverage variables
2+
CODECOV_ENV
3+
CODECOV_TOKEN
4+
CODECOV_URL
5+
CODECOV_SLUG
6+
VCS_COMMIT_ID
7+
VCS_BRANCH_NAME
8+
VCS_PULL_REQUEST
9+
VCS_SLUG
10+
VCS_TAG
11+
CI_BUILD_URL
12+
CI_BUILD_ID
13+
CI_JOB_ID
14+
15+
# Github specific code coverage variables
16+
GITHUB_ACTIONS
17+
GITHUB_HEAD_REF
18+
GITHUB_REF
19+
GITHUB_REPOSITORY
20+
GITHUB_RUN_ID
21+
GITHUB_SERVER_URL
22+
GITHUB_SHA
23+
GITHUB_WORKFLOW

0 commit comments

Comments
 (0)