rcds.challenge — Challenges

class rcds.ChallengeLoader(project: rcds.Project)[source]

Class for loading a Challenge within the context of a rcds.Project

load(root: Path)[source]

Load a challenge by path

The challenge must be within the project associated with this loader.

Parameters:

root (pathlib.Path) – Path to challenge root

class rcds.Challenge(project: Project, root: Path, config: dict)[source]

A challenge within a given rcds.Project

This class is not meant to be constructed directly, use a ChallengeLoader to load a challenge.

create_transaction() AssetManagerTransaction[source]

Get a transaction to update this challenge’s assets

get_relative_path() Path[source]

Utiity function to get this challenge’s path relative to the project root

register_asset_source(do_add: Callable[[AssetManagerTransaction], None]) None[source]

Register a function to add assets to the transaction for this challenge.

render_description() str[source]

Render the challenge’s description template to a string

rcds.challenge.config - Config loading

class rcds.challenge.config.ConfigLoader(project: Project)[source]

Object that manages loading challenge config files

check_config(config_file: Path) Tuple[Dict[str, Any] | None, Iterable[ValidationError] | None][source]

Load and validate a config file, returning any errors encountered.

If the config file is valid, the tuple returned contains the loaded config as the first element, and the second element is None. Otherwise, the second element is an iterable of errors that occurred during validation

This method wraps parse_config().

Parameters:

config_file (pathlib.Path) – The challenge config to load

load_config(config_file: Path) Dict[str, Any][source]

Loads a config file, or throw an exception if it is not valid

This method wraps check_config(), and throws the first error returned if there are any errors.

Parameters:

config_file (pathlib.Path) – The challenge config to load

Returns:

The loaded config

parse_config(config_file: Path) Iterable[ValidationError | Dict[str, Any]][source]

Load and validate a config file, returning both the config and any errors encountered.

Parameters:

config_file (pathlib.Path) – The challenge config to load

Returns:

Iterable containing any errors (all instances of rcds.errors.ValidationError) and the parsed config. The config will always be last.

exception rcds.challenge.config.InvalidFlagError[source]
exception rcds.challenge.config.TargetFileNotFoundError(message: str, target: Path)[source]
exception rcds.challenge.config.TargetNotFoundError[source]

rcds.challenge.docker - Docker containers

rcds.challenge.docker.get_context_files(root: Path) Iterator[Path][source]

Generate a list of all files in the build context of the specified Dockerfile

Parameters:

root (pathlib.Path) – Path to the containing directory of the Dockerfile to analyze

rcds.challenge.docker.generate_sum(root: Path) str[source]

Generate a checksum of all files in the build context of the specified directory

Parameters:

root (pathlib.Path) – Path to the containing directory of the Dockerfile to analyze

class rcds.challenge.docker.ContainerManager(challenge: Challenge)[source]

Object managing all containers defined by a given rcds.Challenge

__init__(challenge: Challenge)[source]
Parameters:

challenge (rcds.Challenge) – The challenge that this ContainerManager belongs to

class rcds.challenge.docker.Container(*, container_manager: ContainerManager, name: str)[source]

A single container

IS_BUILDABLE: bool = False
build(force: bool = False) None[source]

Build the challenge if applicable and necessary.

For challenges that are not buildable (IS_BUILDABLE is False), this method is a no-op

Parameters:

force (bool) – Force a rebuild of this container even if it is up-to-date

get_full_tag() str[source]

Get the full image tag (e.g. k8s.gcr.io/etcd:3.4.3-0) for this container

Returns:

The image tag

is_built() bool[source]

If the container is buildable (IS_BUILDABLE is True), this method returns whether or not the container is already built (and up-to-date). For non-buildable containers, this method always returns True.

Returns:

Whether or not the container is built

class rcds.challenge.docker.BuildableContainer(**kwargs)[source]

A container that is built from source

IS_BUILDABLE: bool = True
build(force: bool = False) None[source]

Build the challenge if applicable and necessary.

For challenges that are not buildable (IS_BUILDABLE is False), this method is a no-op

Parameters:

force (bool) – Force a rebuild of this container even if it is up-to-date

get_full_tag() str[source]

Get the full image tag (e.g. k8s.gcr.io/etcd:3.4.3-0) for this container

Returns:

The image tag

is_built() bool[source]

Checks if a container built with a build context with a matching hash exists, either locally or remotely.

Returns:

Whether or not the image was found