Custom golang launch command on Azure Web App
#php editor Strawberry will introduce to you the custom golang startup command on Azure Web App today. Azure Web App is a managed cloud service that helps developers easily deploy and scale web applications. Golang is an efficient programming language that is fast, reliable and concise. By customizing golang startup commands, developers can better control the startup process of web applications and achieve more personalized functions. This article will introduce in detail how to configure and use customized golang startup commands on Azure Web App to help developers make better use of this feature.
Question content
I am trying to deploy a go web application with github actions to azure app service. The entire deployment succeeds until the application needs to be deployed using azure/webapps-deploy@v2
.
To see where the problem lies, I created a simple go 'hello world' test application. Just deploy this very simple application and you're good to go. However, while trying to deploy the test application, I noticed something:
- The application is completely rebuilt on azure rather than using an executable to run. My previous deployment file looked like this:
name: go deployment on: push: branches: [ "master" ] pull_request: branches: [ "master" ] jobs: build: runs-on: ubuntu-latest environment: production steps: # checkout the repo - uses: actions/checkout@master # setup go - name: setup go uses: actions/setup-go@v3 with: go-version: '1.20' - run: go version # install dependencies - name: go build working-directory: . run: | go build - name: upload artifact for deployment job uses: actions/upload-artifact@v3 with: name: go-app path: . deploy: runs-on: ubuntu-latest needs: build environment: name: 'production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: - name: download artifact from build job uses: actions/download-artifact@v3 with: name: go-app - name: 'deploy to azure web app' id: deploy-to-webapp uses: azure/webapps-deploy@v2 with: app-name: ${{ env.azure_webapp_name }} slot-name: 'production' publish-profile: ${{ secrets.azureappservice_publishprofile }} package: .
There is no problem with this deployment. Codebase applications are fed into Azure Web Apps. When I try to use the executable in the last step, the deployment fails. Of course, azure web app has a custom field for setting the launch command. I tried setting it to ./main
to run the executable on startup, but this still failed.
with: app-name: ${{ env.azure_webapp_name }} slot-name: 'production' publish-profile: ${{ secrets.azureappservice_publishprofile }} package: main
When building the go application on my local machine using go build main.go
and then executing ./main
, the application runs without issue.
- Because I couldn't just execute the executable from the previous step, I decided to roll back and let Azure App Service execute the go app as-is. If so, the whole build step is no longer needed and you can just push the code to an azure web service. like this:
name: Go on: push: branches: [ "master" ] pull_request: branches: [ "master" ] jobs: build: runs-on: ubuntu-latest environment: name: 'Production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: # checkout the repo - uses: actions/checkout@master - name: 'Deploy to Azure Web App' id: deploy-to-webapp uses: azure/webapps-deploy@v2 with: app-name: ${{ env.AZURE_WEBAPP_NAME }} slot-name: 'Production' publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }} package: .
Despite having to push the entire codebase, it still works great. However, in our production application, due to structural reasons, the main.go file is not located in the root directory. To mimic this behavior, I placed the main.go file in the /cmd directory. Deployment of azure web app failed again. One can guess that this may be due to azure not being able to find the main.go file. I want to use the start command again, but this time run cmd/main.go using
go. Sadly, this doesn't work either.
azure web apps displays everything built when running the pipeline:
Any suggestions? What am I missing here?
Is there any solution on how to upload the executable created in the previous step to azure web app and run the executable there?
Workaround
First, you should set an environment variable in azure web app: website_run_from_package
to 1
. This prevents the build from running on Azure again. From this moment on, you should be able to upload pre-built executables.
I also had to set up the launch command to run my specific executable.
After doing this, I see the following in the logs for https://appname- here.scm.azurewebsites.net/api/logstream
2023-04-26T17:20:12.596331026Z Detecting platforms... 2023-04-26T17:20:12.805572634Z Could not detect any platform in the source directory. 2023-04-26T17:20:15.792565274Z Running /home/site/wwwroot/go-test now 2023-04-26T17:20:15.928193597Z /home/site/wwwroot/go-test: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.32' not found (required by /home/site/wwwroot/go-test) 2023-04-26T17:20:15.934491135Z /home/site/wwwroot/go-test: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.34' not found (required by /home/site/wwwroot/go-test)
The version glibc_2.34
appears because the application was built in the pipeline using ubuntu-latest. This is ubuntu-22.04, which has glibc_2.35
but the azure machine I want to run it on doesn't have this version. Building with ubuntu-20.04
version glibc_2.31
works perfectly.
The above is the detailed content of Custom golang launch command on Azure Web App. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...

What should I do if the custom structure labels in GoLand are not displayed? When using GoLand for Go language development, many developers will encounter custom structure tags...

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys
