Skip to content

Commit 5909952

Browse files
authored
Merge pull request #3177 from Azure/dev
Merging dev to master
2 parents b8273ee + d231af8 commit 5909952

File tree

12 files changed

+158
-40
lines changed

12 files changed

+158
-40
lines changed

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM microsoft/dotnet:2.1-sdk AS installer-env
2+
3+
ENV PublishWithAspNetCoreTargetManifest false
4+
5+
COPY . /workingdir
6+
7+
RUN cd workingdir && \
8+
dotnet build WebJobs.Script.sln && \
9+
dotnet publish src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj --output /azure-functions-host
10+
11+
# Runtime image
12+
FROM microsoft/dotnet:2.1-aspnetcore-runtime
13+
14+
RUN apt-get update && \
15+
apt-get install -y gnupg && \
16+
curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
17+
apt-get update && \
18+
apt-get install -y nodejs
19+
20+
COPY --from=installer-env ["/azure-functions-host", "/azure-functions-host"]
21+
COPY --from=installer-env ["/workingdir/sample", "/home/site/wwwroot"]
22+
23+
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
24+
ENV HOME=/home
25+
ENV ASPNETCORE_URLS=http://+:80
26+
EXPOSE 80
27+
28+
CMD dotnet /azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost.dll

build.ps1

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function CrossGen([string] $runtime, [string] $publishTarget, [string] $privateS
4444

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

4949
$successfullDlls =@()
5050
$failedDlls = @()
@@ -87,8 +87,9 @@ function CrossGen([string] $runtime, [string] $publishTarget, [string] $privateS
8787
}
8888

8989

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

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

119-
function BuildPackages([string] $runtime<#, [bool] $isSelfContained#>) {
120+
function BuildPackages([bool] $isNoRuntime) {
121+
if($isNoRuntime) {
122+
BuildOutput ""
123+
CreateZips ".no-runtime"
124+
} else {
125+
BuildOutput "win-x86"
126+
BuildOutput "win-x64"
127+
128+
New-Item -Itemtype directory -path $buildOutput\publish.runtime\SiteExtensions\Functions
129+
Move-Item -Path $buildOutput\publish.win-x86\SiteExtensions\Functions -Destination $buildOutput\publish.runtime\SiteExtensions\Functions\32bit -Force
130+
Move-Item -Path $buildOutput\publish.win-x64\SiteExtensions\Functions -Destination $buildOutput\publish.runtime\SiteExtensions\Functions\64bit -Force
131+
Move-Item -Path $buildOutput\publish.runtime\SiteExtensions\Functions\32bit\applicationHost.xdt -Destination $buildOutput\publish.runtime\SiteExtensions\Functions -Force
132+
Remove-Item -Path $buildOutput\publish.runtime\SiteExtensions\Functions\64bit\applicationHost.xdt
133+
134+
CreateZips ".runtime"
135+
}
136+
}
137+
138+
139+
function BuildOutput([string] $runtime) {
120140
$runtimeSuffix = ""
121141
if (![string]::IsNullOrEmpty($runtime)) {
122142
$runtimeSuffix = ".$runtime"
@@ -128,17 +148,28 @@ function BuildPackages([string] $runtime<#, [bool] $isSelfContained#>) {
128148
$siteExtensionPath = "$publishTarget\SiteExtensions"
129149
$privateSiteExtensionPath = "$siteExtensionPath\Functions"
130150

131-
dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
132-
#dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -r $runtime -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
151+
if ($runtime -eq "win-x86" -or $runtime -eq "") {
152+
dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
153+
} else {
154+
# 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.
155+
dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -r $runtime -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release
156+
}
133157

134158
# replace IL dlls with crossgen dlls
135159
if (![string]::IsNullOrEmpty($runtime)) {
136160
CrossGen $runtime $publishTarget $privateSiteExtensionPath
137161
}
162+
}
138163

139-
# Do not put siffux to win-x86 zips names
140-
if ($runtime -eq "win-x86") {
141-
$runtimeSuffix = "";
164+
165+
function CreateZips([string] $runtimeSuffix) {
166+
$publishTarget = "$buildOutput\publish$runtimeSuffix"
167+
$siteExtensionPath = "$publishTarget\SiteExtensions"
168+
$privateSiteExtensionPath = "$siteExtensionPath\Functions"
169+
170+
# We do not want .runtime as suffix for zips
171+
if ($runtimeSuffix -eq ".runtime") {
172+
$runtimesuffix = "";
142173
}
143174

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

190-
#build win-x86 extensions
191-
BuildPackages "win-x86"
221+
#build win-x86 and win-x64 extension
222+
BuildPackages 0
192223
}

sample/HttpTrigger-Java/Function.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616
public class Function {
1717
/**
18-
* This function listens at endpoint "/api/hello". Two ways to invoke it using "curl" command in bash:
19-
* 1. curl -d "HTTP Body" {your host}/api/hello
18+
* This function listens at endpoint "/api/HttpTrigger-Java". Two ways to invoke it using "curl" command in bash:
19+
* 1. curl -d "HTTP Body" {your host}/api/HttpTrigger-Java
2020
* 2. curl {your host}/api/HttpTrigger-Java?name=HTTP%20Query
2121
*/
2222
@FunctionName("HttpTrigger-Java")
23-
public HttpResponseMessage<String> HttpTriggerJava(
24-
@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
23+
public HttpResponseMessage HttpTriggerJava(
24+
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
2525
final ExecutionContext context) {
2626
context.getLogger().info("Java HTTP trigger processed a request.");
2727

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

3232
if (name == null) {
33-
return request.createResponse(400, "Please pass a name on the query string or in the request body");
33+
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
3434
} else {
35-
return request.createResponse(200, "Hello " + name);
35+
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
3636
}
3737
}
3838
}
307 Bytes
Binary file not shown.
Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Security.Claims;
56
using System.Text;
7+
using System.Threading;
68
using System.Threading.Tasks;
79
using Microsoft.AspNetCore.Authentication;
810
using Microsoft.AspNetCore.Authentication.JwtBearer;
911
using Microsoft.Azure.Web.DataProtection;
1012
using Microsoft.Azure.WebJobs.Extensions.Http;
1113
using Microsoft.Azure.WebJobs.Script.Config;
14+
using Microsoft.Azure.WebJobs.Script.WebHost;
1215
using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authentication;
1316
using Microsoft.IdentityModel.Tokens;
1417
using static Microsoft.Azure.WebJobs.Script.EnvironmentSettingNames;
@@ -18,11 +21,23 @@ namespace Microsoft.Extensions.DependencyInjection
1821
{
1922
public static class ScriptJwtBearerExtensions
2023
{
24+
private static double _specialized = 0;
25+
2126
public static AuthenticationBuilder AddScriptJwtBearer(this AuthenticationBuilder builder)
2227
=> builder.AddJwtBearer(o =>
2328
{
2429
o.Events = new JwtBearerEvents()
2530
{
31+
OnMessageReceived = c =>
32+
{
33+
// Temporary: Tactical fix to address specialization issues. This should likely be moved to a token validator
34+
if (_specialized == 0 && !WebScriptHostManager.InStandbyMode && Interlocked.CompareExchange(ref _specialized, 1, 0) == 0)
35+
{
36+
o.TokenValidationParameters = CreateTokenValidationParameters();
37+
}
38+
39+
return Task.CompletedTask;
40+
},
2641
OnTokenValidated = c =>
2742
{
2843
c.Principal.AddIdentity(new ClaimsIdentity(new Claim[]
@@ -35,19 +50,32 @@ public static AuthenticationBuilder AddScriptJwtBearer(this AuthenticationBuilde
3550
return Task.CompletedTask;
3651
}
3752
};
38-
string defaultKey = Util.GetDefaultKeyValue();
39-
if (defaultKey != null)
53+
54+
o.TokenValidationParameters = CreateTokenValidationParameters();
55+
56+
if (!WebScriptHostManager.InStandbyMode)
4057
{
41-
// TODO: Once ScriptSettingsManager is gone, Audience and Issuer shouold be pulled from configuration.
42-
o.TokenValidationParameters = new TokenValidationParameters()
43-
{
44-
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(defaultKey)),
45-
ValidateAudience = true,
46-
ValidateIssuer = true,
47-
ValidAudience = string.Format(AdminJwtValidAudienceFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName)),
48-
ValidIssuer = string.Format(AdminJwtValidIssuerFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName))
49-
};
58+
// We're not in standby mode, so flag as specialized
59+
_specialized = 1;
5060
}
5161
});
62+
63+
private static TokenValidationParameters CreateTokenValidationParameters()
64+
{
65+
string defaultKey = Util.GetDefaultKeyValue();
66+
67+
var result = new TokenValidationParameters();
68+
if (defaultKey != null)
69+
{
70+
// TODO: Once ScriptSettingsManager is gone, Audience and Issuer shouold be pulled from configuration.
71+
result.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(defaultKey));
72+
result.ValidateAudience = true;
73+
result.ValidateIssuer = true;
74+
result.ValidAudience = string.Format(AdminJwtValidAudienceFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName));
75+
result.ValidIssuer = string.Format(AdminJwtValidIssuerFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName));
76+
}
77+
78+
return result;
79+
}
5280
}
5381
}

src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@
2424
<ItemGroup>
2525
<None Remove="applicationHost.xdt" />
2626
<None Remove="Resources\Functions\WarmUp\run.csx" />
27-
<None Remove="web.InProcess.xdt" />
27+
<None Remove="web.InProcess.win-x64.xdt" />
28+
<None Remove="web.InProcess.win-x86.xdt" />
2829
</ItemGroup>
2930
<ItemGroup>
3031
<Content Include="applicationHost.xdt">
3132
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3233
</Content>
33-
<Content Include="web.InProcess.xdt">
34+
<Content Include="web.InProcess.win-x64.xdt">
35+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
36+
</Content>
37+
<Content Include="web.InProcess.win-x86.xdt">
3438
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3539
</Content>
3640
</ItemGroup>

src/WebJobs.Script.WebHost/applicationHost.xdt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<site name="%XDT_SITENAME%" xdt:Locator="Match(name)">
66
<application path="/" xdt:Locator="Match(path)" xdt:Transform="Remove" />
77
<application path="/" applicationPool="%XDT_APPPOOLNAME%" xdt:Transform="Insert">
8-
<virtualDirectory path="/" physicalPath="%XDT_EXTENSIONPATH%" />
9-
</application>
8+
<virtualDirectory path="/" physicalPath="%XDT_EXTENSIONPATH%\%XDT_BITNESS%" />
9+
</application>
1010
</site>
1111
</sites>
1212
</system.applicationHost>
1313
<system.webServer>
1414
<globalModules>
1515
<add name="AspNetCoreModuleV2" xdt:Locator="Match(name)" xdt:Transform="Remove" />
16-
<add name="AspNetCoreModuleV2" image="%XDT_EXTENSIONPATH%\ancm\aspnetcoreV2.dll" xdt:Transform="Insert" />
16+
<add name="AspNetCoreModuleV2" image="%XDT_EXTENSIONPATH%\%XDT_BITNESS%\ancm\aspnetcoreV2.dll" xdt:Transform="Insert" />
1717
</globalModules>
1818
</system.webServer>
1919
<location path="%XDT_SITENAME%" xdt:Locator="Match(path)" xdt:Transform="InsertIfMissing">
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
3+
<system.webServer>
4+
<handlers>
5+
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" xdt:Transform="Replace" xdt:Locator="Match(name)" />
6+
</handlers>
7+
<aspNetCore processPath=".\Microsoft.Azure.WebJobs.Script.WebHost.exe" arguments="" stdoutLogEnabled="false" hostingModel="inprocess" xdt:Transform="Replace" />
8+
</system.webServer>
9+
</configuration>
File renamed without changes.

src/WebJobs.Script/WebJobs.Script.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<NoWarn>NU1701</NoWarn>
3232
</PackageReference>
3333
<PackageReference Include="Microsoft.Azure.AppService.Proxy.Client" Version="2.0.5350001-beta-fc119b98" />
34-
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.1.0-beta7" />
34+
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.1.0-beta8" />
3535
<PackageReference Include="Microsoft.Azure.Functions.NodeJsWorker" Version="1.0.0-beta3" />
3636
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta7-11351" />
3737
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.0-beta7-10629" />

0 commit comments

Comments
 (0)