diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ae773b2..6b2f670 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,16 +2,18 @@ name: Build on: - pull_request: +# pull_request: push: branches: [main, develop] - tags: ['*'] + tags: ['v*'] workflow_dispatch: env: REGISTRY: ghcr.io BASE_REPO: ubuntu BASE_TAG: "22.04" + ROOT_REPO: project8/luna_base_root + ROOT_TAG: "root_v6.28.06" jobs: @@ -84,6 +86,8 @@ jobs: build-args: | img_repo=${{ env.BASE_REPO }} img_tag=${{ env.BASE_TAG }} + root_repo=${{ env.REGISTRY }}/${{ env.ROOT_REPO }} + root_tag=${{ env.ROOT_TAG }} common_tag=${{ steps.tag_name.outputs.tag }} tags: ${{ steps.docker_meta.outputs.tags }} platforms: ${{ matrix.push && 'linux/amd64,linux/arm64' || 'linux/amd64' }} diff --git a/.github/workflows/build_root.yaml b/.github/workflows/build_root.yaml new file mode 100644 index 0000000..6753281 --- /dev/null +++ b/.github/workflows/build_root.yaml @@ -0,0 +1,86 @@ + +name: Build ROOT + +on: + pull_request: + push: + tags: ['root_v*'] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + BASE_REPO: ubuntu + BASE_TAG: "22.04" + ROOT_TAG: "root_v6.28.06" + NARG: 2 + +jobs: + + build-and-publish: + + name: Build and push the docker images + + strategy: + matrix: + build: [Dev] + include: + - push: true +# - push: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }} + - build: Dev + tag-suffix: '-dev' + + runs-on: ubuntu-latest + steps: + + - name: Check out the repo + uses: actions/checkout@v4 + with: + submodules: recursive + # Need to avoid a shallow clone (fetch-depth=1) so that the lookup of the tag works + fetch-depth: 0 + + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ github.repository }} + flavor: | + latest=auto + suffix=${{ matrix.tag-suffix }},onlatest=true + tags: | + type=semver,pattern={{raw}} + type=ref,event=branch + type=ref,event=pr + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: setup_buildx + uses: docker/setup-buildx-action@v3 + with: + buildkitd-flags: --debug + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: Root/Dockerfile +# push: ${{ matrix.push }} + push: false + build-args: | + img_repo=${{ env.BASE_REPO }} + img_tag=${{ env.BASE_TAG }} + root_tag=${{ env.ROOT_TAG }} + narg=${{ env.NARG }} + tags: ${{ env.REGISTRY }}/project8/luna_base_root:${{ env.ROOT_TAG }} + platforms: linux/arm64 +# platforms: ${{ matrix.push && 'linux/amd64,linux/arm64' || 'linux/amd64' }} diff --git a/Dev/Dockerfile b/Dev/Dockerfile index cfd8b83..3d45b89 100644 --- a/Dev/Dockerfile +++ b/Dev/Dockerfile @@ -1,6 +1,11 @@ ARG img_repo=ubuntu ARG img_tag=22.04 +ARG root_repo=ghcr.io/project8/luna_base_root +ARG root_tag=root_v6.28.06 + +FROM ${root_repo}:${root_tag} as root_image + FROM ${img_repo}:${img_tag} as base_image ARG common_tag=beta @@ -30,7 +35,9 @@ COPY Scripts ${scripts_dir} # Install as many dependencies as possible using apt RUN ${scripts_dir}/install_packages.sh dev &&\ ${scripts_dir}/install_python_packages.sh &&\ - ${scripts_dir}/install_other_packages.sh &&\ +# ${scripts_dir}/install_other_packages.sh &&\ ${scripts_dir}/create_common_setup.sh &&\ rm -rf ${scripts_dir} &&\ /bin/true + +COPY --from=root_image /usr/local/root /usr/local/root diff --git a/Prod/Dockerfile b/Prod/Dockerfile index b108176..5f934d3 100644 --- a/Prod/Dockerfile +++ b/Prod/Dockerfile @@ -35,7 +35,7 @@ COPY Scripts ${scripts_dir} # libhdf5-dev is removed because it was previously needed to install h5py, but isn't needed for running RUN ${scripts_dir}/install_packages.sh prod &&\ ${scripts_dir}/install_python_packages.sh &&\ - ${scripts_dir}/install_other_packages.sh &&\ +# ${scripts_dir}/install_other_packages.sh &&\ apt-get purge -y \ wget \ pipenv \ @@ -44,3 +44,5 @@ RUN ${scripts_dir}/install_packages.sh prod &&\ ${scripts_dir}/create_common_setup.sh &&\ rm -rf ${scripts_dir} &&\ /bin/true + +COPY --from=root_image /usr/local/root /usr/local/root diff --git a/Root/Dockerfile b/Root/Dockerfile new file mode 100644 index 0000000..a44b9c5 --- /dev/null +++ b/Root/Dockerfile @@ -0,0 +1,33 @@ +ARG img_repo=ubuntu +ARG img_tag=22.04 + +FROM ${img_repo}:${img_tag} as base_image + +# TARGETARCH should get set automatically +ARG TARGETARCH + +# These need to be filled in +ARG root_tag +ARG narg=2 + +ARG cc_val=gcc +ARG cxx_val=g++ +ENV CC=${cc_val} +ENV CXX=${cxx_val} + + + +# Set bash as the default shell +SHELL ["/bin/bash", "-c"] + +ENV CMAKE_LIBRARY_PATH=/usr/lib64 + +# Copy all build scripts +COPY Scripts ${scripts_dir} + +# Install as many dependencies as possible using apt +RUN ${scripts_dir}/install_packages.sh dev root &&\ + ${scripts_dir}/install_root.sh $root_tag $TARGETARCH $narg &&\ + rm -rf ${scripts_dir} &&\ + /bin/true + diff --git a/Scripts/install_packages.sh b/Scripts/install_packages.sh index dc4e392..7fb59ad 100755 --- a/Scripts/install_packages.sh +++ b/Scripts/install_packages.sh @@ -23,9 +23,9 @@ # - vim: convenience utility # - wget: downloading files (e.g. tarballs to install) # - libgsl(-dev): ROOT, Kassiopeia -# - libopenblas(-dev): ??? -# - liblapack(-dev): ??? -# - libfreetype(-dev): ??? +# - libopenblas(-dev): ROOT +# - liblapack(-dev): ROOT +# - libfreetype(-dev): ROOT # - libx11(-dev): ROOT # - libxpm(-dev): ROOT # - libxft(-dev): ROOT @@ -53,24 +53,33 @@ if [[ "$1" = "dev" ]]; then DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ build-essential \ dpkg-dev \ + openssl \ wget \ + git \ cmake \ clang \ - openssl \ - vim \ - python3 \ - pipenv \ libgsl-dev \ - libopenblas-dev \ - liblapack-dev \ - libfreetype-dev \ libx11-dev \ libxpm-dev \ libxft-dev \ libxext-dev \ - libpng-dev \ - libjpeg-dev \ + libopenblas-dev \ + liblapack-dev \ + libfreetype-dev \ + python3 \ + pipenv \ + libssl-dev \ libfftw3-dev \ + libpng-dev \ + libjpeg-dev + + if [[ "$2" = "root" ]]; then + echo "Exiting after only ROOT dependencies installed" + exit 0 + fi + + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + vim \ libboost-all-dev \ libeigen3-dev \ libhdf5-dev \ diff --git a/Scripts/install_root.sh b/Scripts/install_root.sh new file mode 100755 index 0000000..2f71e3a --- /dev/null +++ b/Scripts/install_root.sh @@ -0,0 +1,69 @@ +#! /bin/bash +set -e # exit on error + +# +# This script installs the other (non-python, outside of apt) packages. +# Usage: +# > ./install_other_packages.sh +# +# Current packages here: +# - ROOT: No longer available in the package manager (after Xenial) +# Required by Katydid, Locust, Kassiopeia +# + +ROOT_TAG=$1 +echo "Installing ROOT: $ROOT_TAG" + +TARGETARCH=$2 +echo "Target arch: $TARGETARCH" + +NARG=$3 + +if [[ "$TARGETARCH" = "amd64" ]]; then + echo "Installing pre-built binary" + + ROOT_TARBALL="${ROOT_TAG}.Linux-ubuntu22-x86_64-gcc11.4.tar.gz" + + cd /usr/local + + # Install files and cleanup + URL="https://root.cern/download/$ROOT_TARBALL" + echo "getting this file: $URL" + wget -nv --no-check-certificate $URL #https://root.cern/download/$ROOT_TARBALL + tar -xzf $ROOT_TARBALL + + # Cleanup + rm $ROOT_TARBALL +else + echo "Installing from source" + + # ROOT requires numpy + pip3 install --upgrade pip + pip3 install 'numpy>=1.14' + + ROOT_TARBALL="${ROOT_TAG}.source.tar.gz" + ROOT_SOURCE=/tmp_source + ROOT_INSTALL=/usr/local/root + + mkdir -p $ROOT_INSTALL + + mkdir $ROOT_SOURCE + cd $ROOT_SOURCE + + # Build + wget -nv --no-check-certificate https://root.cern/download/$ROOT_TARBALL + tar -xzf $ROOT_TARBALL + # Tags have the format root_vX.Y.Z, and the directories that are in the tarballs have the format root-X.Y.Z + ROOT_DIR=`echo "$ROOT_TAG" | sed -r 's/[_v]+/-/g'` + mkdir ${ROOT_DIR}/root_build + cd ${ROOT_DIR}/root_build + cmake -DCMAKE_INSTALL_PREFIX=$ROOT_INSTALL .. + cmake --build . -- install -j$NARG + + # Cleanup + cd / + rm $ROOT_TARBALL + rm -r $ROOT_SOURCE +fi + +echo "Target arch: $TARGETARCH"