Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 20035cc

Browse files
authored
Merge pull request #153 from brettmillerb/azfunction-pwsh
Added pwsh az function container
2 parents bdcba08 + 03f243d commit 20035cc

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "Azure Functions & pwsh (.NET Core 2.2)",
3+
"dockerFile": "Dockerfile",
4+
"appPort": 7071,
5+
// Use 'settings' to set *default* container specific settings.json values on container create.
6+
// You can edit these settings after create using File > Preferences > Settings > Remote.
7+
"settings": {
8+
"terminal.integrated.shell.linux": "/usr/bin/pwsh"
9+
},
10+
// Uncomment the next line to run commands after the container is created.
11+
// "postCreateCommand": "dotnet restore",
12+
// Uncomment the next line to use a non-root user. On Linux, this will prevent
13+
// new files getting created as root, but you may need to update the USER_UID
14+
// and USER_GID in .devcontainer/Dockerfile to match your user if not 1000.
15+
// "runArgs": [ "-u", "vscode" ],
16+
// Add the IDs of extensions you want installed when the container is created in the array below.
17+
"extensions": [
18+
"ms-azuretools.vscode-azurefunctions",
19+
"ms-vscode.powershell"
20+
]
21+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
3+
4+
# Avoid warnings by switching to noninteractive
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux,
8+
# this user's GID/UID must match your local user UID/GID to avoid permission issues
9+
# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See
10+
# https://aka.ms/vscode-remote/containers/non-root-user for details.
11+
ARG USERNAME=vscode
12+
ARG USER_UID=1000
13+
ARG USER_GID=$USER_UID
14+
15+
ARG PS_VERSION=6.2.3
16+
ARG PS_PACKAGE=powershell_${PS_VERSION}-1.debian.9_amd64.deb
17+
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE}
18+
19+
# Download the Linux package and save it
20+
ADD ${PS_PACKAGE_URL} /tmp/powershell.deb
21+
22+
# Define ENVs for Localization/Globalization
23+
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
24+
LC_ALL=en_US.UTF-8 \
25+
LANG=en_US.UTF-8 \
26+
# set a fixed location for the Module analysis cache
27+
PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache
28+
29+
ENV FUNCTIONS_WORKER_RUNTIME=powershell
30+
31+
# Configure apt and install packages
32+
RUN apt-get update \
33+
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
34+
&& apt install -y /tmp/powershell.deb \
35+
#
36+
# Verify git and needed tools are installed
37+
&& apt-get -y install \
38+
git \
39+
iproute2 \
40+
procps \
41+
curl \
42+
apt-transport-https \
43+
gnupg2 \
44+
lsb-release \
45+
# less is required for help in powershell
46+
less \
47+
# requied to setup the locale
48+
locales \
49+
# required for SSL
50+
ca-certificates \
51+
gss-ntlmssp \
52+
&& apt-get dist-upgrade -y \
53+
# enable en_US.UTF-8 locale
54+
&& sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen \
55+
# generate locale
56+
&& locale-gen && update-locale \
57+
# remove powershell package
58+
&& rm /tmp/powershell.deb \
59+
#
60+
# Install Azure Functions and Azure CLI
61+
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \
62+
&& 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 \
63+
&& curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) \
64+
&& apt-get update \
65+
&& apt-get install -y azure-cli azure-functions-core-tools \
66+
#
67+
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
68+
&& groupadd --gid $USER_GID $USERNAME \
69+
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
70+
# [Optional] Add sudo support for the non-root user
71+
&& apt-get install -y sudo \
72+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
73+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
74+
#
75+
# Clean up
76+
&& apt-get autoremove -y \
77+
&& apt-get clean -y \
78+
&& rm -rf /var/lib/apt/lists/* \
79+
# intialize powershell module cache
80+
&& pwsh \
81+
-NoLogo \
82+
-NoProfile \
83+
-Command " \
84+
\$ErrorActionPreference = 'Stop' ; \
85+
\$ProgressPreference = 'SilentlyContinue' ; \
86+
while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) { \
87+
Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; \
88+
Start-Sleep -Seconds 6 ; \
89+
}"
90+
91+
# Switch back to dialog for any ad-hoc use of apt-get
92+
ENV DEBIAN_FRONTEND=
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
README.md
2+
test-project
3+
.vscode
4+
.npmignore
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Azure Functions & Pwsh (.NET Core Latest)
2+
3+
## Summary
4+
5+
*Develop Azure Functions in PowerShell. Includes NET Core (Latest), the Azure Functions SDK, and related extensions and dependencies.*
6+
7+
| Metadata | Value |
8+
|----------|-------|
9+
| *Contributors* | [brettmillerb](https://github.com/brettmillerb) |
10+
| *Definition type* | Dockerfile |
11+
| *Languages, platforms* | Azure Functions, .NET Core, PowerShell |
12+
13+
## Using this definition with an existing folder
14+
15+
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:
16+
17+
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.
18+
19+
2. To use VS Code's copy of this definition:
20+
1. Start VS Code and open your project folder.
21+
2. Press <kbd>F1</kbd> select and **Remote-Containers: Add Development Container Configuration Files...** from the command palette.
22+
3. Select the Azure Functions & pwsh (.NET Core 2.2) definition.
23+
24+
3. To use latest-and-greatest copy of this definition from the repository:
25+
1. Clone this repository.
26+
2. Copy the contents of `containers/azure-functions-pwsh-6/.devcontainer` to the root of your project folder.
27+
3. Start VS Code and open your project folder.
28+
29+
4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs.
30+
31+
5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition.
32+
33+
## Testing the definition
34+
35+
This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:
36+
37+
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.
38+
2. Clone this repository.
39+
3. Start VS Code, press <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**
40+
4. Select the `containers/azure-functions-pwsh-6` folder.
41+
5. After the folder has opened in the container, press <kbd>F1</kbd> and select **Azure Functions: Create Function...**.
42+
6. Enter these options:
43+
1. Yes (when prompted to create a new project)
44+
2. powershell
45+
3. HTTP Trigger
46+
4. HttpTriggerPowerShell
47+
5. Anonymous
48+
6. Open in current window
49+
7. Press <kbd>F5</kbd> to start debugging project.
50+
8. After the debugger is started, open a local browser and enter the URL: `http://localhost:7071/api/HttpTriggerPowerShell?name=remote`.
51+
- If the port 7071 is not already open, press <kbd>F1</kbd>, select **Remote-Containers: Forward Port from Container...**, and then port 7071.
52+
9. You should see "Hello, remote" echoed by the Azure Function.
53+
10. From here, you can add breakpoints or edit the contents of the `test-project` folder to do further testing.
54+
55+
## License
56+
57+
Copyright (c) Microsoft Corporation. All rights reserved.
58+
59+
Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE).

0 commit comments

Comments
 (0)