Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add suaveazurebootstrapper #31

Merged
merged 1 commit into from
Jan 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions templates/suaveazurebootstrapper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# suave.io on Azure

[![Deploy to Azure](http://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/)

This repository shows how to use [FAKE](https://github.com/fsharp/FAKE), [Paket](https://github.com/fsprojects/Paket) and [KuduSync](https://github.com/projectkudu/KuduSync) to deploy a [suave.io](http://suave.io/) website to Azure.

## Getting started

* Go to http://azure.microsoft.com/ and create an Azure account
* Clone this repo and follow the setup steps from https://azuredeploy.net/
* Congratulations your first suave.io website is running on Azure!
* (Optional) Look at your Azure management portal and copy the deployment trigger url to the webhooks of your github repo.
* This allows you to trigger deployments via `git push origin master`.

## How is it working?

Whenever you push to Azure the `deploy.cmd` will be run and

* it downloads the latest paket.exe and uses it to restore the NuGet packages from the `paket.dependencies`
* it uses FAKE to execute the `build.fsx` which can be used to compile an application
* it uses [KuduSync](https://github.com/projectkudu/KuduSync) to synchronize the changes to your Website
* it uses FAKE to run the `site/webserver.fsx` script which then starts a [suave.io](https://github.com/SuaveIO/suave) webserver

## Going further

This is a basic setup and only starts a very small FAKE script on Azure.
Feel free to modify the build and webserver script or you might even want to start a different application from it.
If you need more NuGet packages then modify the `paket.dependencies` file and run `.paket/paket.exe install`.
You can find more information in the [Paket docs](http://fsprojects.github.io/Paket/).
15 changes: 15 additions & 0 deletions templates/suaveazurebootstrapper/build.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------

#r @"packages/FAKE/tools/FakeLib.dll"

open Fake


// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override

Target "All" DoNothing

RunTargetOrDefault "All"
121 changes: 121 additions & 0 deletions templates/suaveazurebootstrapper/deploy.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off

:: ----------------------
:: KUDU Deployment Script
:: Version: 0.1.11
:: ----------------------

:: Prerequisites
:: -------------

:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
goto error
)

:: Setup
:: -----

setlocal enabledelayedexpansion

SET ARTIFACTS=%~dp0%..\artifacts

IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%~dp0%.
)

IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)

IF NOT DEFINED NEXT_MANIFEST_PATH (
SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest

IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
)
)

IF NOT DEFINED KUDU_SYNC_CMD (
:: Install kudu sync
echo Installing Kudu Sync
call npm install kudusync -g --silent
IF !ERRORLEVEL! NEQ 0 goto error

:: Locally just running "kuduSync" would also work
SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Restore packages
:: ----------------

IF NOT EXIST ".paket\paket.bootstrapper.exe" (
echo Downloading paket.bootstrapper.exe
mkdir .paket
curl https://github.com/fsprojects/Paket/releases/download/1.2.0/paket.bootstrapper.exe -L --insecure -o .paket\paket.bootstrapper.exe
)

.paket\paket.bootstrapper.exe
IF !ERRORLEVEL! NEQ 0 goto error

.paket\paket.exe restore
IF !ERRORLEVEL! NEQ 0 goto error

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Run FAKE build script
:: ----------------------

packages\FAKE\tools\FAKE.exe build.fsx
IF !ERRORLEVEL! NEQ 0 goto error

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------

echo Handling Basic Web Site deployment.

:: 1. KuduSync
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
IF !ERRORLEVEL! NEQ 0 goto error
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Post deployment stub
IF DEFINED POST_DEPLOYMENT_ACTION call "%POST_DEPLOYMENT_ACTION%"
IF !ERRORLEVEL! NEQ 0 goto error

goto end

:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%

:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul

:exitSetErrorLevel
exit /b 1

:exitFromFunction
()

:end
endlocal
echo Finished successfully.
4 changes: 4 additions & 0 deletions templates/suaveazurebootstrapper/paket.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source https://nuget.org/api/v2

nuget FAKE
nuget Suave
9 changes: 9 additions & 0 deletions templates/suaveazurebootstrapper/paket.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
NUGET
remote: https://nuget.org/api/v2
specs:
FAKE (3.29.2)
FSharp.Core (3.1.2.1)
FsPickler (1.0.17)
Suave (0.26.1)
FSharp.Core (>= 3.1.2.1)
FsPickler (>= 1.0.7)
24 changes: 24 additions & 0 deletions templates/suaveazurebootstrapper/site/webserver.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// --------------------------------------------------------------------------------------
// Start up Suave.io
// --------------------------------------------------------------------------------------

#r "../packages/FAKE/tools/FakeLib.dll"
#r "../packages/Suave/lib/net40/Suave.dll"

open Fake
open Suave
open Suave.Http.Successful
open Suave.Web
open Suave.Types
open System.Net

let serverConfig =
let port = getBuildParamOrDefault "port" "8083" |> Sockets.Port.Parse
{ defaultConfig with bindings = [ HttpBinding.mk HTTP IPAddress.Loopback port ] }

startWebServer serverConfig
(OK
("Hello World! It's Suave.io on Azure Websites.<br /><ul>" +
"<li>Sample git Repo: <a href='https://github.com/shanselman/suavebootstrapper'>https://github.com/shanselman/suavebootstrapper</a></li>" +
"<li>Intro blog post: <a href='http://www.hanselman.com/blog/RunningSuaveioAndFWithFAKEInAzureWebAppsWithGitAndTheDeployButton.aspx'>http://www.hanselman.com/blog/RunningSuaveioAndFWithFAKEInAzureWebAppsWithGitAndTheDeployButton.aspx</a></li>" +
"</ul>"))
17 changes: 17 additions & 0 deletions templates/suaveazurebootstrapper/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="httpplatformhandler" />
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform
stdoutLogEnabled="false" stdoutLogFile="fake.log" startupTimeLimit="20"
processPath="%HOME%\site\wwwroot\packages\FAKE\tools\FAKE.exe"
arguments="%HOME%\site\wwwroot\site\webserver.fsx port=%HTTP_PLATFORM_PORT%" >
<environmentVariables>
<environmentVariable name="WhateverYouLike" value="GoesHere"/>
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>