Skip to content

Commit 877d8b4

Browse files
committed
isolate registration commands
Signed-off-by: sk593 <[email protected]>
1 parent 0221ca2 commit 877d8b4

File tree

5 files changed

+203
-43
lines changed

5 files changed

+203
-43
lines changed

.github/build/test.mk

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,26 @@ ifndef RECIPE_PATH
4545
endif
4646
@./.github/scripts/build-terraform-recipe.sh "$(RECIPE_PATH)"
4747

48+
.PHONY: register-recipe
49+
register-recipe: ## Register a single recipe (requires RECIPE_PATH parameter)
50+
ifndef RECIPE_PATH
51+
$(error RECIPE_PATH parameter is required. Usage: make register-recipe RECIPE_PATH=<path-to-recipe-directory>)
52+
endif
53+
@./.github/scripts/register-recipe.sh "$(RECIPE_PATH)"
54+
55+
.PHONY: register
56+
register: ## Register all built recipes
57+
@./.github/scripts/register-all-recipes.sh "$(RESOURCE_TYPE_ROOT)"
58+
4859
.PHONY: test-recipe
49-
test-recipe: ## Test a single recipe by registering and deploying it (requires RECIPE_PATH parameter)
60+
test-recipe: ## Test a single recipe (assumes already registered, requires RECIPE_PATH parameter)
5061
ifndef RECIPE_PATH
5162
$(error RECIPE_PATH parameter is required. Usage: make test-recipe RECIPE_PATH=<path-to-recipe-directory>)
5263
endif
5364
@./.github/scripts/test-recipe.sh "$(RECIPE_PATH)"
5465

5566
.PHONY: test
56-
test: ## Run all recipe tests
67+
test: ## Run all recipe tests (assumes already registered)
5768
@./.github/scripts/test-all-recipes.sh "$(RESOURCE_TYPE_ROOT)"
5869

5970
.PHONY: list-resource-types
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# ------------------------------------------------------------
4+
# Copyright 2025 The Radius Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
# ------------------------------------------------------------
18+
19+
# =============================================================================
20+
# Register all Radius recipes in the repository by calling register-recipe.sh
21+
# for each discovered recipe directory. This should be run after building all
22+
# recipes but before testing them.
23+
# =============================================================================
24+
25+
set -euo pipefail
26+
27+
REPO_ROOT="${1:-$(pwd)}"
28+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
29+
30+
echo "==> Finding all recipes in $REPO_ROOT"
31+
32+
# Use while read loop for better compatibility (mapfile requires bash 4+)
33+
RECIPE_DIRS=()
34+
while IFS= read -r line; do
35+
RECIPE_DIRS+=("$line")
36+
done < <("$SCRIPT_DIR"/list-recipe-folders.sh "$REPO_ROOT")
37+
38+
if [[ ${#RECIPE_DIRS[@]} -eq 0 ]]; then
39+
echo "==> No recipes found"
40+
exit 0
41+
fi
42+
43+
echo "==> Found ${#RECIPE_DIRS[@]} recipe(s) to register"
44+
45+
FAILED_RECIPES=()
46+
PASSED_RECIPES=()
47+
48+
# Register each recipe
49+
for recipe_dir in "${RECIPE_DIRS[@]}"; do
50+
# Convert to relative path for cleaner output
51+
RELATIVE_PATH="${recipe_dir#$REPO_ROOT/}"
52+
echo ""
53+
echo "================================================"
54+
echo "Registering: $RELATIVE_PATH"
55+
echo "================================================"
56+
57+
if ./.github/scripts/register-recipe.sh "$recipe_dir"; then
58+
PASSED_RECIPES+=("$RELATIVE_PATH")
59+
else
60+
FAILED_RECIPES+=("$RELATIVE_PATH")
61+
fi
62+
done
63+
64+
# Print summary
65+
echo ""
66+
echo "================================================"
67+
echo "Registration Summary"
68+
echo "================================================"
69+
echo "Passed: ${#PASSED_RECIPES[@]}"
70+
echo "Failed: ${#FAILED_RECIPES[@]}"
71+
72+
if [[ ${#FAILED_RECIPES[@]} -gt 0 ]]; then
73+
echo ""
74+
echo "Failed recipe registrations:"
75+
for recipe in "${FAILED_RECIPES[@]}"; do
76+
echo " - $recipe"
77+
done
78+
exit 1
79+
fi
80+
81+
echo ""
82+
echo "==> All recipes registered successfully!"

.github/scripts/register-recipe.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
3+
# ------------------------------------------------------------
4+
# Copyright 2025 The Radius Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
# ------------------------------------------------------------
18+
19+
# =============================================================================
20+
# Register a single Radius recipe. Automatically detects whether the recipe
21+
# is Bicep or Terraform and registers it with the appropriate template path.
22+
#
23+
# Usage: ./register-recipe.sh <path-to-recipe-directory>
24+
# Example: ./register-recipe.sh Security/secrets/recipes/kubernetes/bicep
25+
# =============================================================================
26+
27+
set -euo pipefail
28+
29+
RECIPE_PATH="${1:-}"
30+
31+
if [[ -z "$RECIPE_PATH" ]]; then
32+
echo "Error: Recipe path is required"
33+
echo "Usage: $0 <path-to-recipe-directory>"
34+
exit 1
35+
fi
36+
37+
if [[ ! -d "$RECIPE_PATH" ]]; then
38+
echo "Error: Recipe directory not found: $RECIPE_PATH"
39+
exit 1
40+
fi
41+
42+
# Normalize path: convert absolute to relative for consistency
43+
RECIPE_PATH="$(realpath --relative-to="$(pwd)" "$RECIPE_PATH" 2>/dev/null || echo "$RECIPE_PATH")"
44+
RECIPE_PATH="${RECIPE_PATH#./}"
45+
46+
# Detect recipe type based on file presence
47+
if [[ -f "$RECIPE_PATH/main.tf" ]]; then
48+
RECIPE_TYPE="terraform"
49+
TEMPLATE_KIND="terraform"
50+
elif ls "$RECIPE_PATH"/*.bicep &>/dev/null; then
51+
RECIPE_TYPE="bicep"
52+
TEMPLATE_KIND="bicep"
53+
else
54+
echo "Error: Could not detect recipe type in $RECIPE_PATH"
55+
exit 1
56+
fi
57+
58+
echo "==> Registering $RECIPE_TYPE recipe at $RECIPE_PATH"
59+
60+
# Extract resource type from path (e.g., Security/secrets -> Radius.Security/secrets)
61+
RESOURCE_TYPE_PATH=$(echo "$RECIPE_PATH" | sed -E 's|/recipes/.*||')
62+
CATEGORY=$(basename "$(dirname "$RESOURCE_TYPE_PATH")")
63+
RESOURCE_NAME=$(basename "$RESOURCE_TYPE_PATH")
64+
RESOURCE_TYPE="Radius.$CATEGORY/$RESOURCE_NAME"
65+
66+
echo "==> Resource type: $RESOURCE_TYPE"
67+
68+
# Determine template path based on recipe type
69+
if [[ "$RECIPE_TYPE" == "bicep" ]]; then
70+
# For Bicep, use OCI registry path (match build-bicep-recipe.sh format)
71+
# Path format: localhost:5000/radius-recipes/{category}/{resourcename}/{platform}/{language}/{recipe-filename}
72+
# Find the .bicep file in the recipe directory
73+
BICEP_FILE=$(ls "$RECIPE_PATH"/*.bicep 2>/dev/null | head -n 1)
74+
RECIPE_FILENAME=$(basename "$BICEP_FILE" .bicep)
75+
RECIPE_NAME="$RECIPE_FILENAME"
76+
77+
# Extract platform and language from path (e.g., recipes/kubernetes/bicep -> kubernetes/bicep)
78+
RECIPES_SUBPATH="${RECIPE_PATH#*recipes/}"
79+
80+
# Build OCI path (use reciperegistry for in-cluster access)
81+
# Note: Build script pushes to localhost:5000 (which is port-forwarded to reciperegistry)
82+
# But Radius running in-cluster needs to pull from reciperegistry:5000
83+
CATEGORY_LOWER=$(echo "$CATEGORY" | tr '[:upper:]' '[:lower:]')
84+
RESOURCE_LOWER=$(echo "$RESOURCE_NAME" | tr '[:upper:]' '[:lower:]')
85+
TEMPLATE_PATH="reciperegistry:5000/radius-recipes/${CATEGORY_LOWER}/${RESOURCE_LOWER}/${RECIPES_SUBPATH}/${RECIPE_FILENAME}:latest"
86+
elif [[ "$RECIPE_TYPE" == "terraform" ]]; then
87+
# For Terraform, use HTTP module server with format: resourcename-platform.zip
88+
PLATFORM=$(basename "$(dirname "$RECIPE_PATH")")
89+
RECIPE_NAME="${RESOURCE_NAME}-${PLATFORM}"
90+
TEMPLATE_PATH="http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/${RECIPE_NAME}.zip"
91+
fi
92+
93+
echo "==> Registering recipe: $RECIPE_NAME"
94+
echo "==> Template path: $TEMPLATE_PATH"
95+
96+
rad recipe register default \
97+
--environment default \
98+
--resource-type "$RESOURCE_TYPE" \
99+
--template-kind "$TEMPLATE_KIND" \
100+
--template-path "$TEMPLATE_PATH" \
101+
--plain-http
102+
103+
echo "==> Recipe registered successfully"

.github/scripts/test-recipe.sh

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# ------------------------------------------------------------
1818

1919
# =============================================================================
20-
# Test a single Radius recipe by registering it, deploying a test app, and
21-
# cleaning up. Automatically detects whether the recipe is Bicep or Terraform.
20+
# Test a single Radius recipe by deploying a test app and cleaning up.
21+
# Assumes the recipe has already been registered.
2222
#
2323
# Usage: ./test-recipe.sh <path-to-recipe-directory>
2424
# Example: ./test-recipe.sh Security/secrets/recipes/kubernetes/bicep
@@ -46,10 +46,8 @@ RECIPE_PATH="${RECIPE_PATH#./}"
4646
# Detect recipe type based on file presence
4747
if [[ -f "$RECIPE_PATH/main.tf" ]]; then
4848
RECIPE_TYPE="terraform"
49-
TEMPLATE_KIND="terraform"
5049
elif ls "$RECIPE_PATH"/*.bicep &>/dev/null; then
5150
RECIPE_TYPE="bicep"
52-
TEMPLATE_KIND="bicep"
5351
else
5452
echo "Error: Could not detect recipe type in $RECIPE_PATH"
5553
exit 1
@@ -63,44 +61,13 @@ CATEGORY=$(basename "$(dirname "$RESOURCE_TYPE_PATH")")
6361
RESOURCE_NAME=$(basename "$RESOURCE_TYPE_PATH")
6462
RESOURCE_TYPE="Radius.$CATEGORY/$RESOURCE_NAME"
6563

64+
echo "==> Assuming recipe is already registered"
6665
echo "==> Resource type: $RESOURCE_TYPE"
6766

68-
# Determine template path based on recipe type
69-
if [[ "$RECIPE_TYPE" == "bicep" ]]; then
70-
# For Bicep, use OCI registry path (match build-bicep-recipe.sh format)
71-
# Path format: localhost:5000/radius-recipes/{category}/{resourcename}/{platform}/{language}/{recipe-filename}
72-
# Find the .bicep file in the recipe directory
73-
BICEP_FILE=$(ls "$RECIPE_PATH"/*.bicep 2>/dev/null | head -n 1)
74-
RECIPE_FILENAME=$(basename "$BICEP_FILE" .bicep)
75-
RECIPE_NAME="$RECIPE_FILENAME"
76-
77-
# Extract platform and language from path (e.g., recipes/kubernetes/bicep -> kubernetes/bicep)
78-
RECIPES_SUBPATH="${RECIPE_PATH#*recipes/}"
79-
80-
# Build OCI path (use reciperegistry for in-cluster access)
81-
CATEGORY_LOWER=$(echo "$CATEGORY" | tr '[:upper:]' '[:lower:]')
82-
RESOURCE_LOWER=$(echo "$RESOURCE_NAME" | tr '[:upper:]' '[:lower:]')
83-
TEMPLATE_PATH="reciperegistry:5000/radius-recipes/${CATEGORY_LOWER}/${RESOURCE_LOWER}/${RECIPES_SUBPATH}/${RECIPE_FILENAME}:latest"
84-
elif [[ "$RECIPE_TYPE" == "terraform" ]]; then
85-
# For Terraform, use HTTP module server with format: resourcename-platform.zip
86-
PLATFORM=$(basename "$(dirname "$RECIPE_PATH")")
87-
RECIPE_NAME="${RESOURCE_NAME}-${PLATFORM}"
88-
TEMPLATE_PATH="http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/${RECIPE_NAME}.zip"
89-
fi
90-
91-
echo "==> Registering recipe: $RECIPE_NAME"
92-
rad recipe register default \
93-
--environment default \
94-
--resource-type "$RESOURCE_TYPE" \
95-
--template-kind "$TEMPLATE_KIND" \
96-
--template-path "$TEMPLATE_PATH" \
97-
--plain-http
98-
9967
# Check if test file exists
10068
TEST_FILE="$RESOURCE_TYPE_PATH/test/app.bicep"
10169
if [[ ! -f "$TEST_FILE" ]]; then
10270
echo "==> No test file found at $TEST_FILE, skipping deployment test"
103-
rad recipe unregister default --resource-type "$RESOURCE_TYPE"
10471
exit 0
10572
fi
10673

@@ -117,12 +84,7 @@ if rad deploy "$TEST_FILE" --application "$APP_NAME" --environment default; then
11784
else
11885
echo "==> Test deployment failed"
11986
rad app delete "$APP_NAME" --yes 2>/dev/null || true
120-
rad recipe unregister default --resource-type "$RESOURCE_TYPE"
12187
exit 1
12288
fi
12389

124-
# Unregister the recipe
125-
echo "==> Unregistering recipe"
126-
rad recipe unregister default --resource-type "$RESOURCE_TYPE"
127-
12890
echo "==> Test completed successfully"

.github/workflows/validate-resource-types.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ jobs:
3737
run: make create-radius-cluster
3838
- name: Build
3939
run: make build
40+
- name: Register
41+
run: make register
4042
- name: Test
4143
run: make test

0 commit comments

Comments
 (0)