Skip to content

Commit

Permalink
Add FAKE 5 Azure modules
Browse files Browse the repository at this point in the history
  • Loading branch information
panesofglass committed Mar 6, 2018
1 parent 77700f4 commit a94b9b1
Show file tree
Hide file tree
Showing 19 changed files with 680 additions and 36 deletions.
130 changes: 95 additions & 35 deletions Fake.sln

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ let dotnetAssemblyInfos =
[ "dotnet-fake", "Fake dotnet-cli command line tool"
"Fake.Api.Slack", "Slack Integration Support"
"Fake.Api.GitHub", "GitHub Client API Support via Octokit"
"Fake.Azure.CloudServices", "FAKE - F# Make Azure Cloud Services Support"
"Fake.Azure.Emulators", "FAKE - F# Make Azure Emulators Support"
"Fake.Azure.Kudu", "FAKE - F# Make Azure Kudu Support"
"Fake.Azure.WebJobs", "FAKE - F# Make Azure Web Jobs Support"
"Fake.Core.Context", "Core Context Infrastructure"
"Fake.Core.Environment", "Environment Detection"
"Fake.Core.Process", "Starting and managing Processes"
Expand Down
17 changes: 17 additions & 0 deletions src/app/Fake.Azure.CloudServices/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Azure Cloud Services Support")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Azure Cloud Services Support"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0"
let [<Literal>] AssemblyFileVersion = "5.0.0"
96 changes: 96 additions & 0 deletions src/app/Fake.Azure.CloudServices/CloudServices.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/// Contains tasks to package Azure Cloud Services.
module Fake.Azure.CloudServices

open System.IO
open Fake.Core
open Fake.Core.Process
open Fake.IO
open Fake.IO.Globbing.Operators

/// Configuration details for packaging cloud services.
[<CLIMutable>]
type PackageCloudServiceParams =
{ /// The name of the Cloud Service.
CloudService : string
/// The name of the role in the service.
WorkerRole : string
/// The SDK version to use e.g. 2.2. If None, the latest available version is used.
SdkVersion : float option
/// The output path for the .cspkg.
OutputPath : string option }

let DefaultCloudServiceParams = { CloudService = ""; WorkerRole = ""; SdkVersion = None; OutputPath = None }

module VmSizes =
type VmSize = | VmSize of size:string
let ExtraSmall = VmSize "ExtraSmall"
let Small = VmSize "Small"
let Medium = VmSize "Medium"
let Large = VmSize "Large"
let ExtraLarge = VmSize "ExtraLarge"
let A5 = VmSize "A5"
let A6 = VmSize "A6"
let A7 = VmSize "A7"
let A8 = VmSize "A8"
let A9 = VmSize "A9"

/// Modifies the size of the Worker Role in the csdef.
let ModifyVMSize (VmSizes.VmSize vmSize) cloudService =
let csdefPath = sprintf @"%s\ServiceDefinition.csdef" cloudService
csdefPath
|> File.ReadAllText
|> Xml.Doc
|> Xml.XPathReplaceNS
"/svchost:ServiceDefinition/svchost:WorkerRole/@vmsize"
vmSize
[ "svchost", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" ]
|> fun doc -> doc.Save csdefPath

/// Packages a cloud service role into a .cspkg, ready for deployment.
let PackageRole packageCloudServiceParams =
let csPack =
let sdkRoots =
[ @"C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\"
@"C:\Program Files\Microsoft SDKs\Azure\.NET SDK\" ]

let availableCsPacks =
sdkRoots
|> Seq.collect(fun sdkRoot ->
!! (sdkRoot + @"**\cspack.exe")
|> Seq.filter(fun path -> path.Substring(sdkRoot.Length).StartsWith "v")
|> Seq.map(fun path -> sdkRoot, path))
|> Seq.map(fun (sdkRoot, cspackPath) ->
let version =
cspackPath.Substring(sdkRoot.Length).Split '\\'
|> Seq.head
|> fun version -> version.Substring 1
|> float
version, sdkRoot, cspackPath)
|> Seq.cache

match packageCloudServiceParams.SdkVersion with
| Some version ->
availableCsPacks
|> Seq.tryFind(fun (csPackVersion,_,_) -> csPackVersion = version)
|> Option.map(fun (_,_,csPackFileInfo) -> csPackFileInfo)
| None ->
availableCsPacks
|> Seq.sortBy(fun (v,_,_) -> -v)
|> Seq.map(fun (_,_,csPackFileInfo) -> csPackFileInfo)
|> Seq.tryFind(fun _ -> true)

csPack
|> Option.map(fun csPack ->
packageCloudServiceParams.OutputPath |> Option.iter(fun path -> Directory.ensure <| DirectoryInfo path)
let outputFileArg =
packageCloudServiceParams.OutputPath
|> Option.map(fun path -> Path.Combine(path, (packageCloudServiceParams.CloudService + ".cspkg")))
|> Option.map(sprintf "/out:%s")
|> defaultArg
<| ""

shellExec
{ defaultParams with
Program = csPack
CommandLine = sprintf @"%s\ServiceDefinition.csdef /role:%s;%s\bin\release;%s.dll %s" packageCloudServiceParams.CloudService packageCloudServiceParams.WorkerRole packageCloudServiceParams.WorkerRole packageCloudServiceParams.WorkerRole outputFileArg
Args = [] })
26 changes: 26 additions & 0 deletions src/app/Fake.Azure.CloudServices/Fake.Azure.CloudServices.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<AssemblyName>Fake.Azure.CloudServices</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);FX_NO_REMOTING;USE_ASYNC_LOCAL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="CloudServices.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" />
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" />
<ProjectReference Include="..\Fake.Core.Xml\Fake.Core.Xml.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
12 changes: 12 additions & 0 deletions src/app/Fake.Azure.CloudServices/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
group netcore

FSharp.Core
NETStandard.Library
System.Diagnostics.FileVersionInfo
System.Diagnostics.Process
System.IO.FileSystem.Watcher
System.Xml.XDocument
System.Xml.XPath
System.Xml.XPath.XDocument
System.Xml.XPath.XmlDocument
System.Xml.ReaderWriter
17 changes: 17 additions & 0 deletions src/app/Fake.Azure.Emulators/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Azure Emulators Support")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Azure Emulators Support"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0"
let [<Literal>] AssemblyFileVersion = "5.0.0"
85 changes: 85 additions & 0 deletions src/app/Fake.Azure.Emulators/Emulators.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/// Contains tasks to control the local Azure Emulator
module Fake.Azure.Emulators

open System
open Fake.Core
open Fake.IO
open Fake.IO.FileSystemOperators

/// A type for the controlling parameter
[<CLIMutable>]
type private AzureEmulatorParams = {
StorageEmulatorToolPath:Lazy<string>
CSRunToolPath:string
TimeOut:TimeSpan
}

/// Base path for getting tools from Microsoft SDKs
let msSdkBasePath = Environment.ProgramFilesX86 @@ "Microsoft SDKs"

/// The default parameters for Azure emulators
let private AzureEmulatorDefaults = {
StorageEmulatorToolPath =
lazy
let path = msSdkBasePath @@ @"\Azure\Storage Emulator\AzureStorageEmulator.exe"
if File.exists path then path
else failwith (sprintf "Unable to locate Azure Storage Emulator at %s" path)
CSRunToolPath = "\"C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun.exe\""
TimeOut = TimeSpan.FromMinutes 5.
}

let private (|StorageAlreadyStarted|StorageAlreadyStopped|Ok|OtherError|) = function
| 0 -> Ok
| -5 -> StorageAlreadyStarted
| -6 -> StorageAlreadyStopped
| _ -> OtherError

/// Stops the storage emulator
let StopStorageEmulator = (fun _ ->
match Process.Exec (fun info ->
{ info with
FileName = AzureEmulatorDefaults.StorageEmulatorToolPath.Value
Arguments = "stop" }) AzureEmulatorDefaults.TimeOut with
| Ok | StorageAlreadyStopped -> ()
| _ -> failwithf "Azure Emulator Failure on stop Storage Emulator"
)

/// Starts the storage emulator
let StartStorageEmulator = (fun _ ->
match Process.Exec (fun info ->
{ info with
FileName = AzureEmulatorDefaults.StorageEmulatorToolPath.Value
Arguments = "start" }) AzureEmulatorDefaults.TimeOut with
| Ok | StorageAlreadyStarted -> ()
| _ -> failwithf "Azure Emulator Failure on start Storage Emulator"
)

/// Stops the compute emulator
let StopComputeEmulator = (fun _ ->
if 0 <> Process.Exec (fun info ->
{ info with
FileName = AzureEmulatorDefaults.CSRunToolPath
Arguments = "/devfabric:shutdown" }) AzureEmulatorDefaults.TimeOut
then
failwithf "Azure Emulator Failure on stop Fabric Emulator"
)

/// Starts the compute emulator
let StartComputeEmulator = (fun _ ->
if 0 <> Process.Exec (fun info ->
{ info with
FileName = AzureEmulatorDefaults.CSRunToolPath
Arguments = "/devfabric:start" }) AzureEmulatorDefaults.TimeOut
then
failwithf "Azure Emulator Failure on start Fabric Emulator"
)

/// Resets the devstore (BLOB, Queues and Tables)
let ResetDevStorage = (fun _ ->
if 0 <> Process.Exec (fun info ->
{ info with
FileName = AzureEmulatorDefaults.StorageEmulatorToolPath.Value
Arguments = "clear all" }) AzureEmulatorDefaults.TimeOut
then
failwithf "Azure Emulator Failure on reset Dev Storage"
)
26 changes: 26 additions & 0 deletions src/app/Fake.Azure.Emulators/Fake.Azure.Emulators.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<AssemblyName>Fake.Azure.Emulators</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);FX_NO_REMOTING;USE_ASYNC_LOCAL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Emulators.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" />
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" />
<ProjectReference Include="..\Fake.Core.Trace\Fake.Core.Trace.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
7 changes: 7 additions & 0 deletions src/app/Fake.Azure.Emulators/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
group netcore

FSharp.Core
NETStandard.Library
System.Diagnostics.FileVersionInfo
System.Diagnostics.Process
System.IO.FileSystem.Watcher
17 changes: 17 additions & 0 deletions src/app/Fake.Azure.Kudu/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Azure Kudu Support")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Azure Kudu Support"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0"
let [<Literal>] AssemblyFileVersion = "5.0.0"
26 changes: 26 additions & 0 deletions src/app/Fake.Azure.Kudu/Fake.Azure.Kudu.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<AssemblyName>Fake.Azure.Kudu</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);FX_NO_REMOTING;USE_ASYNC_LOCAL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Kudu.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" />
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" />
<ProjectReference Include="..\Fake.Core.Trace\Fake.Core.Trace.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
Loading

0 comments on commit a94b9b1

Please sign in to comment.