diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9b28b8e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/build +/build.log +/venv diff --git a/dev/container/.dummy b/dev/container/.dummy new file mode 100644 index 00000000..e69de29b diff --git a/dev/container/Dockerfile b/dev/container/Dockerfile new file mode 100644 index 00000000..ba90f986 --- /dev/null +++ b/dev/container/Dockerfile @@ -0,0 +1,53 @@ +# Dockerfile for building Cetmodules development image. + +# Podman instructions for building and uploading tagged images: +# $ DATE="$(date +"%Y-%m-%d")" +# $ podman build --tag cetmodules-dev:$DATE . +# $ podman login ghcr.io --username -p $(gh auth token) +# $ podman push cetmodules-dev:$DATE ghcr.io/fnalssi/cetmodules-dev:$DATE +# ... and optionally push with destination tag "latest" + +# Base image +FROM ubuntu:latest + +# Set non-interactive frontend to avoid prompts +ENV DEBIAN_FRONTEND=noninteractive + +# Install system dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + git \ + doxygen \ + graphviz \ + m4 \ + ninja-build \ + python3 \ + python3-pip \ + sudo && \ + rm -rf /var/lib/apt/lists/* + +# Install Python packages +RUN pip3 install --no-cache-dir --break-system-packages \ + cmake \ + sphinx \ + sphinxcontrib-moderncmakedomain \ + sphinx-design \ + sphinx-toolbox \ + sphinxcontrib-jquery + +# Install Catch2 +RUN git clone https://github.com/catchorg/Catch2.git /tmp/Catch2 && \ + cmake -S /tmp/Catch2 -B /tmp/Catch2/build -DBUILD_TESTING=OFF && \ + cmake --build /tmp/Catch2/build --target install && \ + rm -rf /tmp/Catch2 + +# Create source and build directories and make them world-writable +RUN mkdir /source /build && \ + chmod 777 /source /build + +# Set working directory +WORKDIR /build + +# Set default command +CMD ["/bin/bash"] diff --git a/dev/container/README.md b/dev/container/README.md new file mode 100644 index 00000000..09f244e7 --- /dev/null +++ b/dev/container/README.md @@ -0,0 +1,57 @@ +# Cetmodules Development Container + +This directory contains a `Dockerfile` to create a containerized development environment for `cetmodules`. + +## Building the Image + +To build the image, run the following command from the root of the repository: + +```bash +# For Docker or Podman +docker build -t cetmodules-dev dev/container +``` + +## Running the Container + +The command to run the container differs between Docker and Podman due to differences in how they handle user namespaces. + +First, create a local `build` directory if it does not already exist: + +```bash +mkdir -p build +``` + +### For Docker Users + +Docker users should map their host user ID directly to the container to ensure correct file ownership on mounted volumes. + +```bash +docker run -it --rm \ + --user "$(id -u):$(id -g)" \ + -v "$(pwd):/source" \ + -v "$(pwd)/build:/build" \ + cetmodules-dev +``` + +### For Podman Users (Rootless) + +Rootless Podman uses user namespaces to map your host user to the `root` user (UID 0) inside the container. To ensure you have permission to write to mounted volumes, you should run as `root` inside the container. Any files created in the mounted volumes will be correctly owned by your user on the host. + +```bash +podman run -it --rm \ + -v "$(pwd):/source" \ + -v "$(pwd)/build:/build" \ + cetmodules-dev +``` +*(Note: Running as `root` is the intended usage for rootless Podman and is safe because you are in an unprivileged user namespace.)* + + +### Usage + +Once inside the container, you can perform an out-of-source build like this: + +```bash +cmake -S /source -B . -DBUILD_DOCS=ON +cmake --build . +ctest +``` diff --git a/dev/setup_cetmodules_dev.sh b/dev/setup_cetmodules_dev.sh new file mode 100644 index 00000000..f850a954 --- /dev/null +++ b/dev/setup_cetmodules_dev.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status. +set -e + +# --- OS Detection --- +if [ -f /etc/os-release ]; then + . /etc/os-release + if [[ "$ID" == "ubuntu" ]]; then + PACKAGE_MANAGER="apt-get" + BUILD_DEPS="build-essential" + elif [[ "$ID" == "almalinux" ]]; then + PACKAGE_MANAGER="dnf" + BUILD_DEPS="gcc-c++" + else + echo "Unsupported operating system: $ID" + exit 1 + fi +else + echo "/etc/os-release not found. Cannot determine operating system." + exit 1 +fi + +# --- System Dependency Installation --- +echo "Updating package lists..." +sudo $PACKAGE_MANAGER update -y + +echo "Installing system dependencies..." +sudo $PACKAGE_MANAGER install -y git doxygen graphviz python3-venv $BUILD_DEPS + +# --- Python Environment Setup --- +echo "Setting up Python virtual environment..." +python3 -m venv venv +source venv/bin/activate + +echo "Installing Python packages (CMake, Sphinx, etc.)..." +pip install cmake sphinx sphinxcontrib-moderncmakedomain sphinx-design sphinx-toolbox sphinxcontrib-jquery + +# --- Catch2 Installation --- +echo "Cloning and installing Catch2..." +git clone https://github.com/catchorg/Catch2.git +cd Catch2 +cmake -S . -B build -DBUILD_TESTING=OFF +sudo cmake --build build --target install +cd .. +rm -rf Catch2 + +# --- cetmodules Build and Test --- +echo "Cloning, building, and testing cetmodules..." +git clone https://github.com/FNALssi/cetmodules.git +cd cetmodules +cmake -S . -B build -DBUILD_DOCS=ON +cmake --build build +ctest --test-dir build + +# --- Documentation Build --- +echo "Building cetmodules documentation..." +cmake --build build --target doc-cetmodules-reference +cd .. + +# --- Completion --- +echo "" +echo "----------------------------------------------------" +echo "Development environment setup for cetmodules is complete!" +echo "To activate the Python virtual environment, run:" +echo "source venv/bin/activate" +echo "----------------------------------------------------"