Skip to content

Commit 2176c3b

Browse files
committed
test: build diracx containers from source in integration tests
Replace --diracx-dist-dir with --diracx-src-dir which uses docker-compose build instead of injecting wheels via the entrypoint. Also fix stale /opt/conda and micromamba references from the old container images.
1 parent c4e89ab commit 2176c3b

3 files changed

Lines changed: 55 additions & 23 deletions

File tree

docs/source/DeveloperGuide/CodeTesting/index.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,11 @@ To deactivate a service from being used with DiracX, you can add it in `integrat
360360
"WorkloadManagement/JobMonitoring",
361361
]
362362
363-
By setting `TEST_DIRACX=Yes` only, it will take the last version of DiracX by default. If you want to provide your own, you have to build your DiracX project, and provide the `dist` folder path when calling `prepare-client`. This path has to be absolute.
363+
By setting `TEST_DIRACX=Yes` only, it will take the last version of DiracX by default. If you want to test against a local DiracX checkout, provide the source directory path when calling `prepare-environment`. This will build the DiracX container images from source and build wheels for the DIRAC containers.
364364

365365
.. code-block:: bash
366366
367-
./integration-tests.py prepare-client TEST_DIRACX=Yes --diracx-dist-dir my-dist-folder/
368-
369-
It will then mount your dist folder into DIRAC and DiracX (in `/diracx_sources`) to install the right dependencies.
367+
./integration-tests.py prepare-environment TEST_DIRACX=Yes --diracx-src-dir /path/to/diracx/
370368
371369
For MacOS, there are two bugs that can be fixed.
372370

integration_tests.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ def create(
175175
flags: Optional[list[str]] = typer.Argument(None),
176176
editable: Optional[bool] = None,
177177
extra_module: Optional[list[str]] = None,
178-
diracx_dist_dir: Optional[str] = None,
178+
diracx_src_dir: Optional[str] = None,
179179
release_var: Optional[str] = None,
180180
run_server_tests: bool = True,
181181
run_client_tests: bool = True,
182182
run_pilot_tests: bool = True,
183183
):
184184
"""Start a local instance of the integration tests"""
185-
prepare_environment(flags, editable, extra_module, diracx_dist_dir, release_var)
185+
prepare_environment(flags, editable, extra_module, diracx_src_dir, release_var)
186186
install_server()
187187
install_client()
188188
install_pilot()
@@ -230,7 +230,7 @@ def prepare_environment(
230230
flags: Optional[list[str]] = typer.Argument(None),
231231
editable: Optional[bool] = None,
232232
extra_module: Optional[list[str]] = None,
233-
diracx_dist_dir: Optional[str] = None,
233+
diracx_src_dir: Optional[str] = None,
234234
release_var: Optional[str] = None,
235235
):
236236
"""Prepare the local environment for installing DIRAC."""
@@ -277,7 +277,7 @@ def prepare_environment(
277277
extra_services = list(chain(*[config["extra-services"] for config in module_configs.values()]))
278278

279279
typer.secho("Running docker compose to create containers", fg=c.GREEN)
280-
with _gen_docker_compose(modules, diracx_dist_dir=diracx_dist_dir) as docker_compose_fn:
280+
with _gen_docker_compose(modules, diracx_src_dir=diracx_src_dir) as docker_compose_fn:
281281
subprocess.run(
282282
[*DOCKER_COMPOSE_CMD, "-f", docker_compose_fn, "up", "-d", "dirac-server", "dirac-client", "dirac-pilot"]
283283
+ extra_services,
@@ -374,7 +374,7 @@ def prepare_environment(
374374
typer.secho("Running docker compose to create DiracX containers", fg=c.GREEN)
375375
typer.secho(f"Will leave a folder behind: {docker_compose_fn_final}", fg=c.YELLOW)
376376

377-
with _gen_docker_compose(modules, diracx_dist_dir=diracx_dist_dir) as docker_compose_fn:
377+
with _gen_docker_compose(modules, diracx_src_dir=diracx_src_dir) as docker_compose_fn:
378378
# We cannot use the temporary directory created in the context manager because
379379
# we don't stay in the contect manager (Popen)
380380
# So we need something that outlives it.
@@ -591,7 +591,7 @@ class TestExit(typer.Exit):
591591

592592

593593
@contextmanager
594-
def _gen_docker_compose(modules, *, diracx_dist_dir=None):
594+
def _gen_docker_compose(modules, *, diracx_src_dir=None):
595595
# Load the docker compose configuration and mount the necessary volumes
596596
input_fn = Path(__file__).parent / "tests/CI/docker-compose.yml"
597597
docker_compose = yaml.safe_load(input_fn.read_text())
@@ -607,23 +607,50 @@ def _gen_docker_compose(modules, *, diracx_dist_dir=None):
607607
docker_compose["services"]["diracx-wait-for-db"]["volumes"].extend(volumes[:])
608608

609609
module_configs = _load_module_configs(modules)
610-
if diracx_dist_dir is not None:
611-
for container_name in [
612-
"dirac-client",
613-
"dirac-pilot",
614-
"dirac-server",
615-
"diracx-init-cs",
616-
"diracx-wait-for-db",
617-
"diracx-init-db",
618-
"diracx",
619-
]:
610+
if diracx_src_dir is not None:
611+
diracx_src_dir = str(Path(diracx_src_dir).absolute())
612+
613+
# Build wheels from the diracx source for the DIRAC containers
614+
diracx_wheel_dir = Path(tempfile.mkdtemp(prefix="diracx-wheels-"))
615+
typer.secho(f"Building diracx wheels in {diracx_wheel_dir}", fg=c.GREEN)
616+
subprocess.run(
617+
[
618+
sys.executable,
619+
"-m",
620+
"pip",
621+
"wheel",
622+
"--no-deps",
623+
f"--wheel-dir={diracx_wheel_dir}",
624+
*[f"{diracx_src_dir}/diracx-{pkg}" for pkg in ["core", "client", "cli"]],
625+
],
626+
check=True,
627+
)
628+
629+
# Mount wheels into DIRAC containers so installDIRACX can find them
630+
for container_name in ["dirac-client", "dirac-pilot", "dirac-server"]:
620631
docker_compose["services"][container_name].setdefault("volumes", []).append(
621-
f"{diracx_dist_dir}:/diracx_sources"
632+
f"{diracx_wheel_dir}:/diracx_sources"
622633
)
623634
docker_compose["services"][container_name].setdefault("environment", []).append(
624635
"DIRACX_CUSTOM_SOURCE_PREFIXES=/diracx_sources"
625636
)
626637

638+
# Build diracx container images from source instead of pulling pre-built ones
639+
diracx_build_services = {
640+
"container-services": ["diracx", "diracx-init-keystore", "diracx-init-db"],
641+
"container-client": ["diracx-init-cs"],
642+
}
643+
for pixi_env, container_names in diracx_build_services.items():
644+
for container_name in container_names:
645+
service = docker_compose["services"][container_name]
646+
del service["image"]
647+
service.pop("pull_policy", None)
648+
service["build"] = {
649+
"context": diracx_src_dir,
650+
"dockerfile": "containers/Dockerfile",
651+
"args": {"PIXI_ENV": pixi_env},
652+
}
653+
627654
# Add any extension services
628655
for module_name, module_configs in module_configs.items():
629656
for service_name, service_config in module_configs["extra-services"].items():

tests/CI/docker-compose.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,14 @@ services:
255255
environment:
256256
- DIRACX_DB_URL_AUTHDB=mysql+aiomysql://Dirac:Dirac@mysql/DiracXAuthDB
257257
entrypoint: |
258-
/entrypoint.sh bash -xc 'micromamba install --yes -c conda-forge mysql-client && mysql -h mysql -u root --password=password -e "CREATE DATABASE DiracXAuthDB" && mysql -h mysql -u root --password=password -e "GRANT SELECT,INSERT,LOCK TABLES,UPDATE,DELETE,CREATE,DROP,ALTER,REFERENCES,CREATE VIEW,SHOW VIEW,INDEX,TRIGGER,ALTER ROUTINE,CREATE ROUTINE ON DiracXAuthDB.* TO Dirac@'"'"'%'"'"'" && python -m diracx.db init-sql && python -m diracx.db init-os'
258+
/entrypoint.sh bash -xc 'python -c "
259+
import pymysql
260+
db = pymysql.connect(host=\"mysql\", user=\"root\", password=\"password\")
261+
c = db.cursor()
262+
c.execute(\"CREATE DATABASE DiracXAuthDB\")
263+
c.execute(\"GRANT SELECT,INSERT,LOCK TABLES,UPDATE,DELETE,CREATE,DROP,ALTER,REFERENCES,CREATE VIEW,SHOW VIEW,INDEX,TRIGGER,ALTER ROUTINE,CREATE ROUTINE ON DiracXAuthDB.* TO Dirac@\\\"%%\\\"\")
264+
db.commit()
265+
" && python -m diracx.db init-sql && python -m diracx.db init-os'
259266
pull_policy: always
260267

261268
diracx:
@@ -300,7 +307,7 @@ services:
300307
/entrypoint.sh bash -xc 'uvicorn --factory diracx.routers:create_app --host=0.0.0.0'
301308
302309
healthcheck:
303-
test: ["CMD", "/opt/conda/bin/python", "-c", 'import requests; requests.get("http://localhost:8000/.well-known/openid-configuration").raise_for_status()']
310+
test: ["CMD", "python", "-c", 'import requests; requests.get("http://localhost:8000/.well-known/openid-configuration").raise_for_status()']
304311
interval: 5s
305312
timeout: 2s
306313
retries: 15

0 commit comments

Comments
 (0)