Thursday, April 16, 2015

Running Go web app on Azure App Services (Websites) with custom deployment script

Short version:

Perform a continues deployment with code from this repo to your Azure Website. Once deploy, you should be able to see below result, a perfect test web app that use Go "net/http" package, Gin and Martini all together.

Behind the scenes:

The core is to understand GoDeploy.cmd script from repo, below are the key concepts:

To run Go app:
     Create a web.config as below. If you build your go app (exe file), all you need is upload your exe file and update web.config file to reference to it.


To build:

    There is no GOROOT environment variable yet, but the binary is reside in "D:\Program Files\Go\1.4.2". define your own GOROOT and point to it

Build Script:

  •     Create workspace and config GOPATH point to it


    ECHO creating %GOPATH%\bin
    MKDIR "%GOPATH%\bin"
    ECHO creating %GOPATH%\pkg
    MKDIR "%GOPATH%\pkg"
    ECHO creating %GOPATH%\src
    MKDIR "%GOPATH%\src"

  • Create app folder under "{folder}/src", and copy source code into it

ECHO copying sourc code to %GOAZUREAPP%
CP gotry.go %GOAZUREAPP%

  • Resolve dependencies and build
ECHO Resolving dependencies
CD "%GOPATH%\src"

ECHO Building ...