Skip to content
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
16 changes: 11 additions & 5 deletions ctf/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def deploy(
remote: Annotated[
str, typer.Option("--remote", help="Incus remote to deploy to")
] = "local",
vm_remote: Annotated[
str | None,
typer.Option("--vm-remote", help="Incus remote for VM to be deployed to"),
] = None,
vm_project: Annotated[
str | None,
typer.Option("--vm-project", help="Incus project for VM to be deployed to"),
] = None,
redeploy: Annotated[
bool, typer.Option("--redeploy", help="Do not use. Use `ctf redeploy` instead.")
] = False,
Expand Down Expand Up @@ -76,6 +84,8 @@ def deploy(
exclude_tracks=exclude_tracks,
production=production,
remote=remote,
vm_remote=vm_remote,
vm_project=vm_project,
redeploy=redeploy,
)

Expand Down Expand Up @@ -355,11 +365,7 @@ def terraform_apply(
production: bool,
remote: str,
) -> set[Track]:
args = [
terraform_binary(),
"apply",
"-auto-approve",
]
args = [terraform_binary(), "apply", "-auto-approve"]

try:
subprocess.run(
Expand Down
10 changes: 10 additions & 0 deletions ctf/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def generate(
remote: Annotated[
str, typer.Option("--remote", help="Incus remote to deploy to")
] = "local",
vm_remote: Annotated[
str | None,
typer.Option("--vm-remote", help="Incus remote for VM to be deployed to"),
] = None,
vm_project: Annotated[
str | None,
typer.Option("--vm-project", help="Incus project for VM to be deployed to"),
] = None,
redeploy: Annotated[
bool, typer.Option("--redeploy", help="Do not use. Use `ctf redeploy` instead.")
] = False,
Expand Down Expand Up @@ -81,6 +89,8 @@ def generate(
production=production,
require_build_container=does_track_require_build_container(track),
has_virtual_machine=track_has_virtual_machine(track),
vm_project=vm_project,
vm_remote=vm_remote,
)
)
distinct_tracks = tmp_tracks
Expand Down
2 changes: 2 additions & 0 deletions ctf/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Track(BaseModel):
# Every object is unique on it's name
name: IncusStr
remote: str = "local"
vm_remote: str | None = None
vm_project: str | None = None
production: bool = False
require_build_container: bool = False
has_virtual_machine: bool = False
Expand Down
10 changes: 10 additions & 0 deletions ctf/redeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def redeploy(
remote: Annotated[
str, typer.Option("--remote", help="Incus remote to deploy to")
] = "local",
vm_remote: Annotated[
str | None,
typer.Option("--vm-remote", help="Incus remote for VM to be deployed to"),
] = None,
vm_project: Annotated[
str | None,
typer.Option("--vm-project", help="Incus project for VM to be deployed to"),
] = None,
force: Annotated[
bool,
typer.Option(
Expand Down Expand Up @@ -63,6 +71,8 @@ def redeploy(
tracks=tracks,
production=production,
remote=remote,
vm_remote=vm_remote,
vm_project=vm_project,
redeploy=True,
force=force,
skip_build=skip_build,
Expand Down
10 changes: 10 additions & 0 deletions ctf/templates/init/.deploy/common/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ variable "incus_remote" {
type = string
}

variable "incus_vm_remote" {
default = null
type = string
}

variable "incus_vm_project" {
default = null
type = string
}

variable "deploy" {
default = "dev"
type = string
Expand Down
20 changes: 18 additions & 2 deletions ctf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def add_tracks_to_terraform_modules(tracks: set[Track]):
already_deployed = {{ 'true' if track.already_deployed else 'false' }}
{% if track.production %}deploy = "production"{% endif %}
{% if track.remote %}incus_remote = "{{ track.remote }}"{% endif %}
{% if track.vm_remote %}incus_vm_remote = "{{ track.vm_remote }}"{% endif %}
{% if track.vm_project %}incus_vm_project = "{{ track.vm_project }}"{% endif %}
{% for ov in output_variables %}
{{ ov }} = module.common.{{ ov }}
{% endfor %}
Expand All @@ -154,7 +156,12 @@ def add_tracks_to_terraform_modules(tracks: set[Track]):
)


def create_terraform_modules_file(remote: str, production: bool = False):
def create_terraform_modules_file(
remote: str,
vm_remote: str | None = None,
vm_project: str | None = None,
production: bool = False,
):
with open(
file=os.path.join(find_ctf_root_directory(), ".deploy", "modules.tf"), mode="w+"
) as fd:
Expand All @@ -165,12 +172,21 @@ def create_terraform_modules_file(remote: str, production: bool = False):
source = "./common"
{% if production %}deploy = "production"{% endif %}
{% if remote %}incus_remote = "{{ remote }}"{% endif %}
{% if vm_remote %}incus_vm_remote = "{{ vm_remote }}"{% endif %}
{% if vm_project %}incus_vm_project = "{{ track.vm_project }}"{% endif %}
}

"""
)
)
fd.write(template.render(production=production, remote=remote))
fd.write(
template.render(
production=production,
remote=remote,
vm_remote=vm_remote,
vm_project=vm_project,
)
)


def get_common_modules_output_variables() -> set[str]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"typer==0.24.1",
"pydantic",
]
version = "4.5.2"
version = "4.6.0"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
Expand Down
Loading