Skip to content

Commit

Permalink
Merge pull request #3177 from Azure/dev
Browse files Browse the repository at this point in the history
Merging dev to master
  • Loading branch information
pragnagopa authored Jul 24, 2018
2 parents b8273ee + d231af8 commit 5909952
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 40 deletions.
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM microsoft/dotnet:2.1-sdk AS installer-env

ENV PublishWithAspNetCoreTargetManifest false

COPY . /workingdir

RUN cd workingdir && \
dotnet build WebJobs.Script.sln && \
dotnet publish src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj --output /azure-functions-host

# Runtime image
FROM microsoft/dotnet:2.1-aspnetcore-runtime

RUN apt-get update && \
apt-get install -y gnupg && \
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
apt-get update && \
apt-get install -y nodejs

COPY --from=installer-env ["/azure-functions-host", "/azure-functions-host"]
COPY --from=installer-env ["/workingdir/sample", "/home/site/wwwroot"]

ENV AzureWebJobsScriptRoot=/home/site/wwwroot
ENV HOME=/home
ENV ASPNETCORE_URLS=http://+:80
EXPOSE 80

CMD dotnet /azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost.dll
57 changes: 44 additions & 13 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function CrossGen([string] $runtime, [string] $publishTarget, [string] $privateS

# Modify web.config for inproc
dotnet tool install -g dotnet-xdt --version 2.1.0-rc.1
dotnet-xdt -s "$privateSiteExtensionPath\web.config" -t "$privateSiteExtensionPath\web.InProcess.xdt" -o "$privateSiteExtensionPath\web.config"
dotnet-xdt -s "$privateSiteExtensionPath\web.config" -t "$privateSiteExtensionPath\web.InProcess.$runtime.xdt" -o "$privateSiteExtensionPath\web.config"

$successfullDlls =@()
$failedDlls = @()
Expand Down Expand Up @@ -87,8 +87,9 @@ function CrossGen([string] $runtime, [string] $publishTarget, [string] $privateS
}


# If not self-contained
Copy-Item -Path $privateSiteExtensionPath\runtimes\win\native\* -Destination $privateSiteExtensionPath -Force
if ($runtime -eq "win-x86") {
Copy-Item -Path $privateSiteExtensionPath\runtimes\win\native\* -Destination $privateSiteExtensionPath -Force
}

#read-host "Press ENTER to continue..."
Remove-Item -Recurse -Force $selfContained -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -116,7 +117,26 @@ function DownloadNupkg([string] $nupkgPath, [string[]]$from, [string[]]$to) {
}
}

function BuildPackages([string] $runtime<#, [bool] $isSelfContained#>) {
function BuildPackages([bool] $isNoRuntime) {
if($isNoRuntime) {
BuildOutput ""
CreateZips ".no-runtime"
} else {
BuildOutput "win-x86"
BuildOutput "win-x64"

New-Item -Itemtype directory -path $buildOutput\publish.runtime\SiteExtensions\Functions
Move-Item -Path $buildOutput\publish.win-x86\SiteExtensions\Functions -Destination $buildOutput\publish.runtime\SiteExtensions\Functions\32bit -Force
Move-Item -Path $buildOutput\publish.win-x64\SiteExtensions\Functions -Destination $buildOutput\publish.runtime\SiteExtensions\Functions\64bit -Force
Move-Item -Path $buildOutput\publish.runtime\SiteExtensions\Functions\32bit\applicationHost.xdt -Destination $buildOutput\publish.runtime\SiteExtensions\Functions -Force
Remove-Item -Path $buildOutput\publish.runtime\SiteExtensions\Functions\64bit\applicationHost.xdt

CreateZips ".runtime"
}
}


function BuildOutput([string] $runtime) {
$runtimeSuffix = ""
if (![string]::IsNullOrEmpty($runtime)) {
$runtimeSuffix = ".$runtime"
Expand All @@ -128,17 +148,28 @@ function BuildPackages([string] $runtime<#, [bool] $isSelfContained#>) {
$siteExtensionPath = "$publishTarget\SiteExtensions"
$privateSiteExtensionPath = "$siteExtensionPath\Functions"

dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
#dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -r $runtime -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
if ($runtime -eq "win-x86" -or $runtime -eq "") {
dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
} else {
# There are no preinstalled 'x64 .NET Core'/'x64 ASP.NET Core' on the stamp so we we need to build self-contained package for x64.
dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -r $runtime -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
}

# replace IL dlls with crossgen dlls
if (![string]::IsNullOrEmpty($runtime)) {
CrossGen $runtime $publishTarget $privateSiteExtensionPath
}
}

# Do not put siffux to win-x86 zips names
if ($runtime -eq "win-x86") {
$runtimeSuffix = "";

function CreateZips([string] $runtimeSuffix) {
$publishTarget = "$buildOutput\publish$runtimeSuffix"
$siteExtensionPath = "$publishTarget\SiteExtensions"
$privateSiteExtensionPath = "$siteExtensionPath\Functions"

# We do not want .runtime as suffix for zips
if ($runtimeSuffix -eq ".runtime") {
$runtimesuffix = "";
}

ZipContent $privateSiteExtensionPath "$buildOutput\Functions.Binaries.$extensionVersion-alpha$runtimeSuffix.zip"
Expand Down Expand Up @@ -184,9 +215,9 @@ $bypassPackaging = $env:APPVEYOR_PULL_REQUEST_NUMBER -and -not $env:APPVEYOR_PUL
if ($bypassPackaging){
Write-Host "Bypassing artifact packaging and CrossGen for pull request." -ForegroundColor Yellow
} else {
# build IL extensions
BuildPackages ""
# build no-runntime extension
BuildPackages 1

#build win-x86 extensions
BuildPackages "win-x86"
#build win-x86 and win-x64 extension
BuildPackages 0
}
12 changes: 6 additions & 6 deletions sample/HttpTrigger-Java/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
public class Function {
/**
* This function listens at endpoint "/api/hello". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/hello
* This function listens at endpoint "/api/HttpTrigger-Java". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/HttpTrigger-Java
* 2. curl {your host}/api/HttpTrigger-Java?name=HTTP%20Query
*/
@FunctionName("HttpTrigger-Java")
public HttpResponseMessage<String> HttpTriggerJava(
@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
public HttpResponseMessage HttpTriggerJava(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");

Expand All @@ -30,9 +30,9 @@ public HttpResponseMessage<String> HttpTriggerJava(
String name = request.getBody().orElse(query);

if (name == null) {
return request.createResponse(400, "Please pass a name on the query string or in the request body");
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponse(200, "Hello " + name);
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
}
}
}
Binary file modified sample/HttpTrigger-Java/HttpTrigger-Java-1.0-SNAPSHOT.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Azure.Web.DataProtection;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.WebHost;
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authentication;
using Microsoft.IdentityModel.Tokens;
using static Microsoft.Azure.WebJobs.Script.EnvironmentSettingNames;
Expand All @@ -18,11 +21,23 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ScriptJwtBearerExtensions
{
private static double _specialized = 0;

public static AuthenticationBuilder AddScriptJwtBearer(this AuthenticationBuilder builder)
=> builder.AddJwtBearer(o =>
{
o.Events = new JwtBearerEvents()
{
OnMessageReceived = c =>
{
// Temporary: Tactical fix to address specialization issues. This should likely be moved to a token validator
if (_specialized == 0 && !WebScriptHostManager.InStandbyMode && Interlocked.CompareExchange(ref _specialized, 1, 0) == 0)
{
o.TokenValidationParameters = CreateTokenValidationParameters();
}

return Task.CompletedTask;
},
OnTokenValidated = c =>
{
c.Principal.AddIdentity(new ClaimsIdentity(new Claim[]
Expand All @@ -35,19 +50,32 @@ public static AuthenticationBuilder AddScriptJwtBearer(this AuthenticationBuilde
return Task.CompletedTask;
}
};
string defaultKey = Util.GetDefaultKeyValue();
if (defaultKey != null)

o.TokenValidationParameters = CreateTokenValidationParameters();

if (!WebScriptHostManager.InStandbyMode)
{
// TODO: Once ScriptSettingsManager is gone, Audience and Issuer shouold be pulled from configuration.
o.TokenValidationParameters = new TokenValidationParameters()
{
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(defaultKey)),
ValidateAudience = true,
ValidateIssuer = true,
ValidAudience = string.Format(AdminJwtValidAudienceFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName)),
ValidIssuer = string.Format(AdminJwtValidIssuerFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName))
};
// We're not in standby mode, so flag as specialized
_specialized = 1;
}
});

private static TokenValidationParameters CreateTokenValidationParameters()
{
string defaultKey = Util.GetDefaultKeyValue();

var result = new TokenValidationParameters();
if (defaultKey != null)
{
// TODO: Once ScriptSettingsManager is gone, Audience and Issuer shouold be pulled from configuration.
result.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(defaultKey));
result.ValidateAudience = true;
result.ValidateIssuer = true;
result.ValidAudience = string.Format(AdminJwtValidAudienceFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName));
result.ValidIssuer = string.Format(AdminJwtValidIssuerFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName));
}

return result;
}
}
}
8 changes: 6 additions & 2 deletions src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
<ItemGroup>
<None Remove="applicationHost.xdt" />
<None Remove="Resources\Functions\WarmUp\run.csx" />
<None Remove="web.InProcess.xdt" />
<None Remove="web.InProcess.win-x64.xdt" />
<None Remove="web.InProcess.win-x86.xdt" />
</ItemGroup>
<ItemGroup>
<Content Include="applicationHost.xdt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="web.InProcess.xdt">
<Content Include="web.InProcess.win-x64.xdt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="web.InProcess.win-x86.xdt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/WebJobs.Script.WebHost/applicationHost.xdt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<site name="%XDT_SITENAME%" xdt:Locator="Match(name)">
<application path="/" xdt:Locator="Match(path)" xdt:Transform="Remove" />
<application path="/" applicationPool="%XDT_APPPOOLNAME%" xdt:Transform="Insert">
<virtualDirectory path="/" physicalPath="%XDT_EXTENSIONPATH%" />
</application>
<virtualDirectory path="/" physicalPath="%XDT_EXTENSIONPATH%\%XDT_BITNESS%" />
</application>
</site>
</sites>
</system.applicationHost>
<system.webServer>
<globalModules>
<add name="AspNetCoreModuleV2" xdt:Locator="Match(name)" xdt:Transform="Remove" />
<add name="AspNetCoreModuleV2" image="%XDT_EXTENSIONPATH%\ancm\aspnetcoreV2.dll" xdt:Transform="Insert" />
<add name="AspNetCoreModuleV2" image="%XDT_EXTENSIONPATH%\%XDT_BITNESS%\ancm\aspnetcoreV2.dll" xdt:Transform="Insert" />
</globalModules>
</system.webServer>
<location path="%XDT_SITENAME%" xdt:Locator="Match(path)" xdt:Transform="InsertIfMissing">
Expand Down
9 changes: 9 additions & 0 deletions src/WebJobs.Script.WebHost/web.InProcess.win-x64.xdt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" xdt:Transform="Replace" xdt:Locator="Match(name)" />
</handlers>
<aspNetCore processPath=".\Microsoft.Azure.WebJobs.Script.WebHost.exe" arguments="" stdoutLogEnabled="false" hostingModel="inprocess" xdt:Transform="Replace" />
</system.webServer>
</configuration>
2 changes: 1 addition & 1 deletion src/WebJobs.Script/WebJobs.Script.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.Azure.AppService.Proxy.Client" Version="2.0.5350001-beta-fc119b98" />
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.1.0-beta7" />
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.1.0-beta8" />
<PackageReference Include="Microsoft.Azure.Functions.NodeJsWorker" Version="1.0.0-beta3" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta7-11351" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.0-beta7-10629" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="1.9.1" />
<PackageReference Include="Microsoft.Azure.EventHubs" Version="1.0.3" />
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.1.0-beta7" />
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.1.0-beta8" />
<PackageReference Include="Microsoft.Azure.Functions.NodeJsWorker" Version="1.0.0-beta3" />
<PackageReference Include="Microsoft.Azure.Mobile.Client" Version="4.0.2" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="2.0.0" />
Expand Down
24 changes: 21 additions & 3 deletions test/WebJobs.Script.Tests.Shared/TestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class TestLogger : ILogger
private readonly Func<string, LogLevel, bool> _filter;
private IList<LogMessage> _logMessages = new List<LogMessage>();

// protect against changes to _logMessages while enumerating
private object _syncLock = new object();

public TestLogger(string category, Func<string, LogLevel, bool> filter = null)
{
Category = category;
Expand All @@ -31,9 +34,21 @@ public bool IsEnabled(LogLevel logLevel)
return _filter?.Invoke(Category, logLevel) ?? true;
}

public IList<LogMessage> GetLogMessages() => _logMessages.ToList();
public IList<LogMessage> GetLogMessages()
{
lock (_syncLock)
{
return _logMessages.ToList();
}
}

public void ClearLogMessages() => _logMessages.Clear();
public void ClearLogMessages()
{
lock (_syncLock)
{
_logMessages.Clear();
}
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Expand All @@ -53,7 +68,10 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
Timestamp = DateTime.UtcNow
};

_logMessages.Add(logMessage);
lock (_syncLock)
{
_logMessages.Add(logMessage);
}
}
}

Expand Down

0 comments on commit 5909952

Please sign in to comment.