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

runner.docker: Set docker.image setting to the latest build-* tag by default #168

Merged
merged 4 commits into from
Apr 5, 2022
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
10 changes: 6 additions & 4 deletions nextstrain/cli/command/check_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,20 @@ def run(opts: Options) -> int:

# Print overall status.
supported_runners = [
runner_name(runner)
runner
for runner, status_ok in runner_status.items()
if status_ok
]

if supported_runners:
print("All good! Supported Nextstrain environments:", ", ".join(map(success, supported_runners)))
print("All good! Supported Nextstrain environments:", ", ".join(success(runner_name(r)) for r in supported_runners))

if opts.set_default:
default_runner = supported_runners[0]
print()
print("Setting default environment to %s." % supported_runners[0])
config.set("core", "runner", supported_runners[0])
print("Setting default environment to %s." % runner_name(default_runner))
config.set("core", "runner", runner_name(default_runner))
default_runner.set_default_config()
else:
print(failure("No good. No support for any Nextstrain environment."))

Expand Down
20 changes: 19 additions & 1 deletion nextstrain/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,25 @@ def set(section: str, field: str, value: str, path: Path = CONFIG):
if section not in config:
config.add_section(section)

config.set(section, field, value)
config[section][field] = value

save(config, path)


def setdefault(section: str, field: str, value: str, path: Path = CONFIG):
"""
Set *field* in *section* to *value* in the config file at the given *path*,
if *field* doesn't already exist.

If *section* does not exist, it is automatically created.
"""
with write_lock():
config = load(path)

if section not in config:
config.add_section(section)

config[section].setdefault(field, value)

save(config, path)

Expand Down
7 changes: 7 additions & 0 deletions nextstrain/cli/runner/aws_batch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ def test_setup() -> RunnerTestResults:
]


def set_default_config() -> None:
"""
No-op.
"""
pass


def update() -> bool:
"""
No-op. Updating the AWS Batch environment isn't meaningful.
Expand Down
8 changes: 8 additions & 0 deletions nextstrain/cli/runner/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ def test_image_version():
]


def set_default_config() -> None:
"""
Sets ``docker.image``, if it isn't already set, to the latest ``build-*``
image.
"""
config.setdefault("docker", "image", latest_build_image(DEFAULT_IMAGE))


def update() -> bool:
"""
Pull down the latest Docker image build and prune old image versions.
Expand Down
7 changes: 7 additions & 0 deletions nextstrain/cli/runner/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def test_setup() -> RunnerTestResults:
]


def set_default_config() -> None:
"""
No-op.
"""
pass


def update() -> bool:
"""
No-op. Updating the native environment isn't reasonably possible.
Expand Down
3 changes: 3 additions & 0 deletions nextstrain/cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def run(opts: Options,
@staticmethod
def test_setup() -> Any: ...

@staticmethod
def set_default_config() -> None: ...

@staticmethod
def update() -> bool: ...

Expand Down