Skip to content

Commit

Permalink
Add the region flag to the imagebuilder component custom script downl…
Browse files Browse the repository at this point in the history
…oad action
  • Loading branch information
dreambeyondorange committed Sep 9, 2024
1 parent e647dc1 commit c226014
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cli/src/pcluster/imagebuilder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import yaml

from pcluster.aws.aws_api import AWSApi
from pcluster.aws.common import get_region
from pcluster.utils import get_url_scheme, yaml_load

ROOT_VOLUME_TYPE = "gp3"
Expand Down Expand Up @@ -53,6 +54,8 @@ def wrap_script_to_component(url):
with open(custom_component_script_template_file, "r", encoding="utf-8") as file:
custom_component_script_template = yaml_load(file)

# region_action = _generate_action("Region", "set -v\necho {0}\n".format(get_region()))
# custom_component_script_template["phases"][0]["steps"].insert(0, region_action)
script_url_action = _generate_action("ScriptUrl", "set -v\necho {0}\n".format(url))
custom_component_script_template["phases"][0]["steps"].insert(0, script_url_action)
script_scheme_action = _generate_action("ScriptUrlScheme", "set -v\necho {0}\n".format(scheme))
Expand Down
4 changes: 2 additions & 2 deletions cli/src/pcluster/resources/imagebuilder/custom_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ phases:
set -v
mkdir /tmp/parallelcluster/
temp_file=$(mktemp -p /tmp/parallelcluster/)
echo "${temp_file}"
echo "$temp_file"
# Download script
- name: Download
Expand All @@ -33,7 +33,7 @@ phases:
if [[ {{ build.ScriptUrlScheme.outputs.stdout }} == "https" ]]; then
curl --retry 3 -L -o {{ build.TempScript.outputs.stdout }} {{ build.ScriptUrl.outputs.stdout }}
elif [[ {{ build.ScriptUrlScheme.outputs.stdout }} == "s3" ]]; then
aws s3 cp {{ build.ScriptUrl.outputs.stdout }} {{ build.TempScript.outputs.stdout }}
aws s3 cp {{ build.ScriptUrl.outputs.stdout }} {{ build.TempScript.outputs.stdout }} --region ${AWS::Region}
else
echo "Invalid script url"
exit {{ build.Fail.outputs.stdout }}
Expand Down
3 changes: 1 addition & 2 deletions cli/src/pcluster/templates/imagebuilder_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from pcluster import imagebuilder_utils, utils
from pcluster.aws.aws_api import AWSApi
from pcluster.aws.common import get_region
from pcluster.config.common import BaseTag
from pcluster.config.imagebuilder_config import ImageBuilderConfig, ImageBuilderExtraChefAttributes, Volume
from pcluster.constants import (
Expand Down Expand Up @@ -979,7 +978,7 @@ def _add_custom_components(self, components, policy_statements, components_resou
description="This component is custom component for script, script name is {0}, script url is "
"{1}".format(component_script_name, custom_component.value),
platform="Linux",
data=wrap_script_to_component(custom_component.value),
data=Fn.sub(wrap_script_to_component(custom_component.value)),
)
components.append(
imagebuilder.CfnImageRecipe.ComponentConfigurationProperty(component_arn=Fn.ref(component_id))
Expand Down
10 changes: 10 additions & 0 deletions tests/integration-tests/configs/mini.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test-suites:
createami:
test_createami.py::test_build_image_custom_components:
dimensions:
- instances:
- m6g.xlarge
oss:
- alinux2
regions:
- cn-northwest-1

0 comments on commit c226014

Please sign in to comment.