Skip to content

Commit

Permalink
Build docker image before test
Browse files Browse the repository at this point in the history
Before we were not building so the test docker-compose
was using the remote image and not the source we were testing.
  • Loading branch information
sbidoul committed Nov 30, 2024
1 parent 8377700 commit cd72d66
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,58 @@

HERE = Path(__file__).parent


@pytest.fixture(scope="session", autouse=True)
def compose_build():
cmd = ["docker", "compose", "build"]
if "ODOOVERSION" in os.environ:
cmd.extend(["--build-arg", f"ODOOVERSION={os.environ['ODOOVERSION']}"])
if "PYTHONTAG" in os.environ:
cmd.extend(["--build-arg", f"PYTHONTAG={os.environ['PYTHONTAG']}"])
if "DISTRO" in os.environ:
cmd.extend(["--build-arg", f"DISTRO={os.environ['DISTRO']}"])
if "BUILDER" in os.environ:
cmd.extend(["--builder", os.environ["BUILDER"]])
subprocess.run(cmd, check=True, cwd=HERE)
# These must match the default in tests/Dockerfile
DEFAULT_TEST_IMAGE = "ghcr.io/acsone/odoo-bedrock"
DEFAULT_TEST_ODOOVERSION = "16.0"
DEFAULT_TEST_PYTHONTAG = "py310"
DEFAULT_TEST_DISTRO = "jammy"


@pytest.fixture(scope="session")
def odoo_version():
# /!\ Default must be the same as the ODOOVERSION build arg in test Dockerfile
return os.environ.get("ODOOVERSION", "16.0")
return os.environ.get("ODOOVERSION", DEFAULT_TEST_ODOOVERSION)


@pytest.fixture(scope="session")
def python_tag():
return os.environ.get("PYTHONTAG", DEFAULT_TEST_PYTHONTAG)


@pytest.fixture(scope="session")
def distro():
return os.environ.get("DISTRO", DEFAULT_TEST_DISTRO)


@pytest.fixture(scope="session", autouse=True)
def compose_build(odoo_version, python_tag, distro):
docker_build_options = [
"--build-arg",
f"ODOOVERSION={odoo_version}",
"--build-arg",
f"PYTHONTAG={python_tag}",
"--build-arg",
f"DISTRO={distro}",
]
if "BUILDER" in os.environ:
docker_build_options.extend(["--builder", os.environ["BUILDER"]])
cmd = [
"docker",
"build",
"--file",
f"Dockerfile-{odoo_version}",
"--tag",
f"{DEFAULT_TEST_IMAGE}:{odoo_version}-{python_tag}-{distro}-latest",
*docker_build_options,
".",
]
subprocess.run(cmd, check=True, cwd=HERE.parent)
cmd = [
"docker",
"compose",
"build",
*docker_build_options,
]
subprocess.run(cmd, check=True, cwd=HERE)


@pytest.fixture(scope="session")
Expand Down

0 comments on commit cd72d66

Please sign in to comment.