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

Commit

Permalink
Fix Azure Functions Node defintions, add test projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuxel committed Apr 27, 2019
1 parent c31bcef commit 59ba913
Show file tree
Hide file tree
Showing 28 changed files with 424 additions and 42 deletions.
25 changes: 4 additions & 21 deletions containers/azure-functions-node-8/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM mcr.microsoft.com/dotnet/core/sdk:2.1
FROM node:8

# Configure apt
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -19,32 +19,15 @@ RUN apt-get -y install \
gnupg2 \
lsb-release

# Install Node.js via NVM - See https://github.com/creationix/nvm
# Change the number "8" in the two lines below to pick a different version
RUN curl -so- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash 2>&1 \
&& /bin/bash -c "source $HOME/.nvm/nvm.sh \
&& nvm install --no-progress 8 \
&& nvm alias default 8" 2>&1

# Install eslint
RUN /bin/bash -c "source $HOME/.nvm/nvm.sh && npm install -g eslint"

# Install latest yarn
RUN curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
&& echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get -y install --no-install-recommends yarn

# Install Azure Functions and Azure CLI
# Install Azure Functions, .NET Core, and Azure CLI
RUN 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 | apt-key add - 2>/dev/null \
&& 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
&& apt-get install -y azure-cli dotnet-sdk-2.1 azure-functions-core-tools

# Clean up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
ENV DEBIAN_FRONTEND=dialog

5 changes: 5 additions & 0 deletions containers/azure-functions-node-8/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
13 changes: 13 additions & 0 deletions containers/azure-functions-node-8/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node Functions",
"type": "node",
"request": "attach",
"port": 9229,
"cwd": "${workspaceFolder}/test-project",
"preLaunchTask": "func: host start"
}
]
}
11 changes: 11 additions & 0 deletions containers/azure-functions-node-8/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"azureFunctions.projectRuntime": "~2",
"azureFunctions.projectLanguage": "JavaScript",
"azureFunctions.deploySubpath": ".",
"azureFunctions.preDeployTask": "func: extensions install",
"files.exclude": {
"obj": true,
"bin": true
},
"debug.internalConsoleOptions": "neverOpen"
}
17 changes: 17 additions & 0 deletions containers/azure-functions-node-8/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"command": "host start",
"problemMatcher": "$func-watch",
"dependsOn": "func: extensions install",
"isBackground": true
},
{
"label": "PATH",
"type": "shell",
"command": "echo $PATH"
}
]
}
13 changes: 13 additions & 0 deletions containers/azure-functions-node-8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ This definition requires an Azure subscription to use. You can create a [free ac

5. Finally, press <kbd>F1</kbd> 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 <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**
4. Select the `containers/azure-functions-node-8` folder.
5. After the folder has opened in the container, press <kbd>F5</kbd> to start the project.
6. After the debugger is started, open a local browser and enter the URL: `http://localhost:7071/api/HttpTrigger?name=remote`.
7. You should see "Hello remote" echoed by the Azure Function.
8. 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.
Expand Down
4 changes: 4 additions & 0 deletions containers/azure-functions-node-8/test-project/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git*
.vscode
local.settings.json
test
90 changes: 90 additions & 0 deletions containers/azure-functions-node-8/test-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json

# TypeScript output
dist
out
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');

if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + (req.query.name || req.body.name)
};
}
else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Azure"
}
10 changes: 10 additions & 0 deletions containers/azure-functions-node-8/test-project/extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsAsErrors></WarningsAsErrors>
<DefaultItemExcludes>**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.2" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions containers/azure-functions-node-8/test-project/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.0"
}
4 changes: 4 additions & 0 deletions containers/azure-functions-node-8/test-project/proxies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {}
}
25 changes: 4 additions & 21 deletions containers/azure-functions-node-lts/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM mcr.microsoft.com/dotnet/core/sdk:2.1
FROM node:lts

# Configure apt
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -19,32 +19,15 @@ RUN apt-get -y install \
gnupg2 \
lsb-release

# Install Node.js via NVM - See https://github.com/creationix/nvm
# Change the "lts/*" in the two lines below to pick a different version
RUN curl -so- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash 2>&1 \
&& /bin/bash -c "source $HOME/.nvm/nvm.sh \
&& nvm install --no-progress lts/* \
&& nvm alias default lts/*" 2>&1

# Install eslint
RUN /bin/bash -c "source $HOME/.nvm/nvm.sh && npm install -g eslint"

# Install latest yarn
RUN curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
&& echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get -y install --no-install-recommends yarn

# Install Azure Functions and Azure CLI
# Install Azure Functions, .NET Core, and Azure CLI
RUN 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 | apt-key add - 2>/dev/null \
&& 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
&& apt-get install -y azure-cli dotnet-sdk-2.1 azure-functions-core-tools

# Clean up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
ENV DEBIAN_FRONTEND=dialog

5 changes: 5 additions & 0 deletions containers/azure-functions-node-lts/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
13 changes: 13 additions & 0 deletions containers/azure-functions-node-lts/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node Functions",
"type": "node",
"request": "attach",
"port": 9229,
"cwd": "${workspaceFolder}/test-project",
"preLaunchTask": "func: host start"
}
]
}
11 changes: 11 additions & 0 deletions containers/azure-functions-node-lts/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"azureFunctions.projectRuntime": "~2",
"azureFunctions.projectLanguage": "JavaScript",
"azureFunctions.deploySubpath": ".",
"azureFunctions.preDeployTask": "func: extensions install",
"files.exclude": {
"obj": true,
"bin": true
},
"debug.internalConsoleOptions": "neverOpen"
}
17 changes: 17 additions & 0 deletions containers/azure-functions-node-lts/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"command": "host start",
"problemMatcher": "$func-watch",
"dependsOn": "func: extensions install",
"isBackground": true
},
{
"label": "PATH",
"type": "shell",
"command": "echo $PATH"
}
]
}
13 changes: 13 additions & 0 deletions containers/azure-functions-node-lts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ This definition requires an Azure subscription to use. You can create a [free ac

5. Finally, press <kbd>F1</kbd> 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 <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**
4. Select the `containers/azure-functions-node-lts` folder.
5. After the folder has opened in the container, press <kbd>F5</kbd> to start the project.
6. After the debugger is started, open a local browser and enter the URL: `http://localhost:7071/api/HttpTrigger?name=remote`.
7. You should see "Hello remote" echoed by the Azure Function.
8. 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.
Expand Down
4 changes: 4 additions & 0 deletions containers/azure-functions-node-lts/test-project/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git*
.vscode
local.settings.json
test
Loading

0 comments on commit 59ba913

Please sign in to comment.