Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fsharp/FAKE
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Aug 24, 2015
2 parents 6c12159 + 290622e commit f6f51a5
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 192 deletions.
2 changes: 1 addition & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let release = LoadReleaseNotes "RELEASE_NOTES.md"
let packages =
["FAKE.Core",projectDescription
"FAKE.Gallio",projectDescription + " Extensions for Gallio"
"FAKE.IIS",projectDescription + " Extensions for IIS"
"FAKE.IIS",projectDescription + " Extensions for IIS Administration"
"FAKE.SQL",projectDescription + " Extensions for SQL Server"
"FAKE.Experimental",projectDescription + " Experimental Extensions"
"FAKE.Deploy.Lib",projectDescription + " Extensions for FAKE Deploy"
Expand Down
35 changes: 35 additions & 0 deletions help/iis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# FAKE.IIS

FAKE.IIS provides extensions around the Microsoft.Web.Administration library to provide clean interfaces to easily configure IIS Sites and Application Pools.

## Creating a ApplicationPool and Site
#r "Fake.IIS.dll"
#load "IISHelper.fs"

open Fake.IISHelper

let siteName = "fake.site"
let appPoolName = "fake.appPool"
let port = ":80:"
let path = @"C:\inetpub\wwwroot"

let siteConfig = SiteConfig(siteName, port, path, appPoolName)
let appPoolConfig = ApplicationPoolConfig(appPoolName)

(IIS
(Site siteConfig)
(ApplicationPool appPoolConfig)
(None))

## Deleting an Application Pool and Site
#r "Fake.IIS.dll"

#load "IISHelper.fs"

open Fake.IISHelper

let siteName = "fake.site"
let appPoolName = "fake.appPool"

deleteSite siteName
deleteApplicationPool appPool
2 changes: 1 addition & 1 deletion help/templates/template.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<li><a href="@Root/watch.html">File Watcher</a></li>
<li class="divider"></li>
<li><a href="@Root/deploy.html">Fake.Deploy</a></li>

<li><a href="@Root/iis.html">Fake.ISS</a></li>
<li class="nav-header">Reference</li>

<li><a href="@Root/apidocs/index.html">API Reference</a></li>
Expand Down
3 changes: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nuget FSharp.Formatting
nuget FSharp.Formatting.CommandTool
nuget SourceLink.Fake
nuget RavenDB.Server
nuget serilog.sinks.nlog
nuget xunit.runners
nuget UnionArgParser
nuget Nancy.Authentication.Stateless
Expand Down Expand Up @@ -37,4 +38,4 @@ nuget xunit.runners ~> 1.9
nuget Newtonsoft.Json
nuget Microsoft.AspNet.Razor 2.0.30506
nuget Microsoft.AspNet.WebPages 2.0.30506
nuget HashLib
nuget HashLib
5 changes: 5 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ NUGET
Microsoft.AspNet.Razor (>= 2.0.30506) - framework: >= net40
Nancy (>= 1.2.0)
Newtonsoft.Json (7.0.1)
NLog (4.0.1)
NuGet.CommandLine (2.8.6)
NuGet.Core (2.8.6)
Microsoft.Web.Xdt (>= 2.1.0)
RavenDB.Client (2.5.2962)
Microsoft.CompilerServices.AsyncTargetingPack
RavenDB.Server (3.0.3690)
Serilog (1.5.9)
Serilog.Sinks.NLog (1.5.4)
NLog (>= 3.0.0.0)
Serilog (>= 1.4.204 < 2.0)
SourceLink.Fake (1.0.0)
SSH.NET (2013.4.7)
System.Web.Razor.Unofficial (2.0.2)
Expand Down
35 changes: 28 additions & 7 deletions src/app/Fake.Deploy/AppConfig.fs
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
module Fake.AppConfig

open System
open System.IO
open System.Configuration
open System.Collections.Generic

type Authorization =
| Off
| On

let HasKey name =
ConfigurationManager.AppSettings.AllKeys
|> Seq.exists(fun key -> key = name)
let mutable appSettings = ConfigurationManager.AppSettings

let HasKey name =
ConfigurationManager.AppSettings.AllKeys
|> Seq.exists (fun key -> key = name)

let Key<'T>(name : string) =
let value = ConfigurationManager.AppSettings.[name]
let value = appSettings.[name]
Convert.ChangeType(value, typedefof<'T>) :?> 'T

let WorkDirectory =
match (HasKey "WorkDirectory") with
| false -> "."
| true -> Key<string> "WorkDirectory"
|> Path.GetFullPath

let LogDirectory =
match (HasKey "LogDirectory") with
| false -> WorkDirectory
| true ->
let dir = Key<string> "LogDirectory"
if dir.StartsWith("~") then dir.Replace("~", WorkDirectory)
else dir
|> Path.GetFullPath

let AuthorizedKeysFile = Key<string> "AuthorizedKeysFile"

let Authorization =
let Authorization =
let keyName = "Authorization"
match (HasKey keyName) with
| false -> Off
| true ->
| true ->
match (Key<string> keyName).ToLower() with
| "on" -> On
| "off" -> Off
| x -> failwith (sprintf "'%s' is not a valid value for Authorization" x)

let ServerName = Key<string> "ServerName"

let Port = Key<string> "Port"
77 changes: 44 additions & 33 deletions src/app/Fake.Deploy/DeploymentAgent.fs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
module Fake.DeploymentAgent

open System
open System.IO
open System.Diagnostics
open Fake
open Fake.DeploymentHelper
open Fake.DeployAgentModule
open Nancy
open Nancy.Hosting.Self
open Nancy.Security

let mutable private logger : string * EventLogEntryType -> unit = ignore

let getBodyFromNancyRequest (ctx : Nancy.Request) =
use ms = new MemoryStream()
ctx.Body.CopyTo ms
Expand Down Expand Up @@ -39,11 +35,15 @@ let runDeployment workDir (ctx : Nancy.Request) =
let response = doDeployment scriptFile scriptArguments
match response with
| FakeDeployAgentHelper.Success _ ->
logger (sprintf "Successfully deployed %s %s" package.Id package.Version, EventLogEntryType.Information)
Logger.info "Successfully deployed %s %s" package.Id package.Version
| FakeDeployAgentHelper.Failure failure ->
Logger.error "Deployment failed of %s %s failed\r\nDetails:\r\n%A" package.Id package.Version response
Logger.info "Failure: %A" failure.Exception
Logger.info "Messages for failed deploy:"
failure.Messages |> Seq.iter(fun m -> Logger.info "Deploy message: %A IsError:%b %s" m.Timestamp m.IsError m.Message )
| response ->
logger
(sprintf "Deployment failed of %s %s failed\r\nDetails:\r\n%A" package.Id package.Version response,
EventLogEntryType.Information)
Logger.error "Deployment failed of %s %s failed\r\nDetails:\r\n%A" package.Id package.Version response

response |> Json.serialize


Expand All @@ -52,9 +52,7 @@ let createNancyHost uri =
config.UrlReservations.CreateAutomatically <- true
new NancyHost(config, uri)


let mutable workDir = Path.GetDirectoryName(Uri(typedefof<FakeModule>.Assembly.CodeBase).LocalPath)

let mutable workDir = AppConfig.WorkDirectory

type DeployAgentModule() as http =
inherit FakeModule("/fake")
Expand All @@ -64,38 +62,51 @@ type DeployAgentModule() as http =
|> FakeDeployAgentHelper.DeploymentResponse.QueryResult
|> http.Response.AsJson

let logged f =
try
f()
with
| ex ->
Logger.errorEx ex "%s" ex.Message
reraise()

do
http.RequiresAuthentication()


http.post "/" (fun _ ->
runDeployment workDir http.Request)

http.get "/deployments/" (fun _ ->
let status = http.Request.Query ?> "status"
match status with
| "active" -> getActiveReleases workDir
| _ -> getAllReleases workDir
|> createResponse
logged (fun () -> runDeployment workDir http.Request))

http.get "/deployments/" (fun _ ->
logged (fun () ->
let status = http.Request.Query ?> "status"
match status with
| "active" -> getActiveReleases workDir
| _ -> getAllReleases workDir
|> createResponse
)
)

http.get "/deployments/{app}/" (fun p ->
let app = p ?> "app"
let status = http.Request.Query ?> "status"
match status with
| "active" ->
getActiveReleaseFor workDir app
|> Seq.singleton
| _ -> getAllReleasesFor workDir app
|> createResponse
logged (fun () ->
let app = p ?> "app"
let status = http.Request.Query ?> "status"
match status with
| "active" ->
getActiveReleaseFor workDir app
|> Seq.singleton
| _ -> getAllReleasesFor workDir app
|> createResponse
)
)

http.put "/deployments/{app}" (fun p ->
let version = p ?> "version"
let app = p ?> "app"
let result = rollbackTo workDir app version
http.Response
.AsJson result
logged (fun () ->
let version = p ?> "version"
let app = p ?> "app"
let result = rollbackTo workDir app version
http.Response
.AsJson result
)
)

http.get "/statistics/" (fun _ -> getStatistics() |> http.Response.AsJson)
Loading

0 comments on commit f6f51a5

Please sign in to comment.