Skip to content

Commit 354882b

Browse files
committed
Started to work on the build container.
1 parent 5579efc commit 354882b

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

ctf/generate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
create_terraform_modules_file,
1212
find_ctf_root_directory,
1313
get_all_available_tracks,
14+
load_yaml_file,
1415
terraform_binary,
1516
validate_track_can_be_deployed,
1617
)
@@ -54,6 +55,20 @@ def generate(
5455
LOG.debug(msg=f"Found {len(distinct_tracks)} tracks")
5556
# Generate the Terraform modules file.
5657
create_terraform_modules_file(remote=remote, production=production)
58+
59+
for track in distinct_tracks:
60+
if os.path.isfile(
61+
build_yaml_file_path := os.path.join(
62+
find_ctf_root_directory(),
63+
"challenges",
64+
track,
65+
"ansible",
66+
"build.yaml",
67+
)
68+
) and (build_yaml_file := load_yaml_file(build_yaml_file_path)) and build_yaml_file:
69+
#TODO: set build for track
70+
pass
71+
5772
add_tracks_to_terraform_modules(
5873
tracks=distinct_tracks,
5974
remote=remote,

ctf/utils.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def add_tracks_to_terraform_modules(
8080
{% for track in tracks %}
8181
module "track-{{ track }}" {
8282
source = "../challenges/{{ track }}/terraform"
83+
{% if build_container %}
84+
build_container = true
85+
{% endif %}
8386
{% if production %}
8487
deploy = "production"
8588
{% endif %}
@@ -96,6 +99,7 @@ def add_tracks_to_terraform_modules(
9699
fd.write(
97100
template.render(
98101
tracks=tracks - get_terraform_tracks_from_modules(),
102+
build_container=build_container,
99103
production=production,
100104
remote=remote,
101105
)
@@ -145,6 +149,7 @@ def remove_tracks_from_terraform_modules(
145149
current_tracks = get_terraform_tracks_from_modules()
146150

147151
create_terraform_modules_file(remote=remote, production=production)
152+
# TODO: loosing the build_container
148153
add_tracks_to_terraform_modules(
149154
tracks=(current_tracks - tracks), remote=remote, production=production
150155
)
@@ -175,19 +180,16 @@ def remove_ctf_script_root_directory_from_path(path: str) -> str:
175180
return os.path.relpath(path=path, start=find_ctf_root_directory())
176181

177182

183+
def load_yaml_file(file: str) -> dict[str, Any]:
184+
return yaml.safe_load(stream=open(file, mode="r", encoding="utf-8"))
185+
186+
178187
def parse_track_yaml(track_name: str) -> dict[str, Any]:
179-
r = yaml.safe_load(
180-
stream=open(
181-
file=(
182-
p := os.path.join(
183-
find_ctf_root_directory(), "challenges", track_name, "track.yaml"
184-
)
185-
),
186-
mode="r",
187-
encoding="utf-8",
188+
r = load_yaml_file(
189+
p := os.path.join(
190+
find_ctf_root_directory(), "challenges", track_name, "track.yaml"
188191
)
189192
)
190-
191193
r["file_location"] = remove_ctf_script_root_directory_from_path(path=p)
192194

193195
return r
@@ -203,14 +205,11 @@ def parse_post_yamls(track_name: str) -> list[dict]:
203205
)
204206
):
205207
if post.endswith(".yml") or post.endswith(".yaml"):
206-
with open(
207-
file=os.path.join(posts_dir, post), mode="r", encoding="utf-8"
208-
) as f:
209-
r = post_data = yaml.safe_load(stream=f)
210-
r["file_location"] = remove_ctf_script_root_directory_from_path(
211-
path=posts_dir
212-
)
213-
posts.append(post_data)
208+
r = load_yaml_file(os.path.join(posts_dir, post))
209+
r["file_location"] = remove_ctf_script_root_directory_from_path(
210+
path=posts_dir
211+
)
212+
posts.append(r)
214213

215214
return posts
216215

0 commit comments

Comments
 (0)