Skip to content

Commit

Permalink
upgrading from preview to stable azure functions v2
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Jul 9, 2019
1 parent ae7ee69 commit 4de8cda
Show file tree
Hide file tree
Showing 20 changed files with 544 additions and 521 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/azure-functions/dotnet

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils 2>&1

RUN apt-get -y install git procps lsb-release

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

ENV SHELL /bin/bash
6 changes: 6 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Blazor Sandbox",
"dockerFile": "Dockerfile",
"appPort": 9000,
"extensions": ["ms-vscode.csharp"]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
obj
node_modules
.vs
.vs
.ionide
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-vscode.csharp"
]
}
21 changes: 3 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// {
// "name": ".NET Core Launch (console)",
// "type": "coreclr",
// "request": "launch",
// "preLaunchTask": "build",
// "program": "${workspaceFolder}/TicTacToe.Tests/bin/Debug/netcoreapp2.0/TicTacToe.Tests.dll",
// "args": [],
// "cwd": "${workspaceFolder}",
// "console": "internalConsole",
// "stopAtEntry": false,
// "internalConsoleOptions": "openOnSessionStart"
// },
{
"name": ".NET Core Attach",
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"FSharp.fsacRuntime": "netcore",
"azureFunctions.projectRuntime": "~2",
"azureFunctions.projectLanguage": "C#",
"azureFunctions.deploySubpath": "DDDApi.Functions/bin/Release/netcoreapp2.1/publish",
"azureFunctions.preDeployTask": "publish",
"debug.internalConsoleOptions": "neverOpen",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
}
100 changes: 48 additions & 52 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,57 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
{
"label": "clean",
"command": "dotnet clean",
"type": "shell",
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/DDDApi.Functions"
}
},
"problemMatcher": "$msCompile",
"windows": {
"options": {
"shell": {
"executable": "powershell.exe"
{
"label": "build",
"command": "dotnet build",
"type": "shell",
"dependsOn": "clean",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/DDDApi.Functions"
}
}
}
},
{
"label": "publish",
"command": "dotnet publish",
"dependsOn": "build",
"type": "shell",
"problemMatcher": [],
"windows": {
"options": {
"shell": {
"executable": "powershell.exe"
},
{
"label": "clean release",
"command": "dotnet clean --configuration Release",
"type": "shell",
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/DDDApi.Functions"
}
}
}
},
{
"label": "run func",
"command": "cd DDDApi.Functions;func start --script-root bin/debug/netstandard2.0/publish",
"dependsOn": "publish",
"type": "shell",
"problemMatcher": [],
"windows": {
"options": {
"shell": {
"executable": "powershell.exe"
},
{
"label": "publish",
"command": "dotnet publish --configuration Release",
"type": "shell",
"dependsOn": "clean release",
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/DDDApi.Functions"
}
}
},
{
"type": "func",
"dependsOn": "build",
"options": {
"cwd": "${workspaceFolder}/DDDApi.Functions/bin/Debug/netcoreapp2.1"
},
"command": "host start",
"isBackground": true,
"problemMatcher": "$func-watch"
}
},
// {
// "label": "run test",
// "command": "dotnet run --project 'TicTacToe.Tests/TicTacToe.Tests.fsproj'",
// "type": "shell",
// "problemMatcher": []
// }
]
}
}
2 changes: 1 addition & 1 deletion DDDApi.Functions/AgendaFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module AgendaFunctions =
OkObjectResult(agendaResponse) :> IActionResult

[<FunctionName("Get_agenda_for_year")>]
let getAgenda([<HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Get-Agenda/{year}")>] req: HttpRequest,
let getAgenda([<HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "api/v1/Get-Agenda/{year}")>] req: HttpRequest,
[<Table("Sessions")>]sessionsTable: CloudTable,
[<Table("Agenda")>]agendaTable: CloudTable,
year: string) =
Expand Down
12 changes: 8 additions & 4 deletions DDDApi.Functions/DDDApi.Functions.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DDDApi\DDDApi.fsproj" />
Expand All @@ -12,9 +13,9 @@
<Content Include="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="proxies.json">
<!-- <Content Include="proxies.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</Content> -->
<Content Include=".azurefunctions/swagger/swagger.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -28,6 +29,9 @@
<ItemGroup>
<PackageReference Include="FSharp.Azure.Storage" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.14" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.7.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.6" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion DDDApi.Functions/DocumentationFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open System.IO
module DocumentationFunctions =

[<FunctionName("Get_Swagger")>]
let getSwagger([<HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Get-Swagger")>] req: HttpRequest,
let getSwagger([<HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "api/v1/Get-Swagger")>] req: HttpRequest,
context: ExecutionContext) =

let path = Path.Combine(context.FunctionDirectory, ".azurefunctions", "swagger", "swagger.json")
Expand Down
4 changes: 2 additions & 2 deletions DDDApi.Functions/SessionFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open FSharp.Azure.Storage.Table

module SessionFunctions =
[<FunctionName("Get_sessions_for_a_year")>]
let getSessions([<HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Get-Sessions/{year}")>] req: HttpRequest,
let getSessions([<HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "api/v1/Get-Sessions/{year}")>] req: HttpRequest,
[<Table("Sessions")>]sessionsTable: CloudTable,
year: string) =
let pk = sprintf "Session-%s" year
Expand All @@ -32,7 +32,7 @@ module SessionFunctions =
} |> Async.StartAsTask

[<FunctionName("Get_session_by_id")>]
let getSession([<HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Get-Session/{id}")>] req: HttpRequest,
let getSession([<HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "api/v1/Get-Session/{id}")>] req: HttpRequest,
[<Table("Sessions")>]sessionsTable: CloudTable,
id: string) =
async {
Expand Down
12 changes: 6 additions & 6 deletions DDDApi.Functions/SessionizeFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ open Microsoft.Azure.WebJobs
open Microsoft.WindowsAzure.Storage.Table
open DDDApi
open DDDApi.SessionizeApi
open Microsoft.Azure.WebJobs.Host
open FSharp.Azure.Storage.Table
open Microsoft.Extensions.Logging

module SessionizeFunctions =
[<FunctionName("Download_Sessionzie_data")>]
let downloadSessionize([<TimerTrigger("0 5 * * * *")>]timer: TimerInfo,
[<Table("Session")>]sessionsSource: CloudTable,
context: ExecutionContext,
log: TraceWriter) =
let config = (new ConfigurationBuilder())
log: ILogger) =
let config = (ConfigurationBuilder())
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", true, true)
.AddEnvironmentVariables()
.Build()

let apiKey = config.["Sessionize.ApiKey"]
async {
let! sessionize = SessionizeApi.downloadSessionize apiKey
let! sessionize = downloadSessionize apiKey

let makeSession' = SessionizeApi.makeSession sessionize.Speakers sessionize.Categories
let makeSession' = makeSession sessionize.Speakers sessionize.Categories

let remoteSessions = sessionize.Sessions
|> Array.map makeSession'
Expand All @@ -38,7 +38,7 @@ module SessionizeFunctions =
(addNewSessions log remoteSessions existingSessions sessionsSource) |> ignore
(updateSessions log remoteSessions existingSessions sessionsSource) |> ignore

log.Info("Writing to queue")
log.LogInformation("Writing to queue")

return ignore
} |> Async.StartAsTask
9 changes: 4 additions & 5 deletions DDDApi.Functions/VotingFunctions.fs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
namespace DDDApi.Functions
open DDDApi

open System.Net.Http
open Microsoft.WindowsAzure.Storage.Table
open Newtonsoft.Json
open Microsoft.AspNetCore.Mvc
open Microsoft.AspNetCore.Http
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Extensions.Http
open Microsoft.Azure.WebJobs.Host
open System
open System.IO
open DDDApi.Voting
open FSharp.Azure.Storage.Table
open DDDApi.azureTableUtils
open Microsoft.Extensions.Logging

type UserVote = { TicketNumber: string
SessionIds: array<string> }
Expand All @@ -24,14 +23,14 @@ module VotingFunctions =
ip.ToString()

[<FunctionName("Vote_for_session")>]
let saveVote([<HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Save-Vote/{year}")>] req: HttpRequest,
let saveVote([<HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "api/v1/Save-Vote/{year}")>] req: HttpRequest,
[<Table("Sessions")>]sessionsSource: CloudTable,
[<Table("Votes")>]votesTable: CloudTable,
year: string,
log: TraceWriter) =
log: ILogger) =
async {
let now = DateTimeOffset.Now
log.Info(sprintf "Looking for votes in %s" year)
log.LogInformation(sprintf "Looking for votes in %s" year)

match validVotingPeriod now year with
| true ->
Expand Down
6 changes: 2 additions & 4 deletions DDDApi.Functions/host.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"http": {
"routePrefix": "api"
}
}
"version": "2.0"
}
6 changes: 4 additions & 2 deletions DDDApi.Functions/local.settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
},
"ConnectionStrings": {},
"Sessionize": {
"ApiKey": ""
}
}
}
Loading

0 comments on commit 4de8cda

Please sign in to comment.