hDEV Blog

Just my place to write something about my life as an IT Guy

Running Go Applications directly on Azure App Service

A simple guide on how to run Go Applications directly on Azure App Service, without using Docker or a linked repository. Just upload the application as a binary to the App Service and run it.

This guide is as simple as it is possible to run a simple Go application on Azure App Service, it is not a complete guide on how to deploy a Go application on Azure App Service in a best practice way which will involve a lot of configuration and setup.

10 Minutes Tutorial with the Azure Portal

Prerequisites:

Create a Web App (this is later the App Service)

Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it .NET, .NET Core, Java, Ruby, Node.js, PHP, or Python. Applications run and scale with ease on both Windows and Linux-based environments.

Url: https://portal.azure.com/#create/Microsoft.WebSite

We will create a Web App with the runtime stack .NET 6 and a Linux operation system. Linux is cheaper than Windows and we don’t need any Windows features.

Create a Azure App Service

Create a Azure App Service

I choose the pricing tier B1, it costs 11€/month:

Pricing Tier

Pricing Tier

But there is also a free option with limited cpu time. But if free is crucial for you, you could use just a free VPS and put it behind Cloudflare.

Open the App Service

Azure App Service

Azure App Service

Develop the Go Application

This is a trivial code, but it is a good example to get started with Go.

  1. Get the port to use from the environment variable PORT, for a list and values of all environment variables go to Development Tools -> Advanced Tools -> Environment

  2. Create a logger which logs to console and to a file

  3. Create a simple HTTP server which logs the request

Compile the Go Application for Linux

In my case to develop with Windows 11, so I change the GOOS to linux and the GOARCH to amd64 for each build which will be uploaded to the Azure App Service. And change is back, so I can run the app in the IDE on my windows maschine again.

$env:GOOS="linux"; go build -o app .\main.go; $env:GOOS="windows"

Upload the Application to the App Service

Get the FTPS credentials from Deployment -> Deployment Center -> FTPS credentials. Use these credentials for a new connection with WinSCP.

FTPS credentials

FTPS credentials

Now you can easy transfer the application to the App Service.

WinSCP

WinSCP

Run the Application

To run the application go to Settings -> Configuration -> General settings and change Startup Command to app arg1 arg2.

General Settings

General Settings

Now you can open your url in the browser and see the application running, the first call can take a while because the application is starting.

Hello World from the Application

Hello World from the Application

Diagnostics

Sometimes it is useful to see the logs of the application or start the application itself from the shell. Got to Development tools -> SSH to see a SSH connection in the Browser.

Go to /home/site/wwwroot/ and run app to start the application.

Web SSH

Web SSH

Next Steps

This page will be extended with these steps or a new article will be published.

  • Configure the Firewall to use a allow list of IPs
  • Connect Azure Files for a KV Value Storage
  • Upload Events to Azure Analytics
Impressum Datenschutz