Skip to content

Commit

Permalink
Move to FAKE for kudu stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacabraham committed Apr 7, 2016
1 parent def6df1 commit dfcefa1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 52 deletions.
57 changes: 7 additions & 50 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,13 @@
#r @"FakeLib.dll"

open Fake
open Fake.Azure
open System
open System.IO

Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let solutionFile = "Demonstrator.sln"

module Kudu =
/// Location where staged outputs should go before before synced up to the site.
let deploymentTemp = getBuildParamOrDefault "DEPLOYMENT_TEMP" (Path.GetTempPath() + "kudutemp")
/// Location where synced outputs should be deployed to.
let deploymentTarget = getBuildParamOrDefault "DEPLOYMENT_TARGET" (Path.GetTempPath() + "kudutarget")
/// Used by KuduSync for tracking and diffing deployments.
let nextManifestPath = getBuildParam "NEXT_MANIFEST_PATH"
/// Used by KuduSync for tracking and diffing deployments.
let previousManifestPath = getBuildParam "PREVIOUS_MANIFEST_PATH"
/// The path to the KuduSync application.
let kuduPath = (getBuildParamOrDefault "GO_WEB_CONFIG_TEMPLATE" ".") |> directory

/// The different types of web jobs.
type WebJobType = Scheduled | Continuous

// Some initial cleanup / prep
do
CreateDir deploymentTemp
CreateDir deploymentTarget
CleanDir deploymentTemp

/// Stages a set of files into the temp deployment area, ready from deployment into the website.
let stageWebsite from excludes =
let copied = FileHelper.CopyRecursive from deploymentTemp true
copied
|> Seq.filter(fun file -> excludes |> Seq.exists(fun e -> e file))
|> Seq.iter File.Delete

/// Stages a webjob into the temp deployment area, ready for deployment into the website as a webjob.
let stageWebJob webJobType webjobName files =
let webJobType = match webJobType with Scheduled -> "scheduled" | Continuous -> "continous"
let webjobPath = sprintf @"%s\app_data\jobs\%s\%s\" deploymentTemp webJobType webjobName
CreateDir webjobPath
files |> FileHelper.CopyFiles webjobPath

/// Synchronises all stages files from the temporary deployment to the actual deployment, removing
/// any obsolete files, updating changed files and adding new files.
let kuduSync() =
let succeeded, output =
ProcessHelper.ExecProcessRedirected(fun psi ->
psi.FileName <- combinePaths kuduPath "kudusync.cmd"
psi.Arguments <- sprintf """-v 50 -f "%s" -t "%s" -n "%s" -p "%s" -i ".git;.hg;.deployment;deploy.cmd""" deploymentTemp deploymentTarget nextManifestPath previousManifestPath)
(TimeSpan.FromMinutes 5.)
output |> Seq.iter (fun cm -> printfn "%O: %s" cm.Timestamp cm.Message)
if not succeeded then failwith "Error occurred during Kudu Sync deployment."

Target "BuildSolution" (fun _ ->
solutionFile
|> MSBuildHelper.build (fun defaults ->
Expand All @@ -65,14 +20,16 @@ Target "BuildSolution" (fun _ ->
|> ignore)

Target "StageWebsiteAssets" (fun _ ->
let p = Path.GetFullPath @"src\webhost"
let exclusions =
let blacklist =
[ "typings"
".fs"
".config"
".references"
"tsconfig.json" ] |> Seq.map(fun path (f:string) -> f.Contains path)
Kudu.stageWebsite p exclusions)
"tsconfig.json" ]
let shouldInclude (file:string) =
blacklist
|> Seq.forall(not << file.Contains)
Kudu.stageFolder (Path.GetFullPath @"src\webhost") shouldInclude)

Target "StageWebJob" (fun _ ->
[ @"src\Sample.fsx" ]
Expand Down
6 changes: 4 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ nuget Microsoft.Owin.Host.SystemWeb
nuget Microsoft.Owin.StaticFiles
nuget OwinHost

nuget FAKE

// Suave
nuget Suave

// Application Insights
nuget Microsoft.ApplicationInsights.TraceListener content:none
nuget Microsoft.ApplicationInsights.WindowsServer content:none

// Some data analysis packages
// Football
nuget Deedle
nuget FSharp.Data

// Enigma code
// Enigma
github isaacabraham/enigma src/Enigma/Domain.fs
github isaacabraham/enigma src/Enigma/Logic.fs

Expand Down
1 change: 1 addition & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ NUGET
remote: https://www.nuget.org/api/v2
specs:
Deedle (1.2.4)
FAKE (4.23.4)
FSharp.Core (4.0.0.1)
FSharp.Data (2.2.5)
Microsoft.ApplicationInsights (2.0) - content: none
Expand Down

0 comments on commit dfcefa1

Please sign in to comment.