Why doesn't this simple Go server run in Azure App Services? - azure

I have this code in server.go :
package main
import (
"fmt"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "You just browsed page (if blank you're at the root): %s", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":"+os.Getenv("HTTP_PLATFORM_PORT"), nil)
}
and this web.config :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="d:\home\site\wwwroot\go\bin\go.exe"
arguments="run d:\home\site\wwwroot\server.go"
startupTimeLimit="60">
<environmentVariables>
<environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
Both of these files are in the d:\home\site\wwwroot directory of an Azure App Service. I also have the 1.13.3 version of the x64 Windows go runtime installed (unzipped from go1.13.3.windows-amd64.zip) in d:\home\site\wwwroot\go.
When I browse to fwWebApi.azurewebsites.net/hello it times out.
I got this sample from http://www.wadewegner.com/2014/12/4-simple-steps-to-run-go-language-in-azure-websites/ which is admittedly a few years old. But I want to be able to run a Go web application in Azure App Services.
Can anyone suggest what I can do?

I strongly suggest you use a docker image to run your non supported language on azure app services:
Supported languages ASP.NET, ASP.NET Core, Java, Ruby, Node.js, PHP, or Python
Github: https://github.com/AnassKartit/helloworld-golang
Docker Image
https://hub.docker.com/r/anasskartit/hello-world-golang
First Run will take some time as it downloads the image you can check the logs
Result

Related

Azure App Service - What modified my web.config?

I have an ASP.NET Core website running from Kestrel. It is deployed to Azure App Service in production and another as staging.
I like to configure staging as "production-like" so I set ASPNETCORE_ENVIRONMENTNAME = Production in the Configuration blade of the App Service in the Azure portal. I could see from logs that the code was seeing the environment name as staging still.
It turns out <environmentVariable name="ASPNETCORE_ENVIRONMENTNAME" value="staging" /> is set in the web.config that's on the Azure instance!!
Now, I don't have this set in the web.config or any transforms in my codebase, and I don't use the web.config, in fact I want nothing to do with it or IIS.
My site is deployed via Azure Pipelines. I use environmentName as a build time variable but the YAML only uses it once, to concatenate some text to make up the resource group name.
I then ran dotnet deploy using the same command line as Azure Pipelines runs, but the web.config it writes into the final publish output folder doesn't contain the offending line either.
It was only a few weeks ago I rebuilt and redeployed all my Azure resources. It was all clean, and it's all scripted.
Where on Earth has it come from??!
I'm worried that if I remove it, one day, it'll magically just reappear. It smells very much like someone at Microsoft thought this automagic was a good idea.
Mind you, I've tried to remove it using the App Service Editor and Kudu but I'm not allowed!!
Your app is currently in read only mode because you are running from a package file. To make any changes, please update the content in your zip file and WEBSITE_RUN_FROM_PACKAGE app setting.
So if I'm not setting it, and I'm not allowed to change it, what do I do??
Update 1
I've downloaded the artifacts from Pipelines and the web.config has the setting in place.
The command run, according to the Pipelines log, was this.
dotnet publish --configuration Release --output D:\a\1\s/dotnet-publish-output
But when I run that myself, on my machine, it does not meddle with my web.config.
Wow. So whilst on the school run, it occurred to me that the value that the dotnet command writes into the web.config is correct. How does it know?
The only way it can know is from that environment variable I'm setting in Azure Pipelines and using in my YAML file azureResourceGroup: tz-$(environmentName).
And when I run it on my dev machine vs. running on the Azure build server, that environment variable is not set.
So I set environmentName in the environment on my dev machine before running dotnet publish and, hey presto! It screws up my web.config by adding an environment variable! Amazing.
> $env:environmentName = "undocumented-feature"
> dotnet publish --configuration Release --output C:\DATA\Published
...
> cat C:\DATA\Published\web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyWebsiteYeah.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="undocumented-feature" />
</environmentVariables>
</aspNetCore>
<security>
<requestFiltering>
<requestLimits maxUrl="32768" maxQueryString="262144"/>
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 3E05D228-D9AF-4782-8E33-1F0E69992750-->
Isn't that dreadful.
So I solved the whole problem with my websites ignoring the variables set in the portal by changing the variable name in Pipelines to hostEnvironmentName.

httpModule in Web Application Project not being called when deployed to IIS

I am in the process of converting out web site project to a web application project. I've got everything to compile and even publish (long process). However, now that I've got the project "loading" in IIS, the httpModule is not called.
The modules section of web.config looks like this:
<modules runAllManagedModulesForAllRequests="true">
<add name="ContentWebSite" type="ContentWebSite.ContentWebSite"/>
</modules>
the class of the httpModule starts like this:
namespace ContentWebSite
{
public class ContentWebSite : IHttpModule
{
private HttpApplication _Application;
What am I missing? Setting a breakpoint in the constructor or the init method of the ContentWebSite class is never hit when I'm running in the context of local IIS. When I run in IIS Express, the breakpoint is hit! How do I get IIS to invoke the httpModule?
TIA,
You can check if the application pool mode caused your problem.
Application pool mode: classic versus integrated.
<system.webServer><!--for integrated mode-->
<modules>
<add name="modulename" type="ContentWebSite.ContentWebSite" />
</modules>
</system.webServer>
<system.web><!--for classic mode-->
<httpModules>
<add name="modulename" type="ContentWebSite.ContentWebSite" />
</httpModules>
</system.web>
OK, so I got this working by changing the modules add name line to this:
<add name="modulename" type="ContentWEbSite.ContentWebsite, appName" />
Where appName is the physical name of the DLL generated for the project!

How to deploy jHipster on Azure App Service, I got 500 request timed out

This guideline provided by Microsoft is for SpringBoot App
https://learn.microsoft.com/en-us/azure/app-service/app-service-deploy-spring-boot-web-app-on-azure
which is essentially:
Create an Azure web app for use with Java
Specify the Java version
Obtain FTP deployment credential
Upload your SpringBoot .JAR along with provided web.config
Restart the web app via Azure portal
The app works!
Instead of .jar, jHipster is producing .war file. Since it is essentially the same (i.e. it can be executed with java -jar), I was hoping the steps would also works for .war.
I've uploaded:
the .war file
the .war.original file
web.config
This is the aforementioned web.config. Please note I've renamed the -jar into -war
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -war "%HOME%\site\wwwroot\gmbgenpro-0.0.1-SNAPSHOT.war"">
</httpPlatform>
</system.webServer>
</configuration>
The app is loading so long that I got the 500 request timed out.
EDIT: I've enabled stdout in the web.config and I got the following from the log files:
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -war
So it seems I could not use the -war parameter, and I don't know what to do.
To deploy your JHipster project as a WAR file, make sure you build it with spring-boot.repackage.skip option enabled. This will skip building an executable WAR file and simply package the WAR file normally under ${finalName}.war. This way you can deploy your application to a web runtime on Azure automatically configured for you.
To proceed with the deployment, follow these steps:
Add the following Maven Plugin configuration to your main element of your pom.xml:
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<!-- check Maven Central for the latest version -->
<version>1.3.0</version>
<configuration>
<resourceGroup>your-resource-group</resourceGroup>
<appName>your-app-name</appName>
<linuxRuntime>tomcat 9.0-jre8</linuxRuntime>-->
</configuration>
</plugin>
Build your project with the following command, and adjust your profile accordingly:
./mvnw clean package -Pdev -Dspring-boot.repackage.skip=true
Deploy your application:
./mvnw azure-webapp:deploy
For up-to-date information about the Maven Plugin for Azure App Service, check the documentation.

Error starting application in .netcore

I'm getting the following error when navigating to my IIS published .netcore application:
I have set up my web.config file as so:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\KritnerWebsite.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
Not sure if this warning is relevant or just outdated:
Severity Code Description Project File Line Source Suppression State
Warning The element 'system.webServer' has invalid child element 'aspNetCore'. List of possible elements expected: 'asp, caching, cgi, defaultDocument, directoryBrowse, globalModules, handlers, httpCompression, webSocket, httpErrors, httpLogging, httpProtocol, httpRedirect, httpTracing, isapiFilters, modules, applicationInitialization, odbcLogging, security, serverRuntime, serverSideInclude, staticContent, tracing, urlCompression, validation, management, rewrite'. KritnerWebsite D:\gitWorkspace\KritnerWebsite\src\KritnerWebsite\web.config 12 Build
The line in the web.config was as per the template, I just changed "false" to "true" for stdoutLogEnabled.
I have also created an empty folder in the root directory "logs" - I wasn't sure if this should get created automatically or not. Either way, nothing is being written to the logs, so I am not sure what to try next.
I have opened the solution in VS2015 on my host, compiled it and ran it successfully through commandline/localhost with dotnet run. This is running it in the production configuration, so pulling from my environment variables for insights key, and connection string. So I'm not sure why the site would run successfully on my host through dotnet run but not when published to IIS
How do I get further information on what the error is?
I'm not sure what exactly caused the logs to start correctly recording in ./logs... but they did. With the exception now being recorded I could see that my connection string I had set up in my Environment Variables was off.
Still not sure what caused the logs to not write out in order for me to determine this faster.
After updating my environment variable and running iisreset as per https://serverfault.com/questions/193609/make-iis-see-updated-environment-path-variable my website is now being served properly.

Point Azure webroot to different folder

I've set up an NodeJS website on Azure to continuously deploy from github. Unfortunately my github project is structured in a way that the root isn't the website.
github_root
|_ app(nodejs website)
|
|_ docs
|
|_ blah
It seems that Azure(IIS) is looking for server.js in the github_root.
Is there a way to point IIS to the 'app' folder for the website?
Node.js applications deployed on Windows Azure with IIS server use iisnode - native IIS module that allows hosting of node.js applications.
You can specify which file is you main application file in web.config e.g.
<configuration>
<system.webServer>
<!-- // configure your node.js application file here -->
<handlers>
<add name="iisnode" path="your_application_file.js" verb="*" modules="iisnode" />
</handlers>
<!-- ... // other configuration parameters .... -->
<system.webServer>
<configuration>
You can find more examples (including URL rewriting etc.) on Tomasz Janczuk's (iisnode creator) blog.
I hope that will help or gives you right directions.

Resources