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

Fix doit tests #458

Merged
merged 8 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ The build system will attempt to detect the local architecture and automatically
All commands `build`, `tests`, and `up` will use the locally detected platform and use a version tag based on the state of the local git repository.
However, you can also specify a custom platform or version with the `--platform` and `--version` parameters, example: `doit build --arch=arm64 --version=my-version`.

You can specify target image variants to build with `--target`, example: `doit build --target base --target lab`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify the code, you can now only provide a single --target argument (and we now automatically validate that you choose one of the four valid images. If no target is specified, then all images are built by default.

By default, all image variants are build. You can specify a single target image variant to build with `-t/--target`, example: `doit build --target base`.

### Run automated tests

To run tests, first build the images as described in the previous section.
Then run the automated tests with `doit tests`.
Then run the automated tests for a given image with `doit tests --target <base|base-with-services|lab|full-stack>`.

Tip: The [continuous integration](#continuous-integration) workflow will build, release (at `ghcr.io/aiidalab/*:pr-###`), and test images for all pull requests into the default branch.

For manual testing, you can start the images with `doit up`, however we recommend to use [aiidalab-launch](#deploy-aiidalab-with-aiidalab-launch) to setup a production-ready local deployment.
For manual testing, you can start the images with `doit up --target full-stack`, however we recommend to use [aiidalab-launch](#deploy-aiidalab-with-aiidalab-launch) to setup a production-ready local deployment.

### Continuous integration

Images are built for `linux/amd64` and `linux/arm64` during continuous integration for all pull requests into the default branch and pushed to the GitHub Container Registry (ghcr.io) with tags `ghcr.io/aiidalab/*:pr-###`.
You can run automated or manual tests against those images by specifying the registry and version for both the `up` and `tests` commands, example: `doit up --registry=ghcr.io/ --version=pr-123`.
You can run automated or manual tests against those images by specifying the registry and version for both the `up` and `tests` commands, example: `doit tests --registry=ghcr.io/ --version=pr-123`.

### Creating a release

Expand Down
99 changes: 77 additions & 22 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@

_ARCH_MAPPING = {
"x86_64": "amd64",
"amd64": "amd64",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what podman returns on Fedora 39 at least.

"aarch64": "arm64",
}

ARCH = _ARCH_MAPPING.get(_DOCKER_ARCHITECTURE)

if ARCH is None:
raise RuntimeError(
f"Unsupported architecture {ARCH} on platform {platform.system()}."
print(
f"Unsupported architecture {_DOCKER_ARCHITECTURE} on platform {platform.system()}."
)
exit(1)

_REGISTRY_PARAM = {
"name": "registry",
"short": "r",
"long": "registry",
"type": str,
"default": "",
"help": "Specify the docker image registry.",
"help": "Specify the docker image registry (including the trailing slash).",
}

_ORGANIZATION_PARAM = {
Expand Down Expand Up @@ -63,14 +65,45 @@
}

_TARGET_PARAM = {
"name": "targets",
"long": "targets",
"name": "target",
"long": "target",
"short": "t",
"type": list,
"default": [],
"type": str,
"choices": (
("base", ""),
("base-with-services", ""),
("lab", ""),
("full-stack", ""),
),
# If the target is not provided, all images will be build
"default": "",
"help": "Specify the target to build.",
}

_AIIDALAB_PORT_PARAM = {
"name": "port",
"short": "p",
"long": "port",
"type": int,
"default": 8888,
"help": "Specify the AiiDAlab host port.",
}

_COMPOSE_CMD_PARAM = {
"name": "compose-command",
"long": "compose-cmd",
"type": str,
"default": "docker compose",
"help": "Specify alternative docker compose command (e.g. podman-compose).",
}


def target_required(target: str) -> bool:
if not target:
print("ERROR: Target image must be provided with '-t/--target' option")
return False
return True


def task_build():
"""Build all docker images."""
Expand Down Expand Up @@ -114,38 +147,60 @@ def generate_version_override(
def task_tests():
"""Run tests with pytest."""

# TODO: This currently does not work!
# https://github.com/aiidalab/aiidalab-docker-stack/issues/451
return {
"actions": ["REGISTRY=%(registry)s VERSION=:%(version)s pytest -v"],
"params": [_REGISTRY_PARAM, _VERSION_PARAM, _TARGET_PARAM],
"actions": [
target_required,
"AIIDALAB_PORT=%(port)i REGISTRY=%(registry)s VERSION=:%(version)s "
"pytest -s --target %(target)s --compose-cmd='%(compose-command)s' %(pytest-opts)s",
],
"params": [
_TARGET_PARAM,
_AIIDALAB_PORT_PARAM,
_REGISTRY_PARAM,
_VERSION_PARAM,
{
"name": "pytest-opts",
"long": "pytest-opts",
"type": str,
"default": "",
"help": "Extra options to pytest command.",
},
_COMPOSE_CMD_PARAM,
],
"verbosity": 2,
}


def task_up():
"""Start AiiDAlab server for testing."""
"""Start AiiDAlab server."""

return {
"actions": [
target_required,
"AIIDALAB_PORT=%(port)i REGISTRY=%(registry)s VERSION=:%(version)s "
"docker-compose up --detach"
"%(compose-command)s -f stack/docker-compose.%(target)s.yml up --detach",
],
"params": [
{
"name": "port",
"short": "p",
"long": "port",
"type": int,
"default": 8888,
"help": "Specify the AiiDAlab host port.",
},
_TARGET_PARAM,
_AIIDALAB_PORT_PARAM,
_REGISTRY_PARAM,
_VERSION_PARAM,
_COMPOSE_CMD_PARAM,
],
"verbosity": 2,
}


def task_down():
"""Stop AiiDAlab server."""
return {"actions": ["docker-compose down"], "verbosity": 2}
return {
"actions": [
target_required,
"%(compose-command)s -f stack/docker-compose.%(target)s.yml down",
],
"params": [
_TARGET_PARAM,
_COMPOSE_CMD_PARAM,
],
"verbosity": 2,
}
2 changes: 1 addition & 1 deletion stack/docker-compose.base-with-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
volumes:
- aiidalab-home-folder:/home/jovyan
ports:
- "0.0.0.0:${AIIDALAB_PORT:-}:8888"
- "0.0.0.0:${AIIDALAB_PORT:-8888}:8888"

volumes:
aiidalab-home-folder:
6 changes: 3 additions & 3 deletions stack/docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: '3.4'
services:

database:
image: postgres:12.3
image: docker.io/postgres:12.3
environment:
POSTGRES_USER: pguser
POSTGRES_PASSWORD: password
Expand All @@ -17,7 +17,7 @@ services:
retries: 10

messaging:
image: rabbitmq:3.8.3-management
image: docker.io/rabbitmq:3.8.3-management
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
Expand All @@ -40,7 +40,7 @@ services:
messaging:
condition: service_started
ports:
- "0.0.0.0:${AIIDALAB_PORT:-}:8888"
- "0.0.0.0:${AIIDALAB_PORT:-8888}:8888"

volumes:
aiida-postgres-db:
Expand Down
2 changes: 1 addition & 1 deletion stack/docker-compose.full-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
volumes:
- aiidalab-home-folder:/home/jovyan
ports:
- "0.0.0.0:${AIIDALAB_PORT:-}:8888"
- "0.0.0.0:${AIIDALAB_PORT:-8888}:8888"

volumes:
aiidalab-home-folder:
6 changes: 3 additions & 3 deletions stack/docker-compose.lab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: '3.4'
services:

database:
image: postgres:12.3
image: docker.io/postgres:12.3
environment:
POSTGRES_USER: pguser
POSTGRES_PASSWORD: password
Expand All @@ -17,7 +17,7 @@ services:
retries: 10

messaging:
image: rabbitmq:3.8.3-management
image: docker.io/rabbitmq:3.8.3-management
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
Expand All @@ -40,7 +40,7 @@ services:
messaging:
condition: service_started
ports:
- "0.0.0.0:${AIIDALAB_PORT:-}:8888"
- "0.0.0.0:${AIIDALAB_PORT:-8888}:8888"

volumes:
aiida-postgres-db:
Expand Down
21 changes: 18 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@ def pytest_addoption(parser):
help="target (image name) of the docker-compose file to use.",
type=target_checker,
)
parser.addoption(
"--compose-cmd",
action="store",
required=False,
default="docker compose",
help="Specify custom docker compose command (e.g. 'podman-compose').",
)


@pytest.fixture(scope="session")
def target(pytestconfig):
return pytestconfig.getoption("target")


@pytest.fixture(scope="session")
def docker_compose_command(pytestconfig) -> str:
return pytestconfig.getoption("compose_cmd")


@pytest.fixture(scope="session")
def docker_compose_file(pytestconfig):
target = pytestconfig.getoption("target")
Expand Down Expand Up @@ -76,9 +88,12 @@ def execute(command, user=None, **kwargs):
return execute


@pytest.fixture
def nb_user(aiidalab_exec):
return aiidalab_exec("bash -c 'echo \"${NB_USER}\"'").strip()
@pytest.fixture(scope="session")
def nb_user():
# Let's make this simpler and return a constant value to speed up the tests,
# otherwise we'd need to execute the following command for every test.
# return aiidalab_exec("bash -c 'echo \"${NB_USER}\"'").strip()
return "jovyan"


@pytest.fixture
Expand Down