What’s Suave.io ?
If your first question is “What’s Suave.io” or “Why would I use it ?” then I suggest you to read those slides
Fake is a DSL permitting to write advanced automated builds in FSharp. It can be used by beginners in FSharp because the DSL can hide some FSharp code comlexity. We can define multiple targets like in a Makefile.
What’s FAKE Deploy ?
FAKE Deploy is an agent like MSDeploy installable on your servers. His role is to receive your packaged server applications and install it running a FSHARP deployment script.
Why should I use it instead of another tool ?
- FAKE is a DSL simplifying FSharp writing.
- You can use every .Net library in your build or deployment scripts.
- You have a really great feedback and testability to write your scripts.
Installing FAKE Deploy agent
Everything is documented here, it’s quite simple.
Open a PowerShell as Administrator:
C:\fake_deploy\FAKE\tools\Fake.Deploy.exe.config and set
FAKE Deploy Agent windows service.
Writing build script
We will work on this project. MailCheckerRestApi is a REST Api checking emails validities connecting to their SMTP and starting a sending operation.
Build Script is versionned here
Project directory structure is:
“Deployment” folder contains scripts and resources used by agent on server to install service. Application is using Topshelf for his Windows Service hosting.
- deploy.nuspec is a basic NuGet package template. Agent is waiting for a package upload.
- deployService.fsx is the script ran by the FAKE Deploy agent.
- refs.fs contains libraries includes. It will be replaced in the package to respect futur directory three structure.
- ServiceManifest.json contains configurations for deployment environment. (Local, Preprod, Prod, etc …)
So now look at the build.fsx …
packFakeDeploy () function is packaging the compiled application in the nuget
uploadPackage function run
Fake.Deploy.exe to upload compiled application
Then we can create targets dedicated to a local deployment for example:
Writing deployment script
deployService.fsx I used FAKE because there are a lot of helpers like
I used a simple JSON typeprovider to parse
addUrlAcl is creating Url ACL to authorize Suave to create a HTTP endpoint with the service impersonation.
It is really cool to write this script in FSharp because it’s easy to test and debug. We don’t need to upload the entire package to test a change (a simple ALT + ENTER in the IDE is sufficient)
Test the service install
Clone project and open your powershell as Administrator.
Using it on a production server
When you install an agent on a production server, you should read
Security section of http://fsharp.github.io/FAKE/deploy.html to enable authorization keys.
I suggest to restrict IP access to your continuous delivery server.