Friday, May 1, 2015

Deploy your Go app onto Azure App Services (Websites) in ease

Try it:

             Click this link, you will deploy a sample Go web app onto your Azure subscription


Azure App Services now supports Go 1.4.2 with continues deployment. Once continues deployment is setup, every time you push code to your continues deployment branch, a new deployment will be trigger.

if you read the deployment log detaily, you will notice that Azure will create a Go workspace in temp folder, then copy your code to src\azureapp, build against azureapp folder and produce an "azureapp.exe".

Last, it generate a web.config and use HttpPlatformHandler to run your Go app.


  • Have to place main package at the root of your app
  • Currently only support Go 1.4.2, no able to select a specific Go version yet

Sample Go app:

Sample Deployment Log:

Handling Go deployment.
Prepare workspace
GOROOT D:\Program Files\go\1.4.2
Creating GOPATH\bin D:\local\Temp\30a88a27-1ce2-49ef-b1b8-6f32716c9652\gopath\bin
Creating GOPATH\pkg D:\local\Temp\30a88a27-1ce2-49ef-b1b8-6f32716c9652\gopath\pkg
Creating GOPATH\src D:\local\Temp\30a88a27-1ce2-49ef-b1b8-6f32716c9652\gopath\src
Creating D:\local\Temp\30a88a27-1ce2-49ef-b1b8-6f32716c9652\gopath\src\azureapp
Copy source code to Go workspace
   ROBOCOPY     ::     Robust File Copy for Windows                              
   Started : Thursday, April 30, 2015 5:52:54 PM
   Source : D:\home\site\repository\
     Dest : D:\local\Temp\30a88a27-1ce2-49ef-b1b8-6f32716c9652\gopath\src\azureapp\
     Files : *.*
 Exc Files : .deployment
  Exc Dirs : .git
   Options : *.* /NDL /NFL /S /E /DCOPY:DA /COPY:DAT /NP /R:1000000 /W:30 
                Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         3         1         1         0         0         0
   Files :        13        13         0         0         0         0
   Bytes :    19.4 k    19.4 k         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
    Speed :              182743 Bytes/sec.
   Speed :              10.456 MegaBytes/min.
   Ended : Thursday, April 30, 2015 5:52:54 PM
 Resolving dependencies
Building Go app to produce exe file
Copy files for deployment
KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
Deleting file: 'hostingstart.html'
Copying file: 'azureapp.exe'
Copy web.config
        1 file(s) copied.
Finished successfully.

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 ...