Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2: implement common docker containers #3

Merged
merged 162 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
eeb3c22
#2: add deps scripts
tlamonthezie Sep 18, 2024
501afb7
#2: add generic dockerfiles
tlamonthezie Sep 18, 2024
650146c
#2: add dockerfiles adapted from vt
tlamonthezie Sep 18, 2024
04a17c4
#2: investigate general approach to define CI target platforms
tlamonthezie Sep 18, 2024
784e627
#2: work on analysis of a more generic way to support both github and…
tlamonthezie Sep 19, 2024
339b8f5
#2: generate docker files from configuration file with standardized p…
tlamonthezie Sep 19, 2024
94b0193
#2: make some ci depndencies setup working for docker
tlamonthezie Sep 19, 2024
d272f39
#2: improve dependencies integration support WIP
tlamonthezie Sep 20, 2024
ed853c9
#2: update ci config tree and docker build logic
tlamonthezie Sep 20, 2024
c9221cb
#2: introduce pipeline matrix generator and shared pipeline matrices …
tlamonthezie Sep 20, 2024
39f1c69
#2: update template Github workflow to run all test pipelines with ba…
tlamonthezie Sep 20, 2024
53a6b56
#2: update pipeline matrix json files and template ghworkflow
tlamonthezie Sep 20, 2024
baf2811
#2: name the build and test workflow template
tlamonthezie Sep 20, 2024
8c5a789
#2: add packages config to deps in config file and generate setup scr…
tlamonthezie Sep 23, 2024
acd5bfc
#2: update ci matrix
tlamonthezie Sep 23, 2024
415ad19
#2: update template workflow to retrieve scripts
tlamonthezie Sep 23, 2024
d9942c6
#2: update global ci config file
tlamonthezie Sep 24, 2024
315557f
#2: fix ci shell statement compatibility for zsh
tlamonthezie Sep 24, 2024
529e84b
#2: rename a configuration key
tlamonthezie Sep 24, 2024
f3db604
#2: fix ci shell error
tlamonthezie Sep 24, 2024
8c6ba1e
#2: refactor setup logic
tlamonthezie Sep 24, 2024
bbc25ee
#2: fix permission in ci
tlamonthezie Sep 24, 2024
03ca1e5
#2: try fix ci permissions
tlamonthezie Sep 24, 2024
c3c8fd3
#2: fix zsh error
tlamonthezie Sep 24, 2024
373ae72
#2: add conda environments to macos ci environment
tlamonthezie Sep 24, 2024
7f6ec40
#2: limit dependencies downloads to only required ones
tlamonthezie Sep 24, 2024
588e0bb
#2: move vt files to some unused folder
tlamonthezie Sep 24, 2024
3cf132f
#2: fix docker environment variables and refactor build script
tlamonthezie Sep 25, 2024
627ed2d
#2: add python3 to default apt packages for docker
tlamonthezie Sep 25, 2024
849601d
#2: update dependencies scripts
tlamonthezie Sep 25, 2024
cdddec5
#2: start integrating configuration for vt docker images
tlamonthezie Sep 25, 2024
25bde09
#2: configuration format changes and refactoring
tlamonthezie Sep 25, 2024
43fe3b1
#2: add sample docker run in ci
tlamonthezie Sep 25, 2024
6332e7c
#2: validate build of all docker images in CI
tlamonthezie Sep 25, 2024
7086ddf
#2: refactor rename files
tlamonthezie Sep 25, 2024
a4f44a8
#2: add TODO file for current work
tlamonthezie Sep 25, 2024
48dbcf0
#2: update ci build and test template
tlamonthezie Sep 26, 2024
18a6775
#2: fix extra space in dependency install instruction and simplify co…
tlamonthezie Sep 26, 2024
54c3164
#2: add macos demo and remove old dev config
tlamonthezie Sep 26, 2024
6381689
#2: add support of specifying compiler packages or turn off
tlamonthezie Sep 26, 2024
5d0c246
#2: enable dual run in runner and in docker
tlamonthezie Sep 26, 2024
7438ddf
#2: add post setup script for docker build
tlamonthezie Sep 26, 2024
f930262
#2: add pre-setup script for docker image build
tlamonthezie Sep 26, 2024
e167a8e
#2: fix alpine docker image build problems
tlamonthezie Sep 26, 2024
56765f3
#2: integrate pre setup and post setup into the setup script and add …
tlamonthezie Sep 26, 2024
120bd20
#2: update python
tlamonthezie Sep 27, 2024
e29c6ce
#2: rename ci python scripts
tlamonthezie Sep 27, 2024
bacbd6f
#2: fix macos setup
tlamonthezie Sep 27, 2024
184a527
#2: remove docker debug output
tlamonthezie Sep 27, 2024
9284151
#2: introduce !extend yaml tag to extend lists in config
tlamonthezie Sep 30, 2024
258ff33
#2: add documentation
tlamonthezie Sep 30, 2024
7f9646c
#2: start integration of 2 cuda docker images
tlamonthezie Sep 30, 2024
0b373f2
#2: fix setup script
tlamonthezie Sep 30, 2024
db62189
#2: add support of env in deps scripts call
tlamonthezie Sep 30, 2024
24d13e3
#2: update setup script output
tlamonthezie Sep 30, 2024
b513fd4
#2: add vt build and test CI example
tlamonthezie Sep 30, 2024
dfb248f
#2: fix errors in config and regenerate github matrix
tlamonthezie Sep 30, 2024
c83950f
#2: try fix CI command
tlamonthezie Oct 14, 2024
5e63eeb
#2: forward docker run status code to ci
tlamonthezie Oct 14, 2024
a27409e
#2: update matrix and ci pipeline example
tlamonthezie Oct 14, 2024
b64b468
#2: update ci config
tlamonthezie Oct 14, 2024
e5d16a4
#2: update macos 14 mpich version
tlamonthezie Oct 14, 2024
6763c5b
#2: build timestamp for caching host independent
tlamonthezie Oct 14, 2024
4e9f30d
#2: add config for intel oneapi cpp
tlamonthezie Oct 15, 2024
7ddbdd5
#2: add VT test in build docker to validate docker image
tlamonthezie Oct 15, 2024
ccafaca
#2: fix vt build missing directory in ci
tlamonthezie Oct 15, 2024
d2a76df
#2: add python3 to default alpine packages
tlamonthezie Oct 15, 2024
67bb702
#2: try set intel additional env variables in docker
tlamonthezie Oct 15, 2024
8e1784a
#2: update docker image to support additional variables
tlamonthezie Oct 15, 2024
73143f2
#2: update mpich to latest stable release
tlamonthezie Oct 15, 2024
c2e6166
#2: add new setup configurations from vt - wip
tlamonthezie Oct 22, 2024
7f4df13
#2: add ubuntu configurations and setup
tlamonthezie Oct 22, 2024
f2c494c
#2: add missing mpich build parameter
tlamonthezie Oct 22, 2024
a009cb6
#2: update setup commands pipeline to return error if any
tlamonthezie Oct 22, 2024
9f6042a
#2: change setup shell to bash after bash is installed
tlamonthezie Oct 22, 2024
92a5422
#2: install macos mpich as brew package and add PATH_PREFIX docker va…
tlamonthezie Oct 22, 2024
532670f
#2: exit build-docker-image script with docker build status
tlamonthezie Oct 22, 2024
eb57621
#2: fix invalid base docker images
tlamonthezie Oct 22, 2024
6689dca
#2: fix base docker image versions
tlamonthezie Oct 22, 2024
f01fc63
#2: add docker inspect after docker build to validate the build
tlamonthezie Oct 22, 2024
20448ca
#2: add first version of Azure pipline
tlamonthezie Oct 22, 2024
f9089ed
#2: update azure ci
tlamonthezie Oct 22, 2024
42c3f15
#2: update matrix to match azure specs
tlamonthezie Oct 22, 2024
6b5fbf1
#2: update workflow files comments and limit to PRs
tlamonthezie Oct 22, 2024
8bfe3ee
#2: fix inexisting github runner and install mpich using brew on macos
tlamonthezie Oct 23, 2024
76dff48
#2: fix invalid packages list in conf for some setup
tlamonthezie Oct 23, 2024
5e9f721
#2: use same name in jobs for azure and github workflows
tlamonthezie Oct 23, 2024
c7000b1
#2: update workflows names
tlamonthezie Oct 23, 2024
18ccdf7
#2: fix invalid environment variable in a configuration
tlamonthezie Oct 23, 2024
84792e6
#2: test azure job name
tlamonthezie Oct 23, 2024
e38acb0
#2: test parameter in job name for azure
tlamonthezie Oct 23, 2024
a233075
#2: restore azure pipeline
tlamonthezie Oct 23, 2024
594a262
#2: move azure pipeline file
tlamonthezie Oct 23, 2024
2065134
#2: simplify names in workflows
tlamonthezie Oct 23, 2024
5a17b32
#2: update matrix variables casing
tlamonthezie Oct 23, 2024
96cab4e
#2: add PROXY argument to dockerfile
tlamonthezie Oct 31, 2024
2ba602d
#2: add steps to azure pipeline sample
tlamonthezie Oct 31, 2024
6863006
#2: remove trailing whitespaces
tlamonthezie Oct 31, 2024
0e82d3f
#2: try fix yaml processing errors in Azure
tlamonthezie Oct 31, 2024
ba8d2e1
#2: try fix condition in azure pipeline
tlamonthezie Oct 31, 2024
0eb4a23
#2: try fix condition in azure pipeline
tlamonthezie Oct 31, 2024
760dcee
#2: try another fix in azure workflow
tlamonthezie Oct 31, 2024
c8ae463
#2: try fix azure condition evaluation error
tlamonthezie Oct 31, 2024
caa0940
#2: add all test configurations to the Azure pipelines
tlamonthezie Oct 31, 2024
b7ecc34
#2: add ccache environment variables and add comments in config
tlamonthezie Nov 12, 2024
76ca7dc
#2: add 2 images for gcc with zoltan and clang with zoltan
tlamonthezie Nov 12, 2024
fe50324
#2: rename ci pipelines
tlamonthezie Nov 12, 2024
9c1e988
#2: set FC env variable for fortran in clang images
tlamonthezie Nov 12, 2024
425b89f
#2: update flang variable in config
tlamonthezie Nov 12, 2024
77a5e1a
#2: add missing FC environment variable to docker file
tlamonthezie Nov 12, 2024
658f84d
#2: set FC env var and fortran install only for 2 zoltan images
tlamonthezie Nov 12, 2024
09fb093
#2: update config for zoltan and vtk installations
tlamonthezie Nov 15, 2024
964c0b3
#2: fix configuration name
tlamonthezie Nov 15, 2024
414ec53
#2: replace flang-16 dep by flang-new-16 to try a fix and update nvcc…
tlamonthezie Nov 15, 2024
dedea38
#2: add ENV DEBIAN_FRONTEND=noninteractive to base dockerfile
tlamonthezie Nov 15, 2024
370ef89
#2: empty azure matrix temporarily and update config file
tlamonthezie Nov 15, 2024
d122f3e
#2: update setup scripts and fix dependency
tlamonthezie Nov 19, 2024
abda18a
#2: remove unused old setup scripts
tlamonthezie Nov 19, 2024
6bdbe3f
#2: enable running a command in dependencies setup phase
tlamonthezie Nov 19, 2024
e786d7a
#2 : try fix flang-16 linker issues by using -flang-experimental-exec…
tlamonthezie Nov 19, 2024
1674752
#2: fix fortran link
tlamonthezie Nov 19, 2024
f1b9ad0
#2: fix error in vtk dependency script
tlamonthezie Nov 19, 2024
1341c56
#2: fix error in build-setup.py and add mesa drivers to setup having vtk
tlamonthezie Nov 19, 2024
f2017e7
#2: change flang-16 to gfortran-13 in clang16 test env
tlamonthezie Nov 19, 2024
3caae2d
#2: clean scripts and config and add docker image wf- prefix
tlamonthezie Nov 26, 2024
3851116
#2: add docker push step
tlamonthezie Nov 26, 2024
272dbd6
#2: fix invalid cuda image tag
tlamonthezie Nov 26, 2024
0d45000
#2: remove trailing whitespace
tlamonthezie Nov 26, 2024
80273f3
#2: fix missing space in docker build command
tlamonthezie Nov 26, 2024
2fd8113
#2: restore azure matrix and clean yaml files
tlamonthezie Nov 26, 2024
c1cce2d
#2: use double quotes in python scripts as possible for strings and c…
tlamonthezie Nov 26, 2024
88f4514
#2: clean up workflow files
tlamonthezie Nov 26, 2024
db147ee
#2: remove unused script
tlamonthezie Nov 26, 2024
7f14bf4
#2: simplify and clean base dockerfile
tlamonthezie Nov 27, 2024
7e12398
#2: remove trailing whitespaces
tlamonthezie Nov 27, 2024
0aab735
#2: rebuild docker images in CI
tlamonthezie Nov 27, 2024
8132df5
#2: fix config
tlamonthezie Nov 27, 2024
317d0cd
#2: fix gcov version in gcc environments
tlamonthezie Dec 11, 2024
4788af3
#2: add gcovr to alpine image
tlamonthezie Dec 12, 2024
bae72b4
#2: remove build-and-test github actions moved to the test-ci-project…
tlamonthezie Dec 12, 2024
49a463e
#2: add gcovr package by default in all setup and lcov to develop image
tlamonthezie Dec 12, 2024
3059ca4
#2: keep coverage reporter only in develop and in alpine
tlamonthezie Dec 12, 2024
5cecdf4
#2: remove gcov env variable to simplify
tlamonthezie Dec 18, 2024
5eeb99f
#2: rename ci workflow name
tlamonthezie Dec 18, 2024
31aad46
#2: remove trailig whitespace
tlamonthezie Dec 18, 2024
14c6147
#2: clean and set master branch as the reference branch in CI
tlamonthezie Dec 18, 2024
70314fd
#2: fix missing new line in dependency scripts
tlamonthezie Dec 18, 2024
1a38b18
#2: copy scripts directly to docker instead of wget
tlamonthezie Dec 18, 2024
8eabfbd
#2: update workflow to work even if not on master to build images
tlamonthezie Dec 18, 2024
00131e3
#2: update libunwind script output
tlamonthezie Dec 18, 2024
80334d0
#2: update temp directory used in docker when building
tlamonthezie Dec 18, 2024
8417966
#2: try remove arg statements possibly duplicated
tlamonthezie Dec 18, 2024
2d7e33c
#2: update if condition in ci
tlamonthezie Dec 18, 2024
7db08f7
#2: enable temporary pushing docker images
tlamonthezie Dec 18, 2024
7f8ee3b
#2: restore push docker image condition
tlamonthezie Dec 18, 2024
8d243af
#2: fix condition in setup script
tlamonthezie Dec 18, 2024
6425d47
#2: enable pushing images
tlamonthezie Dec 18, 2024
20c8793
#2: finalize setup script
tlamonthezie Dec 19, 2024
8a94864
#2: remove unnecessary scripts
tlamonthezie Dec 19, 2024
37aadfb
#2: remove obsolete image ubuntu 18 gcc8
tlamonthezie Dec 19, 2024
1682242
#2: fix trailing whitespaces
tlamonthezie Dec 19, 2024
7087408
#2: fix setup script syntax error
tlamonthezie Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/action-git-diff-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Run git check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build & Push docker image

on:
push:
branches:
- master
pull_request:
branches: "*"

jobs:
get-matrix:
runs-on: ubuntu-latest
name: Get matrix
steps:
- uses: actions/checkout@v4
- name: Get matrix
id: get-matrix
run: |
matrix=$(cat ci/shared/matrix/github.json | jq '.matrix' | jq -c '[ .[] | select( .image != null) ]')
echo "runner=$(echo $matrix)" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.get-matrix.outputs.runner }}

build-image:
name: Build ${{ matrix.runner.name }}
runs-on: ${{ matrix.runner.runs-on }}
needs: get-matrix
strategy:
fail-fast: false
matrix:
runner: ${{ fromJson(needs.get-matrix.outputs.matrix ) }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- run: pip install pyyaml

- name: Build Docker image
run: |
python ci/build-docker-image.py ${{ matrix.runner.image }}
docker image inspect ${{ matrix.runner.image }}
- name: Test Docker image (VT build & test)
run: |
CMD='echo "CC=$CC" ; \
echo "CXX=$CXX" ; \
echo "FC=$FC" ; \
echo "CMPLR_ROOT=$CMPLR_ROOT" ; \
echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" ; \
echo "CPATH=$CPATH" ; \
echo "INFOPATH=$INFOPATH" ; \
echo "INTEL_LICENSE_FILE=$INTEL_LICENSE_FILE" ; \
echo "LIBRARY_PATH=$LIBRARY_PATH" ; \
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" ; \
echo "ONEAPI_ROOT=$ONEAPI_ROOT" ; \
echo "PATH=$PATH" ; \
echo "TBBROOT=$TBBROOT" ; \
mkdir -p "/opt/vt/src" "/opt/vt/build/vt" ; \
git clone https://github.com/DARMA-tasking/vt /opt/vt/src ; \
cd /opt/vt/src ; \
bash ci/build_cpp.sh /opt/vt/src /opt/vt/build ; \
bash ci/test_cpp.sh /opt/vt/src /opt/vt/build ; \
bash ci/build_vt_sample.sh /opt/vt/src /opt/vt/build ;
rm -rf "/opt/vt/src" "/opt/vt/build"'
echo "Running ${CMD}"
docker run \
--name test-container \
-e CI="1" \
-e CMAKE_CXX_STANDARD="17" \
-e CMAKE_BUILD_TYPE="Release" \
${{ matrix.runner.image }} \
bash -c "$CMD"
exit $(docker container inspect --format '{{.State.ExitCode}}' test-container)
- name: Push Docker image to DockerHub Container Registry
if: ${{ success() && github.ref == 'refs/heads/master' }}
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }}
docker push ${{ matrix.runner.image }}
2 changes: 1 addition & 1 deletion .github/workflows/check-commit-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Check commit message format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/find-trailing-whitespace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Find Trailing Whitespace
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: DARMA-tasking/find-trailing-whitespace@master
with:
exclude: "sketches;lib"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
102 changes: 102 additions & 0 deletions ci/build-docker-image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""This script enable to build a docker image"""
import copy
import os
import sys

from util import resolve_conf
import yaml

class DockerBuilder:
"""Dockerfile generator class"""

def build(self, args: list):
"""Build an image using a given docker configuration fro the config file"""

raw_config: dict = {}
with open(os.path.dirname(__file__) + "/config.yaml", 'r', encoding="utf-8") as file:
raw_config = yaml.safe_load(file)

config = resolve_conf(copy.deepcopy(raw_config))
images = config.get("images")
setup = config.get("setup")

image_tag = None
if len(args) > 0:
image_tag = args[0]
if image_tag not in images.keys():
print(f"[error] Image not found {image_tag}.\n"
f"Available images:{(os.linesep + '- ')}"
f"{(os.linesep + '- ') . join(images.keys())}")
raise SystemExit(1)
else:
# Step 1: list platforms and their configurations
choices = {k: v for k, v in enumerate(images.keys())}
print("Choose image: ")
for i in choices:
image = images.get(choices[i])
setup_id = image.get("setup")
current_setup = setup.get(setup_id)
if current_setup is None:
raise RuntimeError(f"Invalid setup {setup_id}")
lbl = current_setup.get("label", image.get("setup"))
print(
f"\033[1m[{i}] {choices[i]}\033[0m\n"
f" \033[3;34m{lbl}\033[0m"
)
choice = input("> ")

image_tag = choices[int(choice)]

image = images.get(image_tag)
print("Selected image:")
print("---------------------------")
print(yaml.dump(image, default_flow_style=True))
print("---------------------------")

image_setup = setup.get(image.get("setup"))
dockerfile = image.get("dockerfile")
env = image_setup.get("env")

args = {
"ARCH": image.get("arch"),
"BASE": image.get("base"),
"SETUP_ID": image.get("setup")
}
# Env
supported_env_keys = [
# Compiler
"CC", "CXX", "FC",
# MPI
"MPICH_CC", "MPICH_CXX",
# Intel
"CMPLR_ROOT", "INTEL_LICENSE_FILE", "ONEAPI_ROOT", "TBBROOT",
"CMAKE_PREFIX_PATH", "CPATH", "INFOPATH", "LIBRARY_PATH", "LD_LIBRARY_PATH",
# Path
"PATH_PREFIX"
]
for env_key in supported_env_keys:
args[env_key] = env.get(env_key, '')

invalid_keys = list(key for key in env if not key in supported_env_keys)
if len(invalid_keys) > 0:
raise RuntimeError(f"warning: env keys not supported: {invalid_keys}")

space = ' '

escaped_args = { k:f'"{v}"' for (k,v) in args.items()}

cmd = ("docker build . "
f" --tag {image_tag}"
f" --file {os.path.dirname(__file__)}/docker/{dockerfile}"
f" {space.join([f'--build-arg {k}={v}' for (k,v) in escaped_args.items()])}"
# f" --cache-from={image_tag}" # use previously built image as a cache layer.
" --no-cache"
" --progress=plain"
)
print(cmd)
status = os.system(cmd)
exit(status)

# ENHANCEMENT: option to push to Dockerhub

DockerBuilder().build(sys.argv[1:])
86 changes: 86 additions & 0 deletions ci/build-matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""This script generates CI matrix file(s)"""
import copy
import os
import json
import re

from typing import Union
from util import resolve_conf
import yaml


class MatrixBuilder:
"""A class to generate matrix files for either Github Workflows or Azure Pipelines"""

def generate(self):
"""Generate a matrix of runners and inner environments to be used by CI pipelines"""

raw_config: dict = {}
with open(os.path.dirname(__file__) + "/config.yaml", 'r', encoding="utf-8") as file:
raw_config = yaml.safe_load(file)
config = resolve_conf(copy.deepcopy(raw_config))

for runner_type in ["github", "azure"]:
# Configured runner type could be an array if the 2 platforms are targetted.
# Useful for testing on both github and Azure.
runners = [runner for runner in config.get("runners")
if (
(runner.get("type") is str and runner.get("type") == runner_type) or
(runner_type in runner.get("type")) # list
)]
matrix: Union[dict,list] = []
for runner in runners:
matrix_item = {
"label": runner.get("label"),
("runs-on" if runner_type == "github" else "vmImage"): runner.get("runs-on")
}

# xor
assert( (runner.get("setup") is not None) != (runner.get("image") is not None))

if runner.get("setup") is not None:
setup = config.get("setup").get(runner.get("setup"))

if setup is None:
raise RuntimeError(f"Setup not found {runner.get('setup')}")
matrix_item["setup"] = runner.get("setup")
matrix_item["name"] = runner.get("setup")

elif runner.get("image") is not None:
image_name = (runner.get("image", {}).get("repository", "") + ":"
+ runner.get("image", {}).get("tag", ""))
image = config.get("images").get(image_name)

if image is None:
raise RuntimeError(f"Image not found {runner.get('image')}")

setup = config.get("setup").get(image.get("setup"))
if setup is None:
raise RuntimeError(f"Setup not found {runner.get('setup')}")

matrix_item["image"] = image.get("repository") + ":" + image.get("tag")

if matrix_item["label"] is None:
matrix_item["label"] = image.get("label")

matrix_item["name"] = image.get("tag")

if matrix_item["label"] is None:
matrix_item["label"] = setup.get("label")

matrix.append(matrix_item)

if runner_type == "azure":
matrix = { re.sub("[^0-9a-zA-Z]+", '-', v.get("name")):v for v in matrix }

data = json.dumps({
"_comment": "This file has been generated. Please do not edit",
"matrix": matrix}, indent=2)
with open(
os.path.dirname(__file__) + f"/shared/matrix/{runner_type}.json",
"w+",
encoding="utf-8"
) as file:
file.write(data)

MatrixBuilder().generate()
83 changes: 83 additions & 0 deletions ci/build-setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""This script generates setup scripts"""
import copy
import os
from typing import List, Union

from util import resolve_conf
import yaml

class SetupBuilder:
"""Setup files generator class"""

def __instructions(self, dep_id, args: Union[list, dict]) -> List[str]:
""" Generate shell instructions to setup a dependency"""

# basic command to run in setup script (bash)
if dep_id == "cmd":
assert isinstance(args, list)
return [ f"{' '.join(args)}" ]

call_args = []
env = []

# repeat instructions if args is an array of array
if args is not None and len(args) > 0:
if isinstance(args, list) and isinstance(args[0], list):
instructions = []
for (_, sub_args) in enumerate(args):
instructions.extend(self.__instructions(dep_id, sub_args))
return instructions

env = []
if isinstance(args, dict):
call_args = [ f"\"{a}\"" for a in args.get("args", [])]
env = [ f"{k}=\"{v}\"" for k, v in args.get("env", {}).items()]
else:
call_args = [ f"\"{a}\"" for a in args]
env = []

cmd = f"./{dep_id}.sh"
if len(call_args) > 0:
cmd = f"{cmd} {' '.join(call_args)}"
if len(env) > 0:
cmd = f"{' '.join(env)} {cmd}"

return [ cmd ]

def build(self):
"""Build setup scripts for each setup configuration defined in config"""

raw_config: dict = {}
with open(os.path.dirname(__file__) + "/config.yaml", 'r', encoding="utf-8") as file:
raw_config = yaml.safe_load(file)
config = resolve_conf(copy.deepcopy(raw_config))

setup = config.get("setup")
for (setup_id, setup_config) in setup.items():
# generate install instructions and install dependencies commands
instructions = []
downloads = []
for (dep_id, args) in setup_config.get("deps").items():
if dep_id != "cmd":
downloads.append(f"wget $WF_DEPS_URL/{dep_id}.sh")
instructions.extend(self.__instructions(dep_id, args))

setup_script = ""
with open(
os.path.dirname(__file__) + "/setup-template.sh",
'r',
encoding="utf-8"
) as file:
setup_script = file.read()
setup_script = setup_script.replace("%ENVIRONMENT_LABEL%", setup_config.get("label"))
setup_script = setup_script.replace("%DEPS_DOWNLOAD%", '\n '.join(downloads))
setup_script = setup_script.replace("%DEPS_INSTALL%", '\n'.join(instructions))

setup_filename = f"setup-{setup_id}.sh"
setup_filepath = os.path.join(os.path.dirname(__file__),
"shared", "scripts", setup_filename)

with open(setup_filepath, "w+", encoding="utf-8") as f:
f.write(setup_script)

SetupBuilder().build()
Loading
Loading