Skip to content

Commit 6994621

Browse files
authored
Add GitHub Action to build and test FANS (#19)
* rework github action for build and test and delete old one * adapt workflow to be compatible with local execution using nektos/act * switch back to explicit docker create/exec commands instead of 'container' option The container option doesn't support QEMU emulation and thus selecting a architecture different from the runners/host's one crashed the container with a 'exec format error'. Unfortunately this breaks running the workflows locally using nektos/act. I still have to figure out why exactly. * fix whitespaces and newline at end of file * replace hardcoded paths by variable ones in upload-artifact steps * Clean up docker create command * Consistently use bash -c in docker exec commands, and use single quotes instead of double quotes to prevent host side shell expansion * Execute tests as non root since MPI requires this. * Add non-root user already in first stage, to make it available in the fans-ci image as well * remove linux/arm64 from build and test workflow. Drop QEMU and make use of container: parameter
1 parent c4c41bf commit 6994621

File tree

4 files changed

+87
-116
lines changed

4 files changed

+87
-116
lines changed

.github/workflows/build.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/build_and_package.yaml

Lines changed: 0 additions & 59 deletions
This file was deleted.

.github/workflows/build_and_test.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build and Test
2+
# Builds FANS inside various docker containers and runs the tests.
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
pull_request:
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{github.event_name == 'pull_request'}}
15+
16+
jobs:
17+
build:
18+
name: ${{ format('Ubuntu {0}', matrix.UBUNTU_VERSION) }}
19+
runs-on: ubuntu-latest
20+
container: unistuttgartdae/fans-ci:${{ matrix.UBUNTU_VERSION }}
21+
defaults:
22+
run:
23+
shell: "bash --login -eo pipefail {0}"
24+
env:
25+
FANS_BUILD_DIR: build
26+
FANS_MPI_USER: fans
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
UBUNTU_VERSION: [noble, jammy, focal]
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Generate build directory
36+
run: mkdir -p ${{ env.FANS_BUILD_DIR }}
37+
38+
- name: Configure
39+
working-directory: ${{ env.FANS_BUILD_DIR }}
40+
run: |
41+
cmake --version
42+
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
43+
44+
- uses: actions/upload-artifact@v4
45+
if: failure()
46+
with:
47+
name: ${{ format('Ubuntu {0}', matrix.UBUNTU_VERSION) }} CMakeCache
48+
path: ${{ env.FANS_BUILD_DIR }}/CMakeCache.txt
49+
- uses: actions/upload-artifact@v4
50+
if: failure()
51+
with:
52+
name: ${{ format('Ubuntu {0}', matrix.UBUNTU_VERSION) }} CMakeLogs
53+
path: '${{ env.FANS_BUILD_DIR }}/CMakeFiles/*.log'
54+
- uses: actions/upload-artifact@v4
55+
if: failure()
56+
with:
57+
name: ${{ format('Ubuntu {0}', matrix.UBUNTU_VERSION) }} CompileCommands
58+
path: ${{ env.FANS_BUILD_DIR }}/compile_commands.json
59+
60+
- name: Compile
61+
working-directory: ${{ env.FANS_BUILD_DIR }}
62+
run:
63+
cmake --build . -j $(nproc) || cmake --build . -j1
64+
65+
- name: Adjust user rights
66+
run: chown -R ${{ env.FANS_MPI_USER }} ${{ env.FANS_BUILD_DIR }}
67+
68+
- name: Tests
69+
working-directory: ${{ env.FANS_BUILD_DIR }}
70+
run: su -c "ctest" ${{ env.FANS_MPI_USER }}
71+
72+
- uses: actions/upload-artifact@v4
73+
if: failure()
74+
with:
75+
name: ${{ format('Ubuntu {0}', matrix.UBUNTU_VERSION) }} CTest logs
76+
path: ${{ env.FANS_BUILD_DIR }}/Testing/Temporary/LastTest.log

docker/Dockerfile

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# to take effect)
33
ARG DEBIAN_FRONTEND=noninteractive
44
ARG UBUNTU_VERSION=noble
5+
ARG USER=fans
56

67
################################################################################
78

89
FROM ubuntu:${UBUNTU_VERSION} AS fans_base
910
ARG DEBIAN_FRONTEND
11+
ARG USER
1012

1113
# Context: https://askubuntu.com/questions/1513927/ubuntu-24-04-docker-images-now-includes-user-ubuntu-with-uid-gid-1000
1214
RUN bash -c 'if id "ubuntu" &>/dev/null; then \
@@ -16,6 +18,9 @@ RUN bash -c 'if id "ubuntu" &>/dev/null; then \
1618
echo "Deleted user ubuntu."; \
1719
fi'
1820

21+
# Create a non-root user
22+
RUN useradd -m -s /bin/bash ${USER}
23+
1924
################################################################################
2025

2126
FROM fans_base AS fans_ci
@@ -44,6 +49,8 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
4449

4550
FROM fans_ci AS fans_dev
4651
ARG DEBIAN_FRONTEND
52+
ARG USER
53+
ARG FANS_venv=FANS_venv
4754

4855
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
4956
# Packages required for setting up the non-root user
@@ -63,32 +70,20 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
6370
&& apt-get autoremove --purge -y \
6471
&& rm -rf /var/lib/apt/lists/*
6572

66-
# Create a non-root user
67-
ENV USER=develop
68-
ENV UID=1000
69-
ENV GID=100
70-
ENV HOME=/home/${USER}
71-
RUN adduser --disabled-password \
72-
--gecos "Non-root user" \
73-
--uid ${UID} \
74-
--gid ${GID} \
75-
--home ${HOME} \
76-
${USER} \
77-
#
78-
&& echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER} \
79-
&& chmod 0440 /etc/sudoers.d/${USER}
80-
8173
# Create a python venv for test/h52xdmf.py script
8274
USER ${USER}
8375

84-
ARG FANS_venv=FANS_venv
8576
RUN python -m venv /home/${USER}/venvs/${FANS_venv} && \
8677
echo "\nsource /home/${USER}/venvs/${FANS_venv}/bin/activate\n" >> /home/${USER}/.bashrc && \
8778
. /home/${USER}/venvs/${FANS_venv}/bin/activate && \
8879
python -m pip install --no-cache-dir h5py lxml
8980

9081
USER root
9182

83+
# Add fans user to sudoers
84+
RUN echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER} \
85+
&& chmod 440 /etc/sudoers.d/${USER}
86+
9287
# Entrypoint script changes UID and GID to match given host UID and GID
9388
COPY --chmod=755 docker/Dockerfile_user_env_entrypoint.sh /entrypoint.sh
9489
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)