Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/run-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ jobs:
echo "::warning::Emulator was not ready within 400s (attempt ${attempt}/${attempts})."
docker logs localstack-main --tail 100 2>&1 || true
python -m localstack_cli.cli.main stop || true
# stop does not wait for Docker to remove the container, and a start that still finds it fails with
# 'container named "localstack-main" already exists'.
docker rm -f localstack-main >/dev/null 2>&1 || true
for _ in $(seq 1 30); do docker container inspect localstack-main >/dev/null 2>&1 || break; sleep 1; done
done
echo "::error::Emulator failed to become ready after ${attempts} attempts."
exit 1
Expand Down Expand Up @@ -307,6 +311,10 @@ jobs:
source .venv/bin/activate
echo "::warning::${MATRIX_NAME} failed once; retrying on a fresh emulator."
python -m localstack_cli.cli.main stop || true
# stop does not wait for Docker to remove the container, and a start that still finds it fails with
# 'container named "localstack-main" already exists'.
docker rm -f localstack-main >/dev/null 2>&1 || true
for _ in $(seq 1 30); do docker container inspect localstack-main >/dev/null 2>&1 || break; sleep 1; done
python -m localstack_cli.cli.main start -d
python -m localstack_cli.cli.main wait -t 600
make test SHARD="${SHARD}" SPLITS="${SPLITS}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
RESOURCE_GROUP_NAME="${PREFIX}-rg"
PROFILE_NAME="${PREFIX}-catalog-afd-${SUFFIX}"
ENDPOINT_NAME="${PREFIX}-catalog-${SUFFIX}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# accounts and the shared App Service plan are all inside it.
# =============================================================================

PREFIX='local'
PREFIX="${PREFIX:-local}"
RESOURCE_GROUP_NAME="${PREFIX}-rg"
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"

Expand Down
4 changes: 2 additions & 2 deletions samples/function-app-front-door/python/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
LOCATION='westeurope'
RESOURCE_GROUP_NAME="${PREFIX}-rg"
APP_SERVICE_PLAN_NAME="${PREFIX}-catalog-app-service-plan-${SUFFIX}"
Expand Down
4 changes: 2 additions & 2 deletions samples/function-app-front-door/python/scripts/validate.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
RESOURCE_GROUP_NAME="${PREFIX}-rg"
PRIMARY_FUNCTION_APP_NAME="${PREFIX}-catalog-primary-${SUFFIX}"
SECONDARY_FUNCTION_APP_NAME="${PREFIX}-catalog-secondary-${SUFFIX}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="$PREFIX-rg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
LOCATION='westeurope'
STORAGE_ACCOUNT_NAME="${PREFIX}storage${SUFFIX}"
FUNCTION_APP_NAME="${PREFIX}-functionapp-${SUFFIX}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
FILE_PATH="input.txt"
INPUT_CONTAINER_NAME="input"
OUTPUT_CONTAINER_NAME="output"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
LOCATION='northeurope'
STORAGE_ACCOUNT_NAME="${PREFIX}storage${SUFFIX}"
MANAGED_IDENTITY_NAME="${PREFIX}-identity-${SUFFIX}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
RESOURCE_GROUP_NAME="${PREFIX}-rg"
STORAGE_ACCOUNT_NAME="${PREFIX}storage${SUFFIX}"
INPUT_STORAGE_CONTAINER_NAME='input'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
LOCATION='westeurope'
MANAGED_IDENTITY_TYPE='UserAssigned' # SystemAssigned or UserAssigned
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
Expand Down
4 changes: 3 additions & 1 deletion samples/function-app-service-bus/dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ Found matching container [ls-local-func-test-tdkqjh]
Container [ls-local-func-test-tdkqjh] found successfully
Getting IP address for container [ls-local-func-test-tdkqjh]...
IP address [172.17.0.7] retrieved successfully for container [ls-local-func-test-tdkqjh]
Getting the host port mapped to internal port 80 in container [ls-local-func-test-tdkqjh]...
Getting the port the function app listens on in container [ls-local-func-test-tdkqjh]...
Function app listens on port [80] in container [ls-local-func-test-tdkqjh]
Getting the host port mapped to port [80] in container [ls-local-func-test-tdkqjh]...
Mapped host port [42330] retrieved successfully for container [ls-local-func-test-tdkqjh]
Calling HTTP trigger function to retrieve the last [100] greetings via hostname [babo-func-test.azurewebsites.azure.localhost.localstack.cloud:4566]...
{
Expand Down
4 changes: 2 additions & 2 deletions samples/function-app-service-bus/dotnet/bicep/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="${PREFIX}-rg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

# Usage: call-http-trigger.sh [function-app-name]
#
# The function app to call is the one named by the first argument, else by FUNCTION_APP_NAME, else the only function app in the
# subscription. Name it when several are deployed.

get_docker_container_name_by_prefix() {
local app_prefix="$1"
local container_name
Expand Down Expand Up @@ -65,10 +70,40 @@ get_docker_container_port_mapping() {
echo "$host_port"
}

get_docker_container_app_port() {
local container_name="$1"
local container_port

if [ -z "$container_name" ]; then
echo "Error: Container name is required" >&2
return 1
fi

# The emulator publishes the port the app listens on in its container, which is not necessarily 80:
# an app listens on the port its WEBSITES_PORT app setting names. Read it from the container.
container_port=$(docker inspect -f '{{range $port, $bindings := .NetworkSettings.Ports}}{{if $bindings}}{{println $port}}{{end}}{{end}}' "$container_name" | grep '/tcp$' | head -n 1)
container_port="${container_port%/tcp}"

if [ -z "$container_port" ]; then
echo "Error: Container [$container_name] publishes no TCP port" >&2
return 1
fi

echo "$container_port"
}

call_http_trigger_function() {
# Get the function app name
echo "Getting function app name..."
function_app_name=$(az functionapp list --query '[0].name' --output tsv)
# The function app to call: the one the caller named, else the only one in the subscription
function_app_name="$1"
if [ -z "$function_app_name" ]; then
echo "Getting the name of the only function app in the subscription..."
function_app_count=$(az functionapp list --query "length(@)" --output tsv)
if [ "$function_app_count" != "1" ]; then
echo "Error: Found [${function_app_count:-0}] function apps; name the one to call: $0 <function-app-name>"
exit 1
fi
function_app_name=$(az functionapp list --query "[0].name" --output tsv)
fi

if [ -n "$function_app_name" ]; then
echo "Function app [$function_app_name] successfully retrieved."
Expand All @@ -79,7 +114,7 @@ call_http_trigger_function() {

# Get the resource group name
echo "Getting resource group name for function app [$function_app_name]..."
resource_group_name=$(az functionapp list --query '[0].resourceGroup' --output tsv)
resource_group_name=$(az functionapp list --query "[?name=='${function_app_name}'] | [0].resourceGroup" --output tsv)

if [ -n "$resource_group_name" ]; then
echo "Resource group [$resource_group_name] successfully retrieved."
Expand Down Expand Up @@ -126,9 +161,19 @@ call_http_trigger_function() {
exit 1
fi

# Get the mapped host port for function app HTTP trigger (internal port 80)
echo "Getting the host port mapped to internal port 80 in container [$container_name]..."
host_port=$(get_docker_container_port_mapping "$container_name" "80")
# Get the port the function app listens on in its container
echo "Getting the port the function app listens on in container [$container_name]..."
container_port=$(get_docker_container_app_port "$container_name")
Comment thread
paolosalvatori marked this conversation as resolved.

if [ $? -eq 0 ] && [ -n "$container_port" ]; then
echo "Function app listens on port [$container_port] in container [$container_name]"
else
echo "Failed to get the port the function app listens on in container [$container_name]"
fi

# Get the host port mapped to it
echo "Getting the host port mapped to port [$container_port] in container [$container_name]..."
host_port=$(get_docker_container_port_mapping "$container_name" "$container_port")

if [ $? -eq 0 ] && [ -n "$host_port" ]; then
echo "Mapped host port [$host_port] retrieved successfully for container [$container_name]"
Expand All @@ -145,10 +190,10 @@ call_http_trigger_function() {
echo "Failed to retrieve function hostname"
fi

if [ -n "$container_ip" ]; then
if [ -n "$container_ip" ] && [ -n "$container_port" ]; then
# Call the GetGreetings HTTP trigger function to retrieve the last greetings via the container IP address
echo "Calling HTTP trigger function to retrieve the last [$greeting_count] greetings via container IP address [$container_ip]..."
curl --max-time 10 -s "http://$container_ip/api/greetings?count=$greeting_count" | jq
curl --max-time 10 -s "http://$container_ip:$container_port/api/greetings?count=$greeting_count" | jq
else
echo "Failed to retrieve container IP address"
fi
Expand All @@ -162,4 +207,4 @@ call_http_trigger_function() {
fi
}

call_http_trigger_function
call_http_trigger_function "${1:-${FUNCTION_APP_NAME:-}}"
4 changes: 2 additions & 2 deletions samples/function-app-service-bus/dotnet/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
LOCATION='westeurope'
RESOURCE_GROUP_NAME="${PREFIX}-rg"
LOG_ANALYTICS_NAME="${PREFIX}-log-analytics-${SUFFIX}"
Expand Down
4 changes: 2 additions & 2 deletions samples/function-app-service-bus/dotnet/scripts/validate.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
RESOURCE_GROUP_NAME="${PREFIX}-rg"
LOG_ANALYTICS_NAME="${PREFIX}-log-analytics-${SUFFIX}"
FUNCTION_APP_SUBNET_NSG_NAME="${PREFIX}-func-subnet-nsg-${SUFFIX}"
Expand Down
4 changes: 2 additions & 2 deletions samples/function-app-service-bus/dotnet/terraform/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
PREFIX='local'
SUFFIX='test'
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
LOCATION='westeurope'
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
ZIPFILE="functionapp.zip"
Expand Down
10 changes: 6 additions & 4 deletions samples/function-app-storage-http/dotnet/bicep/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Variables
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="local-func-storage-rg"
PREFIX="${PREFIX:-local}"
SUFFIX="${SUFFIX:-test}"
RESOURCE_GROUP_NAME="${PREFIX}-func-storage-rg"
LOCATION="westeurope"
VALIDATE_TEMPLATE=1
USE_WHAT_IF=0
Expand Down Expand Up @@ -45,7 +47,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
--template-file $TEMPLATE \
--parameters $PARAMETERS \
--parameters \
location=$LOCATION
location=$LOCATION prefix="$PREFIX" suffix="$SUFFIX"

if [[ $? == 0 ]]; then
echo "Bicep template [$TEMPLATE] validation succeeded"
Expand All @@ -61,7 +63,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
--template-file $TEMPLATE \
--parameters $PARAMETERS \
--parameters \
location=$LOCATION)
location=$LOCATION prefix="$PREFIX" suffix="$SUFFIX")

if [[ $? == 0 ]]; then
echo "Bicep template [$TEMPLATE] validation succeeded"
Expand All @@ -80,7 +82,7 @@ if DEPLOYMENT_OUTPUTS=$(az deployment group create \
--only-show-errors \
--template-file $TEMPLATE \
--parameters $PARAMETERS \
--parameters location=$LOCATION \
--parameters location=$LOCATION prefix="$PREFIX" suffix="$SUFFIX" \
--query 'properties.outputs' -o json); then
echo "Bicep template [$TEMPLATE] deployed successfully. Outputs:"
echo "$DEPLOYMENT_OUTPUTS" | jq .
Expand Down
Loading
Loading