-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Allow filtering by platform on workflow call #209
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
base: main
Are you sure you want to change the base?
Changes from all commits
86fd88c
01189e0
ec97de0
7da00f0
9caed2b
c4f7d6b
6830720
5b32741
41617b3
22cfed2
0245f6e
4c766ba
c433a65
510e7ea
80af883
c6f791d
34b1143
ef67359
6e4ceaf
4a26bba
2bbff3e
8e859b0
8ef5aca
6ee9055
518e8c1
42b8043
23ce2ec
7c9989a
ed1ff9b
dc14942
afeaef3
fa9a2c5
40d4b10
310e329
7faa23f
457ea1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,9 @@ def __init__(self, **kwargs) -> None: | |
| self._workflow_run_url = self.vars.get('workflow_run_url', None) | ||
| self._service_path = self.vars.get('service_path', '') | ||
| self._flavors = self.vars.get('flavors', 'default') | ||
| self._platforms = self.validate_platforms( | ||
| self.vars.get('platforms', '*') | ||
| ) | ||
| self._container_structure_filename = self.vars.get( | ||
| 'container_structure_filename', None | ||
| ) | ||
|
|
@@ -123,6 +126,10 @@ def workflow_run_url(self): | |
| def flavors(self): | ||
| return self._flavors | ||
|
|
||
| @property | ||
| def platforms(self): | ||
| return self._platforms | ||
|
|
||
| @property | ||
| def service_path(self): | ||
| return self._service_path | ||
|
|
@@ -251,7 +258,6 @@ def filter_flavors(self): | |
|
|
||
| self._flavors = final_flavors_list | ||
|
|
||
|
|
||
| def filter_auto_build(self): | ||
| logger.info( | ||
| 'Publishing all flavors with auto build enabled:', | ||
|
|
@@ -359,6 +365,33 @@ async def compile_images_for_all_flavors(self): | |
| dockerfile, extra_registries,\ | ||
| extra_tags, platforms = self.get_flavor_data(flavor) | ||
|
|
||
| platforms_to_build = [] | ||
| if self.check_if_build_all_platforms(): | ||
| platforms_to_build = platforms | ||
| else: | ||
| allowed_platforms = self.platforms.replace(' ', '').split(',') | ||
| normalized_allowed_platforms = { | ||
| p.replace('linux/', '') for p in allowed_platforms | ||
| } | ||
|
|
||
| # Get the platforms to build for this flavor by checking the intersection | ||
| platforms_to_build = [ | ||
| platform for platform in platforms | ||
| if platform.replace('linux/', '') in normalized_allowed_platforms | ||
| ] | ||
|
|
||
| logger.info( | ||
| f"Building flavor {flavor} for platforms: {platforms_to_build}" | ||
| ) | ||
|
|
||
| if len(platforms_to_build) == 0: | ||
| print( | ||
| f"::warning title=BuildImages Warning::" | ||
| f"No matching platforms to build for flavor {flavor}. " | ||
| f"Skipping..." | ||
| ) | ||
| continue | ||
|
|
||
| # Set the build arguments for the current flavor | ||
| build_args_list = [ | ||
| dagger.BuildArg(name=key, value=value) | ||
|
|
@@ -424,7 +457,7 @@ async def compile_images_for_all_flavors(self): | |
| secrets, | ||
| dockerfile, | ||
| image, | ||
| platforms | ||
| platforms_to_build | ||
| ) | ||
|
|
||
| image_tag = image.split(":")[1] | ||
|
|
@@ -444,12 +477,43 @@ async def compile_images_for_all_flavors(self): | |
| "workflow_run_url": self.workflow_run_url | ||
| }) | ||
|
|
||
| if len(results_list) == 0: | ||
| print( | ||
| f"::warning title=BuildImages Warning::" | ||
| f"No images were built. " | ||
| f"Please check the workflow filters are correct." | ||
| ) | ||
juanjosevazquezgil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| yaml.default_flow_style = False | ||
| with open(os.path.join("/tmp", self.output_results), "w") as f: | ||
| yaml.dump(results_list, f) | ||
|
|
||
| return results_list | ||
|
|
||
| def check_if_build_all_platforms(self): | ||
| return self.platforms.replace(' ', '') == '*' | ||
|
|
||
|
Comment on lines
+493
to
+495
|
||
| def validate_platforms(self, platforms): | ||
| trimmed_platforms = platforms.replace(' ', '') | ||
| if trimmed_platforms == '*': | ||
| return trimmed_platforms | ||
|
|
||
| platform_list = trimmed_platforms.split(',') | ||
|
|
||
| invalid_platforms = [] | ||
| for platform in platform_list: | ||
| if not re.match(r'^(linux/)?(amd64|arm64)$', platform): | ||
| invalid_platforms.append(platform) | ||
|
|
||
| if invalid_platforms: | ||
| raise ValueError( | ||
| f"Invalid platform(s): {', '.join(invalid_platforms)}. " | ||
| "Valid platforms are: linux/amd64, linux/arm64, amd64, arm64, " | ||
| "or '*'. Whitespace around comma-separated entries is ignored." | ||
| ) | ||
|
|
||
| return trimmed_platforms | ||
|
|
||
| def get_flavor_data(self, flavor): | ||
| flavor_data = self.config.images[flavor] | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.