Skip to content
Snippets Groups Projects
Commit 55543853 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added a simple hello world docker run test, docker name prefixes, CI runs docker. #14

parent 735b736c
No related branches found
No related tags found
1 merge request!5Added a simple hello world docker run test, docker name prefixes, CI runs docker. #14
Pipeline #111353 passed
......@@ -13,6 +13,9 @@ linting:
tests:
stage: test
variables:
NORTH_DOCKER_URL: ${CI_TARGET_DOCKER_ENV_URL}
NORTH_DOCKER_NAME_PREFIX: north-${CI_COMMIT_REF_NAME}
script:
- pip install -e .
- python -m pytest --cov=north -sv tests
......@@ -66,3 +66,15 @@ We recomment using vs-code. Here are vs-code settings that match the CI/CD linti
- `tests` - The [pytest](https://docs.pytest.org/) tests
- `setup.py` - Install the package with pip
- `docker` - All the docker files, scripts for creating/managing images, documentation
## Architecture
North is supposed to be run stand alone or as part of a NOMAD Oasis. Currently, we are
only targeting docker as the environment to run tools.
![with NOMAD Oasis on dev cluster](docs/assets/north-oasis-architecture.png)
- all containers that are run need to have an explicit name and this name has to be prefixed
with `north.config.docker_name_prefix`. This will allow us to target docker environments
that are used by other services.
docs/assets/north-oasis-architecture.png

144 KiB

......@@ -21,7 +21,7 @@ This config file is based on pydantic's
[settings management](https://pydantic-docs.helpmanual.io/usage/settings/).
'''
from typing import Dict, Any
from typing import Dict, Any, Optional
from pydantic import Field, BaseSettings
import yaml
import os.path
......@@ -29,6 +29,19 @@ import os
class NorthConfig(BaseSettings):
docker_url: Optional[str] = Field(
None,
description=(
'The URL to remotely (or locally) connect to the docker engine API. '
'If this is not given, the docker config will be read from the local env.'))
docker_name_prefix: str = Field(
'north',
description=(
'A prefix used for all container names. This can be used to avoid collisions '
'with other services using the same docker environment.')
)
secret: str = Field(
'this is a secret',
description='The secret for generating JWT tokens and other cryptographic material.')
......
......@@ -10,3 +10,4 @@ pytest-cov
types-PyYAML
types-requests
uvicorn
docker
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest
import docker
from docker import DockerClient
from north import config
@pytest.fixture(scope='session')
def docker_client() -> DockerClient:
'''
A session fixture for using docker. It will try to remove all left-over containers
after the test session.
'''
if config.docker_url:
docker_client = DockerClient(base_url=config.docker_url)
else:
docker_client = docker.from_env()
yield docker_client
# Remove old containrs that might be leftover from failing tests
docker_name_prefix_filter = dict(filters=dict(name=f'{config.docker_name_prefix}-.*'))
for container in docker_client.containers.list(**docker_name_prefix_filter):
container.stop()
for container in docker_client.containers.list(**docker_name_prefix_filter, all=True):
container.remove()
def assert_container(docker_client: DockerClient, name: str, remove: bool = False):
container = docker_client.containers.get(name)
assert container is not None
if remove:
container.remove()
def test_run_hello(docker_client: DockerClient):
name = f'{config.docker_name_prefix}-test-hello-world'
results = docker_client.containers.run('ubuntu:latest', 'echo hello world', name=name)
assert results == b'hello world\n', results
assert_container(docker_client, name, remove=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment