diff --git a/.github/actions/smoke-test/action.yml b/.github/actions/smoke-test/action.yml index b175013..c11beb3 100644 --- a/.github/actions/smoke-test/action.yml +++ b/.github/actions/smoke-test/action.yml @@ -4,6 +4,9 @@ inputs: template: description: 'Template to test' required: true + runtime-version: + description: 'Runtime version to test (defaults to the template default)' + required: false runs: using: composite @@ -11,9 +14,15 @@ runs: - name: Build template id: build_template shell: bash - run: ${{ github.action_path }}/build.sh ${{ inputs.template }} + env: + TEMPLATE_ID: ${{ inputs.template }} + RUNTIME_VERSION: ${{ inputs.runtime-version }} + run: bash "${{ github.action_path }}/build.sh" "${TEMPLATE_ID}" - name: Test template id: test_template shell: bash - run: ${{ github.action_path }}/test.sh ${{ inputs.template }} + env: + TEMPLATE_ID: ${{ inputs.template }} + RUNTIME_VERSION: ${{ inputs.runtime-version }} + run: bash "${{ github.action_path }}/test.sh" "${TEMPLATE_ID}" diff --git a/.github/actions/smoke-test/build.sh b/.github/actions/smoke-test/build.sh index 3ae037d..2eba216 100755 --- a/.github/actions/smoke-test/build.sh +++ b/.github/actions/smoke-test/build.sh @@ -15,7 +15,10 @@ npm install -g @devcontainers/cli PREBUILD_DIR="prebuild/${TEMPLATE_ID}" if [ -d "${PREBUILD_DIR}" ] ; then RUNTIME_OPTION=$(jq -r '.options | keys[] | select(. != "azureFunctionsCliVersion")' "src/${TEMPLATE_ID}/devcontainer-template.json") - RUNTIME_VERSION=$(jq -r ".options | .${RUNTIME_OPTION} | .default" "src/${TEMPLATE_ID}/devcontainer-template.json") + RUNTIME_VERSION=${RUNTIME_VERSION:-$(jq -r ".options | .${RUNTIME_OPTION} | .default" "src/${TEMPLATE_ID}/devcontainer-template.json")} + jq -e --arg option "${RUNTIME_OPTION}" --arg version "${RUNTIME_VERSION}" \ + '.options[$option].proposals | index($version) != null' \ + "src/${TEMPLATE_ID}/devcontainer-template.json" > /dev/null PREBUILD_IMAGE="ghcr.io/shibayan/devcontainers/${TEMPLATE_ID}-base:${RUNTIME_VERSION}-noble" if [ -z "${RUNTIME_OPTION}" ] || [ -z "${RUNTIME_VERSION}" ] || [ "${RUNTIME_VERSION}" = "null" ] ; then @@ -42,6 +45,9 @@ if [ "${OPTION_PROPERTY}" != "" ] && [ "${OPTION_PROPERTY}" != "null" ] ; then do OPTION_KEY="\${templateOption:$OPTION}" OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json) + if [ "${OPTION}" = "${RUNTIME_OPTION}" ]; then + OPTION_VALUE="${RUNTIME_VERSION}" + fi if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then echo "Template '${TEMPLATE_ID}' is missing a default value for option '${OPTION}'" diff --git a/.github/actions/smoke-test/test.sh b/.github/actions/smoke-test/test.sh index 5de1a2c..6b53184 100755 --- a/.github/actions/smoke-test/test.sh +++ b/.github/actions/smoke-test/test.sh @@ -6,8 +6,21 @@ SRC_DIR="/tmp/${TEMPLATE_ID}" echo "Running Smoke Test" ID_LABEL="test-container=${TEMPLATE_ID}" -devcontainer exec --workspace-folder "${SRC_DIR}" --id-label ${ID_LABEL} /bin/sh -c 'set -e && if [ -f "test-project/test.sh" ]; then cd test-project && if [ "$(id -u)" = "0" ]; then chmod +x test.sh; else sudo chmod +x test.sh; fi && ./test.sh; else ls -a; fi' +cleanup() { + status=$? + trap - EXIT + container=$(docker ps -aq --filter "label=${ID_LABEL}" | head -n1) || true + if [ -n "${container}" ]; then + project=$(docker inspect --format '{{ index .Config.Labels "com.docker.compose.project" }}' "${container}") || true + if [ -n "${project}" ]; then + docker compose --project-name "${project}" -f "${SRC_DIR}/.devcontainer/docker-compose.yml" down --volumes || true + fi + fi + rm -rf "${SRC_DIR}" + exit "${status}" +} +trap cleanup EXIT -# Clean up -docker rm -f $(docker container ls -f "label=${ID_LABEL}" -q) -rm -rf "${SRC_DIR}" +devcontainer exec --workspace-folder "${SRC_DIR}" --id-label "${ID_LABEL}" \ + --remote-env "EXPECTED_RUNTIME_VERSION=${RUNTIME_VERSION:-}" \ + /bin/bash -c 'set -e; cd test-project; bash test.sh' diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index eee43a7..cb3679f 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -6,8 +6,10 @@ jobs: detect-changes: runs-on: ubuntu-latest outputs: - templates: ${{ steps.filter.outputs.changes }} + configs: ${{ steps.matrix.outputs.configs }} steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 id: filter with: @@ -49,18 +51,40 @@ jobs: - test/test-utils/** - .github/workflows/test-pr.yml + - name: Generate runtime test matrix + id: matrix + env: + TEMPLATES: ${{ steps.filter.outputs.changes }} + shell: bash + run: | + configs=$( + while IFS= read -r template; do + jq -c --arg template "${template}" ' + .options | to_entries[] + | select(.key != "azureFunctionsCliVersion") + | .value.proposals[] as $runtime + | { template: $template, runtime: $runtime } + ' "src/${template}/devcontainer-template.json" + done < <(jq -r '.[]' <<< "${TEMPLATES}") | jq -sc '.' + ) + echo "configs=${configs}" >> "${GITHUB_OUTPUT}" + test: needs: [detect-changes] + if: ${{ needs.detect-changes.outputs.configs != '[]' }} runs-on: ${{ matrix.os }} + timeout-minutes: 45 strategy: + fail-fast: false matrix: - templates: ${{ fromJSON(needs.detect-changes.outputs.templates) }} + config: ${{ fromJSON(needs.detect-changes.outputs.configs) }} os: [ubuntu-24.04, ubuntu-24.04-arm] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - name: Smoke test for '${{ matrix.templates }}' + - name: Smoke test for '${{ matrix.config.template }}' (${{ matrix.config.runtime }}) id: smoke_test uses: ./.github/actions/smoke-test with: - template: "${{ matrix.templates }}" + template: "${{ matrix.config.template }}" + runtime-version: "${{ matrix.config.runtime }}" diff --git a/README.md b/README.md index a96334e..aebb188 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,41 @@ A collection of [Dev Container Templates](https://containers.dev/implementors/te | Template | Languages / Runtimes | Supported Versions | | --- | --- | --- | | [Azure Functions (.NET)](./src/azure-functions-dotnet) | C#, .NET | 8.0 / 9.0 / 10.0 | -| [Azure Functions (Go)](./src/azure-functions-go) | Go | 1.24 / 1.25 / 1.26 | +| [Azure Functions (Go)](./src/azure-functions-go) | Go | 1.26 / 1.27 | | [Azure Functions (Java)](./src/azure-functions-java) | Java | 8 / 11 / 17 / 21 / 25 | -| [Azure Functions (Node.js)](./src/azure-functions-node) | JavaScript, TypeScript | 20 / 22 / 24 | +| [Azure Functions (Node.js)](./src/azure-functions-node) | JavaScript, TypeScript | 22 / 24 | | [Azure Functions (PowerShell)](./src/azure-functions-powershell) | PowerShell | 7.4 / 7.6 | -| [Azure Functions (Python)](./src/azure-functions-python) | Python | 3.10 / 3.11 / 3.12 / 3.13 / 3.14 | +| [Azure Functions (Python)](./src/azure-functions-python) | Python | 3.11 / 3.12 / 3.13 / 3.14 | -> All templates include the Azure Functions Core Tools (version selectable, default: `latest`). +> All templates include the Azure Functions Core Tools (version selectable, default: `latest`, except Python which defaults to `4.13.0`). All language runtimes are provided through separate `*-base` prebuilt Ubuntu 24.04 images for both AMD64 and ARM64. The templates add the selected Azure Functions Core Tools version when the development container is created. +## Runtime support and hosting plans + +The default runtimes are .NET 10, Go 1.27, Java 21, Node.js 24, PowerShell 7.6, and Python 3.13. Core Tools 4.16.0 is also available as an explicit version option. + +The Python template temporarily pins Core Tools to **4.13.0** on both architectures. Core Tools 4.14.0 through 4.16.0 ship incomplete Python workers on Linux ARM64 and fail during startup. See [upstream issue #5772](https://github.com/Azure/azure-functions-core-tools/issues/5772). Restore `latest` only after a fixed release passes the Python HTTP smoke tests on both architectures. + +As of November 3, 2026, .NET 8, .NET 9, and PowerShell 7.4 remain available for existing projects, but their support ends on **November 10, 2026**. Plan to move to .NET 10 (isolated worker) or PowerShell 7.6 before that date. Azure Functions in-process model support also ends on November 10, 2026. Node.js 20, Python 3.10, and Go 1.24/1.25 are no longer offered for new containers because upstream support has ended. Previously published image tags remain available for existing users. + +Local runtime availability does not imply support on every Azure hosting plan: + +| Runtime | Azure hosting restriction | +| --- | --- | +| .NET 10 | Not supported on Linux Consumption; .NET 9 is the last supported version on that plan. | +| Java 25 | Not supported on Linux Consumption; Java 21 is the last supported version on that plan. | +| Node.js 24 | Not supported on Linux Consumption; Node.js 22 is the last supported version on that plan. | +| PowerShell 7.6 | Not supported on Linux Consumption; migrate to Flex Consumption before upgrading from 7.4. | +| Python 3.13 / 3.14 | Not supported on Linux Consumption; Python 3.12 is the last supported version on that plan. | +| Go | Generally available on Flex Consumption. | + +Check the [Azure Functions language support table](https://learn.microsoft.com/azure/azure-functions/functions-versions#languages), [.NET support policy](https://dotnet.microsoft.com/platform/support/policy/dotnet-core), and [Go release policy](https://go.dev/doc/devel/release#policy) before choosing a deployment target. Core Tools 5 remains a preview and is not an explicit template option. + +## Validation + +Pull request CI builds each proposed runtime version for changed templates on both AMD64 and ARM64. It checks the installed tools, generates a language-specific HTTP function, starts the Functions host against the Azurite sidecar, and verifies the HTTP response. The tests use local emulated storage and do not deploy Azure resources. + ## Usage 1. Open the Command Palette in VS Code and select **Dev Containers: Add Dev Container Configuration Files...** diff --git a/prebuild/azure-functions-powershell/.devcontainer/Dockerfile b/prebuild/azure-functions-powershell/.devcontainer/Dockerfile index 7fcd6fc..db92068 100644 --- a/prebuild/azure-functions-powershell/.devcontainer/Dockerfile +++ b/prebuild/azure-functions-powershell/.devcontainer/Dockerfile @@ -1 +1,6 @@ -FROM mcr.microsoft.com/devcontainers/dotnet:8.0-noble +ARG RUNTIME_VERSION + +FROM mcr.microsoft.com/devcontainers/dotnet:8.0-noble AS powershell-7.4 +FROM mcr.microsoft.com/devcontainers/dotnet:10.0-noble AS powershell-7.6 + +FROM powershell-${RUNTIME_VERSION} diff --git a/prebuild/azure-functions-powershell/.devcontainer/devcontainer.json b/prebuild/azure-functions-powershell/.devcontainer/devcontainer.json index aaea938..66b1602 100644 --- a/prebuild/azure-functions-powershell/.devcontainer/devcontainer.json +++ b/prebuild/azure-functions-powershell/.devcontainer/devcontainer.json @@ -1,7 +1,10 @@ { "name": "Azure Functions (PowerShell) Prebuild", "build": { - "dockerfile": "Dockerfile" + "dockerfile": "Dockerfile", + "args": { + "RUNTIME_VERSION": "${localEnv:RUNTIME_VERSION}" + } }, "features": { "ghcr.io/devcontainers/features/powershell:1": { diff --git a/src/azure-functions-dotnet/devcontainer-template.json b/src/azure-functions-dotnet/devcontainer-template.json index a40598d..80f9f68 100644 --- a/src/azure-functions-dotnet/devcontainer-template.json +++ b/src/azure-functions-dotnet/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "azure-functions-dotnet", - "version": "2.0.7", + "version": "2.1.0", "name": "Azure Functions (.NET)", "description": "Develop C# and .NET based Azure Functions. Includes all needed SDKs, extensions, and dependencies.", "documentationURL": "https://github.com/shibayan/devcontainers/tree/master/src/azure-functions-dotnet", @@ -22,6 +22,7 @@ "description": "Azure Functions CLI version:", "proposals": [ "latest", + "4.16.0", "4.12.0", "4.11.0", "4.10.0", diff --git a/src/azure-functions-go/README.md b/src/azure-functions-go/README.md index 4313da5..e858460 100644 --- a/src/azure-functions-go/README.md +++ b/src/azure-functions-go/README.md @@ -7,7 +7,7 @@ Develop Go based Azure Functions. Includes all needed SDKs, extensions, and depe | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| -| goVersion | Go version: | string | 1.24 | +| goVersion | Go version: | string | 1.27 | | azureFunctionsCliVersion | Azure Functions CLI version: | string | latest | diff --git a/src/azure-functions-go/devcontainer-template.json b/src/azure-functions-go/devcontainer-template.json index 34e2e77..b0bfdd6 100644 --- a/src/azure-functions-go/devcontainer-template.json +++ b/src/azure-functions-go/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "azure-functions-go", - "version": "1.0.2", + "version": "1.1.0", "name": "Azure Functions (Go)", "description": "Develop Go based Azure Functions. Includes all needed SDKs, extensions, and dependencies.", "documentationURL": "https://github.com/shibayan/devcontainers/tree/master/src/azure-functions-go", @@ -11,17 +11,17 @@ "type": "string", "description": "Go version:", "proposals": [ - "1.26", - "1.25", - "1.24" + "1.27", + "1.26" ], - "default": "1.24" + "default": "1.27" }, "azureFunctionsCliVersion": { "type": "string", "description": "Azure Functions CLI version:", "proposals": [ "latest", + "4.16.0", "4.12.0" ], "default": "latest" diff --git a/src/azure-functions-java/devcontainer-template.json b/src/azure-functions-java/devcontainer-template.json index 24ecb9f..6c455da 100644 --- a/src/azure-functions-java/devcontainer-template.json +++ b/src/azure-functions-java/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "azure-functions-java", - "version": "2.0.7", + "version": "2.1.0", "name": "Azure Functions (Java)", "description": "Develop Java based Azure Functions. Includes all needed SDKs, extensions, and dependencies.", "documentationURL": "https://github.com/shibayan/devcontainers/tree/master/src/azure-functions-java", @@ -24,6 +24,7 @@ "description": "Azure Functions CLI version:", "proposals": [ "latest", + "4.16.0", "4.12.0", "4.11.0", "4.10.0", diff --git a/src/azure-functions-node/devcontainer-template.json b/src/azure-functions-node/devcontainer-template.json index 0ca6c02..be7a7e8 100644 --- a/src/azure-functions-node/devcontainer-template.json +++ b/src/azure-functions-node/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "azure-functions-node", - "version": "2.0.7", + "version": "2.1.0", "name": "Azure Functions (Node.js)", "description": "Develop JavaScript and TypeScript based Azure Functions. Includes all needed SDKs, extensions, and dependencies.", "documentationURL": "https://github.com/shibayan/devcontainers/tree/master/src/azure-functions-node", @@ -12,8 +12,7 @@ "description": "Node.js version:", "proposals": [ "24", - "22", - "20" + "22" ], "default": "24" }, @@ -22,6 +21,7 @@ "description": "Azure Functions CLI version:", "proposals": [ "latest", + "4.16.0", "4.12.0", "4.11.0", "4.10.0", diff --git a/src/azure-functions-powershell/README.md b/src/azure-functions-powershell/README.md index 2f98309..665d821 100644 --- a/src/azure-functions-powershell/README.md +++ b/src/azure-functions-powershell/README.md @@ -7,7 +7,7 @@ Develop PowerShell based Azure Functions. Includes all needed SDKs, extensions, | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| -| powerShellVersion | PowerShell version: | string | 7.4 | +| powerShellVersion | PowerShell version: | string | 7.6 | | azureFunctionsCliVersion | Azure Functions CLI version: | string | latest | diff --git a/src/azure-functions-powershell/devcontainer-template.json b/src/azure-functions-powershell/devcontainer-template.json index c97239d..bd05ec3 100644 --- a/src/azure-functions-powershell/devcontainer-template.json +++ b/src/azure-functions-powershell/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "azure-functions-powershell", - "version": "2.0.7", + "version": "2.1.0", "name": "Azure Functions (PowerShell)", "description": "Develop PowerShell based Azure Functions. Includes all needed SDKs, extensions, and dependencies.", "documentationURL": "https://github.com/shibayan/devcontainers/tree/master/src/azure-functions-powershell", @@ -14,13 +14,14 @@ "7.6", "7.4" ], - "default": "7.4" + "default": "7.6" }, "azureFunctionsCliVersion": { "type": "string", "description": "Azure Functions CLI version:", "proposals": [ "latest", + "4.16.0", "4.12.0", "4.11.0", "4.10.0", diff --git a/src/azure-functions-python/NOTES.md b/src/azure-functions-python/NOTES.md new file mode 100644 index 0000000..074e2c8 --- /dev/null +++ b/src/azure-functions-python/NOTES.md @@ -0,0 +1,5 @@ +## Core Tools on Linux ARM64 + +This template defaults to Azure Functions Core Tools **4.13.0** on both architectures. Core Tools 4.14.0 through 4.16.0 ship incomplete Python workers on Linux ARM64, causing `func start` to fail with `ImportError` before functions can be indexed. Version 4.13.0 is the last known working release in that range. + +Keep the default pinned until [Azure/azure-functions-core-tools#5772](https://github.com/Azure/azure-functions-core-tools/issues/5772) is resolved and the fixed release passes the Python HTTP smoke tests on both AMD64 and ARM64. Selecting `latest` or `4.16.0` currently exposes ARM64 users to this upstream defect. diff --git a/src/azure-functions-python/README.md b/src/azure-functions-python/README.md index 5ba9409..bb1a1a0 100644 --- a/src/azure-functions-python/README.md +++ b/src/azure-functions-python/README.md @@ -8,10 +8,16 @@ Develop Python based Azure Functions. Includes all needed SDKs, extensions, and | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| | pythonVersion | Python version: | string | 3.13 | -| azureFunctionsCliVersion | Azure Functions CLI version: | string | latest | +| azureFunctionsCliVersion | Azure Functions CLI version: | string | 4.13.0 | +## Core Tools on Linux ARM64 + +This template defaults to Azure Functions Core Tools **4.13.0** on both architectures. Core Tools 4.14.0 through 4.16.0 ship incomplete Python workers on Linux ARM64, causing `func start` to fail with `ImportError` before functions can be indexed. Version 4.13.0 is the last known working release in that range. + +Keep the default pinned until [Azure/azure-functions-core-tools#5772](https://github.com/Azure/azure-functions-core-tools/issues/5772) is resolved and the fixed release passes the Python HTTP smoke tests on both AMD64 and ARM64. Selecting `latest` or `4.16.0` currently exposes ARM64 users to this upstream defect. + --- _Note: This file was auto-generated from the [devcontainer-template.json](https://github.com/shibayan/devcontainers/blob/master/src/azure-functions-python/devcontainer-template.json). Add additional notes to a `NOTES.md`._ diff --git a/src/azure-functions-python/devcontainer-template.json b/src/azure-functions-python/devcontainer-template.json index 802c004..2e0382b 100644 --- a/src/azure-functions-python/devcontainer-template.json +++ b/src/azure-functions-python/devcontainer-template.json @@ -1,6 +1,6 @@ { "id": "azure-functions-python", - "version": "2.0.7", + "version": "2.1.0", "name": "Azure Functions (Python)", "description": "Develop Python based Azure Functions. Includes all needed SDKs, extensions, and dependencies.", "documentationURL": "https://github.com/shibayan/devcontainers/tree/master/src/azure-functions-python", @@ -14,8 +14,7 @@ "3.14", "3.13", "3.12", - "3.11", - "3.10" + "3.11" ], "default": "3.13" }, @@ -24,12 +23,14 @@ "description": "Azure Functions CLI version:", "proposals": [ "latest", + "4.16.0", + "4.13.0", "4.12.0", "4.11.0", "4.10.0", "4.9.0" ], - "default": "latest" + "default": "4.13.0" } }, "platforms": [ diff --git a/test/test-utils/functions-http-test.sh b/test/test-utils/functions-http-test.sh new file mode 100644 index 0000000..9b4b9c0 --- /dev/null +++ b/test/test-utils/functions-http-test.sh @@ -0,0 +1,127 @@ +#!/bin/bash +set -euo pipefail + +LANGUAGE="$1" +PROJECT_DIR=$(mktemp -d) +HOST_PID="" + +cleanup() { + status=$? + trap - EXIT + if [ -n "${HOST_PID}" ]; then + kill -- "-${HOST_PID}" 2>/dev/null || true + wait "${HOST_PID}" 2>/dev/null || true + fi + if [ "${status}" -ne 0 ] && [ -f "${PROJECT_DIR}/host.log" ]; then + cat "${PROJECT_DIR}/host.log" + fi + rm -rf "${PROJECT_DIR}" + exit "${status}" +} +trap cleanup EXIT + +cd "${PROJECT_DIR}" +START_COMMAND=(func start --port 7071) +FUNCTION_NAME=HttpExample + +case "${LANGUAGE}" in + dotnet) + framework="net$(dotnet --version | cut -d. -f1).0" + func init --worker-runtime dotnet-isolated --target-framework "${framework}" + ;; + node) + func init --worker-runtime node --language javascript + ;; + python) + python -m venv .venv + source .venv/bin/activate + func init --worker-runtime python + ;; + powershell) + func init --worker-runtime powershell + pwsh -NoProfile -Command ' + $settings = Get-Content local.settings.json -Raw | ConvertFrom-Json -AsHashtable + $settings.Values.FUNCTIONS_WORKER_RUNTIME_VERSION = "$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)" + $settings | ConvertTo-Json -Depth 10 | Set-Content local.settings.json + ' + ;; + java) + java_version=$(java -version 2>&1 | head -n1 | cut -d '"' -f2 | cut -d. -f1) + if [ "${java_version}" = "1" ]; then java_version=8; fi + mvn -B archetype:generate \ + -DarchetypeGroupId=com.microsoft.azure \ + -DarchetypeArtifactId=azure-functions-archetype \ + -DgroupId=devcontainers.smoke -DartifactId=smoke \ + -Dversion=1.0-SNAPSHOT -Dpackage=devcontainers.smoke \ + -DappName=devcontainers-smoke -DjavaVersion="${java_version}" \ + -DinteractiveMode=false + cd smoke + mvn -B package -DskipTests + START_COMMAND=(mvn -B azure-functions:run) + ;; + go) + func init --worker-runtime go + # Go uses code-first registration; func new is not supported. + cat > main.go <<'GO' +package main + +import ( + "fmt" + "net/http" + + "github.com/azure/azure-functions-golang-worker/sdk" + "github.com/azure/azure-functions-golang-worker/worker" +) + +func main() { + app := sdk.FunctionApp() + app.HTTP("HttpExample", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "devcontainers-smoke") + }, sdk.WithMethods("GET"), sdk.WithAuth("anonymous")) + worker.Start(app) +} +GO + go mod tidy + ;; + *) + echo "Unsupported language: ${LANGUAGE}" >&2 + exit 1 + ;; +esac + +case "${LANGUAGE}" in + java|go) ;; + *) func new --name "${FUNCTION_NAME}" --template "HTTP trigger" --authlevel anonymous ;; +esac + +case "${LANGUAGE}" in + node) npm install ;; + python) python -m pip install -r requirements.txt ;; + # Avoid downloading Azure modules for a simple HTTP trigger. + powershell) printf '@{}\n' > requirements.psd1 ;; +esac + +# Use only the Azurite sidecar; no Azure account or cloud credentials are needed. +export AzureWebJobsStorage=UseDevelopmentStorage=true +export FUNCTIONS_CORE_TOOLS_TELEMETRY_OPTOUT=1 + +# Bound host startup (including builds), and stop the entire process group on exit. +setsid timeout --kill-after=10s 300s "${START_COMMAND[@]}" > "${PROJECT_DIR}/host.log" 2>&1 & +HOST_PID=$! +for ((attempt=0; attempt<150; attempt++)); do + if ! kill -0 "${HOST_PID}" 2>/dev/null; then + echo "Functions host exited before the HTTP trigger became ready." >&2 + exit 1 + fi + if curl --fail --silent --show-error --max-time 2 \ + "http://localhost:7071/api/${FUNCTION_NAME}?name=devcontainers-smoke" \ + > "${PROJECT_DIR}/response.txt" 2>/dev/null \ + && [ -s "${PROJECT_DIR}/response.txt" ]; then + echo "Functions host invoked the ${LANGUAGE} HTTP trigger successfully." + exit 0 + fi + sleep 2 +done + +echo "Timed out waiting for the ${LANGUAGE} HTTP trigger." >&2 +exit 1 diff --git a/test/test-utils/run-template-checks.sh b/test/test-utils/run-template-checks.sh index a8f1bfc..7b0bce6 100644 --- a/test/test-utils/run-template-checks.sh +++ b/test/test-utils/run-template-checks.sh @@ -8,6 +8,24 @@ LABEL="$1" shift check "$LABEL" "$@" +if [ -n "${EXPECTED_RUNTIME_VERSION:-}" ]; then + actual_version=$("$@" 2>&1) + expected_version="${EXPECTED_RUNTIME_VERSION}" + if [ "${LABEL}" = "java" ] && [ "${expected_version}" = "8" ]; then + expected_version=1.8 + fi + case "${LABEL}" in + dotnet) prefix='^' ;; + go) prefix='go' ;; + java) prefix='version "' ;; + node) prefix='^v' ;; + powershell) prefix='PowerShell ' ;; + python) prefix='Python ' ;; + esac + check "selected runtime ${EXPECTED_RUNTIME_VERSION}" \ + grep -E "${prefix}${expected_version//./\\.}([.\"[:space:]]|$)" <<< "${actual_version}" +fi check "func" func --version +check "Functions HTTP trigger" bash functions-http-test.sh "$LABEL" reportResults diff --git a/test/test-utils/test-utils.sh b/test/test-utils/test-utils.sh index 5e4b4ae..3dd0cc6 100644 --- a/test/test-utils/test-utils.sh +++ b/test/test-utils/test-utils.sh @@ -8,7 +8,7 @@ echoStderr() } check() { - LABEL=$1 + local LABEL=$1 shift echo -e "\n🧪 Testing $LABEL" if "$@"; then