From 0ca7ca328f8a88bc2ca5b1b5a42c0a308ce943a1 Mon Sep 17 00:00:00 2001 From: Marc Olivier Bergeron Date: Sat, 9 Aug 2025 22:48:10 -0400 Subject: [PATCH 1/3] Fixed the issue where there is no QA or support for a track (yet) which would forbid deploying the track. Fixed the issue where the monitoring would be on 'main-site' in the track.yaml template. Set a path dynamically instead of hardcoded dot-dot-slashes. Fixed an issue where the network zone would not get deleted when destroying the whole CTF. --- ctf/deploy.py | 2 +- ctf/destroy.py | 9 ++++++++- ctf/templates/main.tf.j2 | 4 ++-- ctf/templates/track.yaml.j2 | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ctf/deploy.py b/ctf/deploy.py index 5d32445..ba95944 100644 --- a/ctf/deploy.py +++ b/ctf/deploy.py @@ -230,7 +230,7 @@ def run_ansible_playbook(remote: str, production: bool, track: str, path: str) - LOG.info(msg=f"Running common yaml with ansible for track {track}...") ansible_args = [ "ansible-playbook", - "../../../.deploy/common.yaml", + os.path.join(CTF_ROOT_DIRECTORY, ".deploy", "common.yaml"), "-i", "inventory", ] + extra_args diff --git a/ctf/destroy.py b/ctf/destroy.py index 52e004f..5861bc0 100644 --- a/ctf/destroy.py +++ b/ctf/destroy.py @@ -57,6 +57,8 @@ def destroy( terraform_tracks = get_terraform_tracks_from_modules() + total_deployed_tracks = len(terraform_tracks) + r = ( subprocess.run( args=["incus", "project", "get-current"], @@ -110,7 +112,11 @@ def destroy( terraform_binary(), "destroy", "-auto-approve", - *[f"-target=module.track-{track}" for track in terraform_tracks], + *( + [] # If every track needs to be destroyed, destroy everything including the network zone as well. + if total_deployed_tracks == len(terraform_tracks) + else [f"-target=module.track-{track}" for track in terraform_tracks] + ), ], cwd=os.path.join(CTF_ROOT_DIRECTORY, ".deploy"), check=False, @@ -194,6 +200,7 @@ def destroy( capture_output=True, env=ENV, ) + remove_tracks_from_terraform_modules( tracks=terraform_tracks, remote=remote, diff --git a/ctf/templates/main.tf.j2 b/ctf/templates/main.tf.j2 index 07b617e..430e5bf 100644 --- a/ctf/templates/main.tf.j2 +++ b/ctf/templates/main.tf.j2 @@ -8,8 +8,8 @@ resource "incus_project" "this" { config = { "features.images" = "false" "user.contacts.dev" = join(", ", local.track.contacts.dev) - "user.contacts.qa" = join(", ", local.track.contacts.qa) - "user.contacts.support" = join(", ", local.track.contacts.support) + "user.contacts.qa" = length(local.track.contacts.qa) > 0 ? join(", ", local.track.contacts.qa) : null + "user.contacts.support" = length(local.track.contacts.support) > 0 ? join(", ", local.track.contacts.support) : null } } diff --git a/ctf/templates/track.yaml.j2 b/ctf/templates/track.yaml.j2 index 3e42155..ca521d1 100644 --- a/ctf/templates/track.yaml.j2 +++ b/ctf/templates/track.yaml.j2 @@ -39,7 +39,7 @@ services: # Each service name must be unique for a given instance (container/VM). - name: {% if data.template == "python-service" %}HTTP-5000{% else %}HTTP{% endif %} # Name of the container or VM - instance: main-site + instance: {{ data.name }} # The IPv6 address was randomly generated from the MAC Address (hwaddr) and the subnets defined in main.tf. # If you need other machines, you can choose another MAC Address and get the IPv6 from the MAC AND the IPv6 subnet ({{ data.ipv6_subnet }}) at https://eui64-calc.princelle.org/ address: '{{ data.full_ipv6_address }}' From 379aeba7bc4cc1f9a13d8fb6188df494552b6fe5 Mon Sep 17 00:00:00 2001 From: Marc Olivier Bergeron Date: Sat, 9 Aug 2025 23:30:38 -0400 Subject: [PATCH 2/3] There should not be anything deployed at the very end because everything is destroyed after every run (sub jobs). This was an unintended bug that was fixed in this branch. --- .github/workflows/tests.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f605b20..d93f74b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,10 +47,10 @@ jobs: - name: Copy CTF files run: | - mkdir -p test-ctf/challenges - cp -r ./challenges test-ctf/ - ls -al test-ctf/ - ls -al test-ctf/challenges + mkdir -p test-ctf/challenges + cp -r ./challenges test-ctf/ + ls -al test-ctf/ + ls -al test-ctf/challenges - name: ctf version working-directory: test-ctf @@ -196,10 +196,3 @@ jobs: ctf redeploy --production --tracks mock-track-python-service [ "$(incus list --all-projects -cn -fcsv | wc -l)" -eq 2 ] || exit 1 ctf destroy --force - - - name: Check deployment results - run: | - incus project list - incus network zone record list ctf - incus network list --all-projects - incus list --all-projects From f87db81ad91d09e3c3aeb4a9c4ac02e81f1716a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milio=20Gonzalez?= Date: Sun, 10 Aug 2025 12:32:38 -0400 Subject: [PATCH 3/3] bump version to 3.0.0 (because of breaking change in destroy.py) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 415d5ee..506f628 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "setuptools", "typer==0.16.0", ] -version = "2.1.0" +version = "3.0.0" classifiers = [ "Programming Language :: Python :: 3", "Operating System :: OS Independent",