diff --git a/containers/azure-functions-pwsh-6/.devcontainer/devcontainer.json b/containers/azure-functions-pwsh-6/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..ccaa4e2c5d --- /dev/null +++ b/containers/azure-functions-pwsh-6/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +{ + "name": "Azure Functions & pwsh (.NET Core 2.2)", + "dockerFile": "Dockerfile", + "appPort": 7071, + // Use 'settings' to set *default* container specific settings.json values on container create. + // You can edit these settings after create using File > Preferences > Settings > Remote. + "settings": { + "terminal.integrated.shell.linux": "/usr/bin/pwsh" + }, + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "dotnet restore", + // Uncomment the next line to use a non-root user. On Linux, this will prevent + // new files getting created as root, but you may need to update the USER_UID + // and USER_GID in .devcontainer/Dockerfile to match your user if not 1000. + // "runArgs": [ "-u", "vscode" ], + // Add the IDs of extensions you want installed when the container is created in the array below. + "extensions": [ + "ms-azuretools.vscode-azurefunctions", + "ms-vscode.powershell" + ] +} diff --git a/containers/azure-functions-pwsh-6/.devcontainer/dockerfile b/containers/azure-functions-pwsh-6/.devcontainer/dockerfile new file mode 100644 index 0000000000..e4da9cbf58 --- /dev/null +++ b/containers/azure-functions-pwsh-6/.devcontainer/dockerfile @@ -0,0 +1,92 @@ + +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux, +# this user's GID/UID must match your local user UID/GID to avoid permission issues +# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See +# https://aka.ms/vscode-remote/containers/non-root-user for details. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +ARG PS_VERSION=6.2.3 +ARG PS_PACKAGE=powershell_${PS_VERSION}-1.debian.9_amd64.deb +ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} + +# Download the Linux package and save it +ADD ${PS_PACKAGE_URL} /tmp/powershell.deb + +# Define ENVs for Localization/Globalization +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ + LC_ALL=en_US.UTF-8 \ + LANG=en_US.UTF-8 \ + # set a fixed location for the Module analysis cache + PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache + +ENV FUNCTIONS_WORKER_RUNTIME=powershell + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ + && apt install -y /tmp/powershell.deb \ + # + # Verify git and needed tools are installed + && apt-get -y install \ + git \ + iproute2 \ + procps \ + curl \ + apt-transport-https \ + gnupg2 \ + lsb-release \ + # less is required for help in powershell + less \ + # requied to setup the locale + locales \ + # required for SSL + ca-certificates \ + gss-ntlmssp \ + && apt-get dist-upgrade -y \ + # enable en_US.UTF-8 locale + && sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen \ + # generate locale + && locale-gen && update-locale \ + # remove powershell package + && rm /tmp/powershell.deb \ + # + # Install Azure Functions and Azure CLI + && echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \ + && echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list \ + && curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) \ + && apt-get update \ + && apt-get install -y azure-cli azure-functions-core-tools \ + # + # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. + && groupadd --gid $USER_GID $USERNAME \ + && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # [Optional] Add sudo support for the non-root user + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + # + # Clean up + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* \ + # intialize powershell module cache + && pwsh \ + -NoLogo \ + -NoProfile \ + -Command " \ + \$ErrorActionPreference = 'Stop' ; \ + \$ProgressPreference = 'SilentlyContinue' ; \ + while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) { \ + Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; \ + Start-Sleep -Seconds 6 ; \ + }" + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND= diff --git a/containers/azure-functions-pwsh-6/.npmignore b/containers/azure-functions-pwsh-6/.npmignore new file mode 100644 index 0000000000..1d72d293eb --- /dev/null +++ b/containers/azure-functions-pwsh-6/.npmignore @@ -0,0 +1,4 @@ +README.md +test-project +.vscode +.npmignore diff --git a/containers/azure-functions-pwsh-6/README.md b/containers/azure-functions-pwsh-6/README.md new file mode 100644 index 0000000000..fbb0a84388 --- /dev/null +++ b/containers/azure-functions-pwsh-6/README.md @@ -0,0 +1,59 @@ +# Azure Functions & Pwsh (.NET Core Latest) + +## Summary + +*Develop Azure Functions in PowerShell. Includes NET Core (Latest), the Azure Functions SDK, and related extensions and dependencies.* + +| Metadata | Value | +|----------|-------| +| *Contributors* | [brettmillerb](https://github.com/brettmillerb) | +| *Definition type* | Dockerfile | +| *Languages, platforms* | Azure Functions, .NET Core, PowerShell | + +## Using this definition with an existing folder + +This definition requires an Azure subscription to use. You can create a [free account here](https://azure.microsoft.com/en-us/free/serverless/) and learn more about using [Azure Functions with VS Code here](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code). Once you have an Azure account, follow these steps: + +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. + +2. To use VS Code's copy of this definition: + 1. Start VS Code and open your project folder. + 2. Press F1 select and **Remote-Containers: Add Development Container Configuration Files...** from the command palette. + 3. Select the Azure Functions & pwsh (.NET Core 2.2) definition. + +3. To use latest-and-greatest copy of this definition from the repository: + 1. Clone this repository. + 2. Copy the contents of `containers/azure-functions-pwsh-6/.devcontainer` to the root of your project folder. + 3. Start VS Code and open your project folder. + +4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs. + +5. Finally, press F1 and run **Remote-Containers: Reopen Folder in Container** to start using the definition. + +## Testing the definition + +This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps: + +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. +2. Clone this repository. +3. Start VS Code, press F1, and select **Remote-Containers: Open Folder in Container...** +4. Select the `containers/azure-functions-pwsh-6` folder. +5. After the folder has opened in the container, press F1 and select **Azure Functions: Create Function...**. +6. Enter these options: + 1. Yes (when prompted to create a new project) + 2. powershell + 3. HTTP Trigger + 4. HttpTriggerPowerShell + 5. Anonymous + 6. Open in current window +7. Press F5 to start debugging project. +8. After the debugger is started, open a local browser and enter the URL: `http://localhost:7071/api/HttpTriggerPowerShell?name=remote`. + - If the port 7071 is not already open, press F1, select **Remote-Containers: Forward Port from Container...**, and then port 7071. +9. You should see "Hello, remote" echoed by the Azure Function. +10. From here, you can add breakpoints or edit the contents of the `test-project` folder to do further testing. + +## License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE).