|
1 | 1 | version: 2.1
|
2 | 2 | jobs:
|
3 | 3 | build:
|
4 |
| - parameters: |
5 |
| - python-version: |
6 |
| - type: string |
| 4 | + environment: |
| 5 | + MIN_PYTHON_VERSION: "3.8" |
| 6 | + MAX_PYTHON_VERSION: "3.13" |
| 7 | + XDMOD_10_5_IMAGE: tools-ext-01.ccr.xdmod.org/xdmod-10.5.0-x86_64:rockylinux8.5-0.3 |
| 8 | + XDMOD_11_0_IMAGE: tools-ext-01.ccr.xdmod.org/xdmod:x86_64-rockylinux8.9.20231119-v11.0.0-1.0-03 |
7 | 9 | docker:
|
8 |
| - - image: cimg/python:<< parameters.python-version >> |
| 10 | + - image: cimg/base:current |
9 | 11 | steps:
|
10 | 12 | - checkout
|
| 13 | + - setup_remote_docker |
11 | 14 | - run:
|
12 |
| - name: Install dependencies |
| 15 | + name: Spin up containers and test different Python versions against different XDMoD web server versions |
13 | 16 | command: |
|
14 |
| - python -m pip install --upgrade pip |
15 |
| - python -m pip install flake8 flake8-commas flake8-quotes pytest |
16 |
| - python -m pip install -e . |
17 |
| - - run: |
18 |
| - name: Lint with Flake8 |
19 |
| - command: python3 -m flake8 . --max-complexity=10 --show-source --exclude __init__.py |
20 |
| - - run: |
21 |
| - name: Test with pytest |
22 |
| - command: python3 -m pytest tests/unit |
23 |
| -workflows: |
24 |
| - full-build: |
25 |
| - jobs: |
26 |
| - - build: |
27 |
| - matrix: |
28 |
| - parameters: |
29 |
| - python-version: |
30 |
| - - "3.13" |
31 |
| - - "3.12" |
32 |
| - - "3.11" |
33 |
| - - "3.10" |
34 |
| - - "3.9" |
35 |
| - - "3.8" |
| 17 | + set -x |
| 18 | + docker compose -f .circleci/docker-compose.yml up -d |
| 19 | + declare -a python_containers=$(yq '.services | keys | .[] | select(. == "python-*")' .circleci/docker-compose.yml) |
| 20 | + declare -a xdmod_containers=$(yq '.services | keys | .[] | select(. == "xdmod-*")' .circleci/docker-compose.yml) |
| 21 | + # Copy the xdmod-data source code to the Python containers, lint |
| 22 | + # with Flake 8, and install the package and its testing |
| 23 | + # dependencies. |
| 24 | + for python_container in $python_containers; do |
| 25 | + docker cp . $python_container:/home/circleci/project |
| 26 | + docker exec $python_container bash -c 'sudo chown -R circleci:circleci /home/circleci/project' |
| 27 | + docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install --upgrade pip' |
| 28 | + docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install --upgrade flake8 flake8-commas flake8-quotes' |
| 29 | + docker exec -w /home/circleci/project $python_container bash -c 'python3 -m flake8 . --max-complexity=10 --show-source --exclude __init__.py' |
| 30 | + docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install -e .' |
| 31 | + docker exec -w /home/circleci/project $python_container bash -c 'python3 -m pip install --upgrade python-dotenv pytest coverage' |
| 32 | + done |
| 33 | + # Set up XDMoD web server containers. |
| 34 | + for xdmod_container in $xdmod_containers; do |
| 35 | + # Generate OpenSSL key and certificate. |
| 36 | + docker exec $xdmod_container bash -c "openssl genrsa -rand /proc/cpuinfo:/proc/filesystems:/proc/interrupts:/proc/ioports:/proc/uptime 2048 > /etc/pki/tls/private/$xdmod_container.key" |
| 37 | + docker exec $xdmod_container bash -c "openssl req -new -key /etc/pki/tls/private/$xdmod_container.key -x509 -sha256 -days 365 -set_serial $RANDOM -extensions v3_req -out /etc/pki/tls/certs/$xdmod_container.crt -subj '/C=XX/L=Default City/O=Default Company Ltd/CN=$xdmod_container' -addext 'subjectAltName=DNS:$xdmod_container'" |
| 38 | + # Update the server hostnames and certificates so the Python |
| 39 | + # containers can make requests to them. |
| 40 | + docker exec $xdmod_container bash -c "sed -i \"s/localhost/$xdmod_container/g\" /etc/httpd/conf.d/xdmod.conf" |
| 41 | + if [[ "$xdmod_container" =~ 'xdmod-*-dev' ]]; then |
| 42 | + if [ "$xdmod_container" = 'xdmod-main-dev' ]; then |
| 43 | + branch='main' |
| 44 | + else |
| 45 | + branch="xdmod$(echo $xdmod_container | sed 's/xdmod-\(.*\)-dev/\1/' | sed 's/-/./')" |
| 46 | + fi |
| 47 | + # Install and run the latest development version of the XDMoD |
| 48 | + # web server. |
| 49 | + docker exec $xdmod_container bash -c 'git clone --depth=1 --branch=$branch https://github.com/ubccr/xdmod.git /root/xdmod' |
| 50 | + docker exec -w /root/xdmod $xdmod_container bash -c 'composer install' |
| 51 | + docker exec -w /root/xdmod $xdmod_container bash -c '/root/bin/buildrpm xdmod' |
| 52 | + docker exec -w /root/xdmod $xdmod_container bash -c 'XDMOD_TEST_MODE=upgrade ./tests/ci/bootstrap.sh' |
| 53 | + docker exec -w /root/xdmod $xdmod_container bash -c './tests/ci/validate.sh' |
| 54 | + elif [[ "$xdmod_container" =~ xdmod-* ]]; then |
| 55 | + # Run the XDMoD web server. |
| 56 | + docker exec $xdmod_container bash -c '/root/bin/services start' |
| 57 | + fi |
| 58 | + # Copy the 10,000 users file into the container and shred it. |
| 59 | + # We use this file so we can test filters with more than 10,000 |
| 60 | + # values and date ranges that span multiple quarters. |
| 61 | + docker cp tests/ci/artifacts/10000users.log $xdmod_container:. |
| 62 | + docker exec $xdmod_container xdmod-shredder -r frearson -f slurm -i 10000users.log |
| 63 | + # Ingest and aggregate. |
| 64 | + date=$(date --utc +%Y-%m-%d) |
| 65 | + docker exec $xdmod_container xdmod-ingestor --ingest |
| 66 | + docker exec $xdmod_container xdmod-ingestor --aggregate=job --last-modified-start-date $date |
| 67 | + # Copy certificate (for doing requests) from the XDMoD container. |
| 68 | + docker cp $xdmod_container:/etc/pki/tls/certs/$xdmod_container.crt . |
| 69 | + # Copy certificate to one of the Python containers and get an |
| 70 | + # XDMoD API token for the XDMoD container. |
| 71 | + docker cp $xdmod_container.crt $python_container:/home/circleci/project |
| 72 | + rest_token=$(docker exec \ |
| 73 | + -e CURL_CA_BUNDLE="/home/circleci/project/$xdmod_container.crt" \ |
| 74 | + $python_container \ |
| 75 | + bash -c "curl \ |
| 76 | + -sS \ |
| 77 | + -X POST \ |
| 78 | + -c xdmod.cookie \ |
| 79 | + -d 'username=normaluser&password=normaluser' \ |
| 80 | + https://$xdmod_container/rest/auth/login \ |
| 81 | + | jq -r '.results.token'" |
| 82 | + ) |
| 83 | + docker exec $python_container bash -c 'echo -n "XDMOD_API_TOKEN="' > ${xdmod_container}-token |
| 84 | + docker exec \ |
| 85 | + -e CURL_CA_BUNDLE="/home/circleci/project/$xdmod_container.crt" \ |
| 86 | + $python_container \ |
| 87 | + bash -c "curl \ |
| 88 | + -sS \ |
| 89 | + -X POST \ |
| 90 | + -b xdmod.cookie \ |
| 91 | + https://$xdmod_container/rest/users/current/api/token?token=$rest_token \ |
| 92 | + | jq -r '.data.token'" \ |
| 93 | + >> ${xdmod_container}-token |
| 94 | + done |
| 95 | + # Run the tests against each XDMoD web server. |
| 96 | + for python_container in $python_containers; do |
| 97 | + for xdmod_container in $xdmod_containers; do |
| 98 | + # Copy certificate (for doing requests) to the Python |
| 99 | + # container. |
| 100 | + docker cp $xdmod_container.crt $python_container:/home/circleci/project |
| 101 | + # Copy XDMoD API token to the Python container. |
| 102 | + docker cp ${xdmod_container}-token $python_container:/home/circleci/.xdmod-data-token |
| 103 | + # Run tests in the Python container. |
| 104 | + docker exec \ |
| 105 | + -e CURL_CA_BUNDLE="/home/circleci/project/$xdmod_container.crt" \ |
| 106 | + -e XDMOD_HOST="https://$xdmod_container" \ |
| 107 | + -e XDMOD_VERSION="$xdmod_container" \ |
| 108 | + $python_container \ |
| 109 | + bash -c 'python3 -m coverage run --branch --append -m pytest -vvs -o log_cli=true tests/' |
| 110 | + done |
| 111 | + # Make sure 100% test coverage. |
| 112 | + docker exec $python_container bash -c 'python3 -m coverage report -m --fail-under=100' |
| 113 | + done |
0 commit comments