Skip to content
Snippets Groups Projects
Commit aed162c7 authored by Wouter Deconinck's avatar Wouter Deconinck
Browse files

feat: rm setup_detectors in jug_xl

parent 4a53e0eb
Branches
Tags
1 merge request!902feat: rm setup_detectors in jug_xl
Pipeline #92358 passed with warnings
Pipeline: detector_benchmarks

#92375

    Pipeline: detector_benchmarks

    #92374

      ...@@ -423,8 +423,6 @@ jug_xl:default: ...@@ -423,8 +423,6 @@ jug_xl:default:
      --build-arg BASE_IMAGE=${BASE_IMAGE} --build-arg BASE_IMAGE=${BASE_IMAGE}
      --build-arg INTERNAL_TAG=${INTERNAL_TAG}-default --build-arg INTERNAL_TAG=${INTERNAL_TAG}-default
      --build-arg JUG_VERSION=${EXPORT_TAG}-$(git rev-parse HEAD) --build-arg JUG_VERSION=${EXPORT_TAG}-$(git rev-parse HEAD)
      --build-arg jobs=${JOBS}
      --build-context detectors=.
      --provenance false --provenance false
      containers/jug containers/jug
      2>&1 | tee build.log 2>&1 | tee build.log
      ...@@ -503,8 +501,6 @@ jug_xl:nightly: ...@@ -503,8 +501,6 @@ jug_xl:nightly:
      --build-arg INTERNAL_TAG=${INTERNAL_TAG}-nightly --build-arg INTERNAL_TAG=${INTERNAL_TAG}-nightly
      --build-arg JUG_VERSION=${EXPORT_TAG}-nightly-$(git rev-parse HEAD)-$(date +%Y-%m-%d_%H-%M-%S) --build-arg JUG_VERSION=${EXPORT_TAG}-nightly-$(git rev-parse HEAD)-$(date +%Y-%m-%d_%H-%M-%S)
      --build-arg NIGHTLY=1 --build-arg NIGHTLY=1
      --build-arg jobs=${JOBS}
      --build-context detectors=.
      --provenance false --provenance false
      containers/jug containers/jug
      2>&1 | tee build.log 2>&1 | tee build.log
      ......
      ...@@ -212,16 +212,16 @@ ccache --show-stats ...@@ -212,16 +212,16 @@ ccache --show-stats
      ccache --zero-stats ccache --zero-stats
      EOF EOF
      ## Create views at /usr/local and /opt/detectors ## Create views at /usr/local and /opt/detector
      RUN <<EOF RUN <<EOF
      set -e set -e
      rm -r /usr/local rm -r /usr/local
      sed -i -e '/view: false/d' ${SPACK_ENV}/spack.yaml sed -i -e '/view: false/d' ${SPACK_ENV}/spack.yaml
      cat /opt/spack-environment/view.yaml >> ${SPACK_ENV}/spack.yaml cat /opt/spack-environment/view.yaml >> ${SPACK_ENV}/spack.yaml
      spack -e ${SPACK_ENV} env view regenerate /usr/local spack -e ${SPACK_ENV} env view regenerate /usr/local
      spack -e ${SPACK_ENV} env view regenerate /opt/detectors spack -e ${SPACK_ENV} env view regenerate /opt/detector
      if [[ -n $NIGHTLY && -f /opt/detectors/epic ]] ; then if [[ -n $NIGHTLY && -f /opt/detector/epic ]] ; then
      ln -s /opt/detectors/epic-main/setup.sh /opt/detectors/setup.sh ln -s /opt/detector/epic-main/setup.sh /opt/detector/setup.sh
      fi fi
      EOF EOF
      ...@@ -314,7 +314,7 @@ COPY --from=staging /opt/spack /opt/spack ...@@ -314,7 +314,7 @@ COPY --from=staging /opt/spack /opt/spack
      COPY --from=staging /opt/spack-environment /opt/spack-environment COPY --from=staging /opt/spack-environment /opt/spack-environment
      COPY --from=staging /opt/software /opt/software COPY --from=staging /opt/software /opt/software
      COPY --from=staging /usr/._local /usr/._local COPY --from=staging /usr/._local /usr/._local
      COPY --from=staging /opt/._detectors /opt/._detectors COPY --from=staging /opt/._detector /opt/._detector
      COPY --from=staging /etc/profile.d /etc/profile.d COPY --from=staging /etc/profile.d /etc/profile.d
      COPY --from=staging /etc/jug_info /etc/jug_info COPY --from=staging /etc/jug_info /etc/jug_info
      COPY --from=staging /etc/eic-env.sh /etc/eic-env.sh COPY --from=staging /etc/eic-env.sh /etc/eic-env.sh
      ...@@ -328,13 +328,13 @@ SHELL ["docker-shell"] ...@@ -328,13 +328,13 @@ SHELL ["docker-shell"]
      ## ensure /usr/local is the view, not a symlink ## ensure /usr/local is the view, not a symlink
      RUN <<EOF RUN <<EOF
      set -ex set -ex
      rm -rf /usr/local /opt/detectors rm -rf /usr/local /opt/detector
      LOCAL_PREFIX_PATH=$(realpath $(ls /usr/._local/ | tail -n1)) LOCAL_PREFIX_PATH=$(realpath $(ls /usr/._local/ | tail -n1))
      mv /usr/._local/${LOCAL_PREFIX_PATH} /usr/local mv /usr/._local/${LOCAL_PREFIX_PATH} /usr/local
      ln -s /usr/local /usr/._local/${LOCAL_PREFIX_PATH} ln -s /usr/local /usr/._local/${LOCAL_PREFIX_PATH}
      DETECTORS_PREFIX_PATH=$(realpath $(ls /opt/._detectors/ | tail -n1)) DETECTOR_PREFIX_PATH=$(realpath $(ls /opt/._detector/ | tail -n1))
      mv /opt/._detectors/${DETECTORS_PREFIX_PATH} /opt/detectors mv /opt/._detector/${DETECTOR_PREFIX_PATH} /opt/detector
      ln -s /opt/detectors /opt/._detectors/${DETECTORS_PREFIX_PATH} ln -s /opt/detector /opt/._detector/${DETECTOR_PREFIX_PATH}
      EOF EOF
      ## set ROOT TFile forward compatibility ## set ROOT TFile forward compatibility
      ......
      #!/usr/bin/env python3
      import os
      import sys
      import yaml
      import argparse
      import subprocess
      from datetime import datetime
      DETECTOR_REPO_GROUP = 'https://github.com/eic'
      DETECTOR_ENV ='''
      #!/bin/sh
      export DETECTOR={detector}
      export DETECTOR_PATH={data_prefix}
      export DETECTOR_CONFIG={detector}
      export DETECTOR_VERSION={version}
      ## Export detector libraries
      export LD_LIBRARY_PATH={prefix}/lib${{LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}}
      ## modify PS1 for this detector version
      export PS1="${{PS1:-}}"
      export PS1="{branch}${{PS1_SIGIL}}>${{PS1#*>}}"
      unset branch
      '''
      if __name__ == '__main__':
      parser = argparse.ArgumentParser()
      parser.add_argument(
      '-p', '--prefix',
      dest='prefix',
      default='/opt/detector',
      help='Main detector prefix')
      parser.add_argument(
      '-c', '--config',
      dest='config',
      default='detectors.yaml',
      help='Detector configuration file')
      parser.add_argument('--nightly', action='store_true', dest='nightly',
      help='Store nightly snapshot (will also be set as default)')
      args = parser.parse_args()
      print('Installing detector configuration from {} to {}'.format(args.config,
      args.prefix))
      if args.nightly:
      print(' --> Nightly requested, will default configurations to nightly')
      else:
      print(' --> Regular run, nightly snapshot will NOT be installed')
      print(' --> Loading detector configuration')
      default_found = False
      default_detector = ''
      default_version = ''
      with open(args.config) as f:
      data=yaml.load(f, Loader=yaml.FullLoader)
      detectors=data['detectors']
      for det in detectors:
      if not args.nightly and 'nightly' in detectors[det]:
      del detectors[det]['nightly']
      for branch in detectors[det]:
      cfg = detectors[det][branch]
      default_str = ''
      if not default_found:
      if args.nightly and branch == 'nightly':
      default_str = ' (default)'
      default_detector = det
      default_version = 'nightly'
      default_found = True
      elif not args.nightly and 'default' in cfg and cfg['default']:
      default_str = ' (default)'
      default_detector = det
      default_version = cfg['version']
      default_found = True
      print(' - {}: {}{}'.format(det, branch, default_str))
      print(' --> Building and installing detector libraries')
      process_list = []
      for det in detectors:
      if not args.nightly and 'nightly' in detectors[det]:
      del detectors[det]['nightly']
      for branch in detectors[det]:
      cfg = detectors[det][branch]
      version = cfg['version'] if branch != 'nightly' else 'nightly'
      prefix = '{}/{}-{}'.format(args.prefix, det, version)
      data_dir = '{}/share/{}'.format(prefix, det)
      ## build and install
      print(' - {}-{}'.format(det, cfg['version']))
      ## cleanup
      cmd = [f'rm -rf /tmp/build-{version} /tmp/det-{version}']
      print(' '.join(cmd))
      subprocess.check_call(' '.join(cmd), shell=True)
      ## clone
      cmd = [
      'git clone --depth 1 -b {branch} {repo_grp}/{detector}.git /tmp/det-{version}'.format(
      branch=cfg['version'],
      repo_grp=DETECTOR_REPO_GROUP,
      detector=det,
      version=version)
      ]
      print(' '.join(cmd))
      subprocess.check_call(' '.join(cmd), shell=True)
      ## patches
      if cfg.get('patches'):
      for patch in cfg['patches']:
      cmd = [f'curl -L {patch} | patch -p1 -d/tmp/det-{version}']
      print(' '.join(cmd))
      subprocess.check_call(' '.join(cmd), shell=True)
      ## build
      cxxflags = ''
      if 'CXXFLAGS' in os.environ:
      cxxflags = os.environ['CXXFLAGS']
      if cfg.get('cxxflags'):
      cxxflags = cfg['cxxflags']
      cmd = [
      f'cmake -B /tmp/build-{version} -S /tmp/det-{version} -DCMAKE_CXX_STANDARD=17',
      f'-DCMAKE_CXX_FLAGS="-Wno-psabi {cxxflags}"',
      f'-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache',
      f'-DCMAKE_INSTALL_PREFIX={prefix}'
      ]
      print(' '.join(cmd))
      subprocess.check_call(' '.join(cmd), shell=True)
      ## install
      cmd = [
      f'cmake --build /tmp/build-{version} -j$(($(($(nproc)/4))+1)) -- install'
      ]
      print(' '.join(cmd))
      subprocess.check_output(' '.join(cmd), shell=True)
      ## write version info to jug_info if available
      if os.path.exists('/etc/jug_info'):
      cmd = [f'cd /tmp/det-{version}',
      '&&',
      'echo " - {detector}/{branch}: {version}-$(git rev-parse HEAD)"'.format(
      detector=det,
      branch=branch,
      version=cfg['version']),
      '>> /etc/jug_info',
      '&&',
      'cd -']
      print(' '.join(cmd))
      subprocess.check_call(' '.join(cmd), shell=True)
      ## cleanup
      cmd = f'rm -rf /tmp/det-{version} /tmp/build-{version}'
      print(cmd)
      subprocess.check_call(cmd, shell=True)
      # be resilient against failures
      if os.path.exists(prefix):
      ## create a shortcut for the prefix if desired
      if branch != version:
      cmd = 'rm -rf {shortcut} && ln -sf {prefix} {shortcut}'.format(
      prefix=prefix,
      shortcut='{}/{}-{}'.format(args.prefix, det, branch))
      print(cmd)
      subprocess.check_call(cmd, shell=True)
      ## write an environment file for this detector
      with open('{prefix}/setup.sh'.format(prefix=prefix), 'w') as f:
      print(DETECTOR_ENV.format(
      prefix=prefix,
      detector=det,
      data_prefix=data_dir,
      version=cfg['version'],
      branch=branch),
      file=f)
      ## run once inside global prefix to initialize artifacts in /opt/detectors
      # os.environ['DETECTOR_PATH'] = args.prefix
      # cmd = f'cd {args.prefix} && source {prefix}/setup.sh && ddsim --compactFile {prefix}/share/{det}/{det}.xml --printLevel DEBUG -G -N1'
      # print(cmd)
      # process_list.append(subprocess.Popen(cmd, shell=True, executable='/bin/bash', stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
      ## run once inside specific prefix to initialize artifacts in $DETECTOR_PATH
      os.environ['DETECTOR_PATH'] = args.prefix
      cmd = f'cd {prefix}/share/{det} && source {prefix}/setup.sh && ddsim --compactFile {prefix}/share/{det}/{det}.xml --printLevel DEBUG -G -N1'
      print(cmd)
      process_list.append(subprocess.Popen(cmd, shell=True, executable='/bin/bash', stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
      while len(process_list) > 0:
      now = datetime.now()
      current_time = now.strftime("%H:%M:%S")
      print("{} processes running... ({})".format(len(process_list), current_time))
      (out, err) = process_list[-1].communicate()
      if process_list[-1].wait() != 0:
      print(process_list[-1].args)
      if out is not None:
      print("stdout:")
      print(out.decode())
      if err is not None:
      print("stderr:")
      print(err.decode())
      sys.exit(1)
      process_list.pop()
      if not default_found and not args.nightly:
      # Skip symlinking if no defaults present and its not a nightly build
      pass
      else:
      print(' --> Symlinking default detector for backward compatibility')
      full_prefix='{}/{}-{}'.format(args.prefix, default_detector, default_version)
      cmd = ['ln -sf {full_prefix}/share {short_prefix}',
      '&&',
      'ln -sf {full_prefix}/lib {short_prefix}',
      '&&',
      'ln -sf {full_prefix}/setup.sh {short_prefix}']
      print(' '.join(cmd))
      subprocess.check_call(' '.join(cmd).format(full_prefix=full_prefix, short_prefix=args.prefix), shell=True)
      print('All done!')
      ...@@ -10,32 +10,8 @@ ARG INTERNAL_TAG="testing" ...@@ -10,32 +10,8 @@ ARG INTERNAL_TAG="testing"
      FROM ${DOCKER_REGISTRY}${BASE_IMAGE}:${INTERNAL_TAG} FROM ${DOCKER_REGISTRY}${BASE_IMAGE}:${INTERNAL_TAG}
      ARG TARGETPLATFORM ARG TARGETPLATFORM
      ARG EICWEB="https://eicweb.phy.anl.gov/api/v4/projects"
      ARG jobs=1
      ## version will automatically bust cache for nightly, as it includes ## version will automatically bust cache for nightly, as it includes
      ## the date ## the date
      ARG JUG_VERSION=1 ARG JUG_VERSION=1
      RUN echo " - jug_xl: ${JUG_VERSION}" >> /etc/jug_info RUN echo " - jug_xl: ${JUG_VERSION}" >> /etc/jug_info
      ## also install detector/ip geometries into opt
      ARG NIGHTLY=''
      ## cache bust when updated repositories
      # - just master on eicweb (FIXME too narrow)
      ADD ${EICWEB}/473/repository/tree?ref=master /tmp/473.json
      ADD ${EICWEB}/452/repository/tree?ref=master /tmp/452.json
      # - all branches for ip6 and epic on github
      ADD https://api.github.com/repos/eic/ip6 /tmp/ip6.json
      ADD https://api.github.com/repos/eic/epic /tmp/epic.json
      COPY setup_detectors.py /tmp
      COPY --from=detectors detectors.yaml /tmp
      RUN --mount=type=cache,target=/ccache/,sharing=locked,id=${TARGETPLATFORM} <<EOF
      set -e
      cd /tmp
      export CCACHE_DIR=/ccache
      [ "z$NIGHTLY" = "z1" ] && NIGHTLY_FLAG="--nightly" || NIGHTLY_FLAG=""
      /tmp/setup_detectors.py --prefix /opt/detector --config /tmp/detectors.yaml $NIGHTLY_FLAG
      ccache --show-stats
      rm /tmp/setup_detectors.py
      EOF
      # Only retain last 6 months of epic geometry versions
      detectors:
      epic:
      nightly:
      default: true
      version: main
      main:
      version: main
      23.10.0:
      version: 23.10.0
      23.11.0:
      version: 23.11.0
      23.12.0:
      version: 23.12.0
      24.02.0:
      version: 24.02.0
      24.02.1:
      version: 24.02.1
      24.03.0:
      version: 24.03.0
      24.03.1:
      version: 24.03.1
      24.04.0:
      version: 24.04.0
      24.05.0:
      version: 24.05.0
      \ No newline at end of file
      ...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
      exclude: [epic] exclude: [epic]
      link_type: symlink link_type: symlink
      detectors: detectors:
      root: /opt/detectors root: /opt/detector
      select: [epic] select: [epic]
      projections: projections:
      all: '{name}-{version}' all: '{name}-{version}'
      ......
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Please register or to comment