search
HomeBackend DevelopmentGolangCustom golang launch command on Azure Web App

Azure Web App 上的自定义 golang 启动命令

#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!

Statement
This article is reproduced at:stackoverflow. If there is any infringement, please contact admin@php.cn delete
Logging Errors Effectively in Go ApplicationsLogging Errors Effectively in Go ApplicationsApr 30, 2025 am 12:23 AM

Effective Go application error logging requires balancing details and performance. 1) Using standard log packages is simple but lacks context. 2) logrus provides structured logs and custom fields. 3) Zap combines performance and structured logs, but requires more settings. A complete error logging system should include error enrichment, log level, centralized logging, performance considerations, and error handling modes.

Empty Interfaces ( interface{} ) in Go: Use Cases and ConsiderationsEmpty Interfaces ( interface{} ) in Go: Use Cases and ConsiderationsApr 30, 2025 am 12:23 AM

EmptyinterfacesinGoareinterfaceswithnomethods,representinganyvalue,andshouldbeusedwhenhandlingunknowndatatypes.1)Theyofferflexibilityforgenericdataprocessing,asseeninthefmtpackage.2)Usethemcautiouslyduetopotentiallossoftypesafetyandperformanceissues,

Comparing Concurrency Models: Go vs. Other LanguagesComparing Concurrency Models: Go vs. Other LanguagesApr 30, 2025 am 12:20 AM

Go'sconcurrencymodelisuniqueduetoitsuseofgoroutinesandchannels,offeringalightweightandefficientapproachcomparedtothread-basedmodelsinlanguageslikeJava,Python,andRust.1)Go'sgoroutinesaremanagedbytheruntime,allowingthousandstorunconcurrentlywithminimal

Go's Concurrency Model: Goroutines and Channels ExplainedGo's Concurrency Model: Goroutines and Channels ExplainedApr 30, 2025 am 12:04 AM

Go'sconcurrencymodelusesgoroutinesandchannelstomanageconcurrentprogrammingeffectively.1)Goroutinesarelightweightthreadsthatalloweasyparallelizationoftasks,enhancingperformance.2)Channelsfacilitatesafedataexchangebetweengoroutines,crucialforsynchroniz

Interfaces and Polymorphism in Go: Achieving Code ReusabilityInterfaces and Polymorphism in Go: Achieving Code ReusabilityApr 29, 2025 am 12:31 AM

InterfacesandpolymorphisminGoenhancecodereusabilityandmaintainability.1)Defineinterfacesattherightabstractionlevel.2)Useinterfacesfordependencyinjection.3)Profilecodetomanageperformanceimpacts.

What is the role of the 'init' function in Go?What is the role of the 'init' function in Go?Apr 29, 2025 am 12:28 AM

TheinitfunctioninGorunsautomaticallybeforethemainfunctiontoinitializepackagesandsetuptheenvironment.It'susefulforsettingupglobalvariables,resources,andperformingone-timesetuptasksacrossanypackage.Here'showitworks:1)Itcanbeusedinanypackage,notjusttheo

Interface Composition in Go: Building Complex AbstractionsInterface Composition in Go: Building Complex AbstractionsApr 29, 2025 am 12:24 AM

Interface combinations build complex abstractions in Go programming by breaking down functions into small, focused interfaces. 1) Define Reader, Writer and Closer interfaces. 2) Create complex types such as File and NetworkStream by combining these interfaces. 3) Use ProcessData function to show how to handle these combined interfaces. This approach enhances code flexibility, testability, and reusability, but care should be taken to avoid excessive fragmentation and combinatorial complexity.

Potential Pitfalls and Considerations When Using init Functions in GoPotential Pitfalls and Considerations When Using init Functions in GoApr 29, 2025 am 12:02 AM

InitfunctionsinGoareautomaticallycalledbeforethemainfunctionandareusefulforsetupbutcomewithchallenges.1)Executionorder:Multipleinitfunctionsrunindefinitionorder,whichcancauseissuesiftheydependoneachother.2)Testing:Initfunctionsmayinterferewithtests,b

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.