使用GoLang部署Azure函数

huangapple go评论87阅读模式
英文:

Deploy azure function with GoLang

问题

目前我正在构建一个使用GoLang编写的Azure无服务器函数。我使用以下构建流程:

trigger:
- main

pool:
  vmImage: 'vs2017-win2016'

steps:
- task: GoTool@0
  inputs:
    version: '1.16.2'

- task: Go@0
  displayName: 'go get'
  inputs:
    arguments: '-d'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: Go@0
  displayName: 'go build'
  inputs:
    command: build
    arguments: '-o go_ibors_backend main.go'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.BinariesDirectory)'
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'

构建流程已成功运行。此外,发布流程也成功部署,但是当我在Azure门户中查看我的函数时,没有结果显示。当我将函数本地推送到Azure时,所有的函数都会显示出来。

发布任务:
使用GoLang部署Azure函数

我做错了什么?

英文:

Currently I'm building a GoLang serverless Azure Function.
I use this build pipeline:

trigger:
- main

pool:
  vmImage: 'vs2017-win2016'
steps:
- task: GoTool@0
  inputs:
    version: '1.16.2'

- task: Go@0
  displayName: 'go get'
  inputs:
    arguments: '-d'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: Go@0
  displayName: 'go build'
  inputs:
    command: build
    arguments: '-o go_ibors_backend main.go'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.BinariesDirectory)'
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'

The build pipeline has run successfully. Also, the release pipeline is deploying successful, but when I look at my functions in the Azure Portal there are no results. When I push the function locally to Azure then all my functions are displayed.

Release task:
使用GoLang部署Azure函数

What I'm doing wrong?

答案1

得分: 0

问题在于ArchiveFiles指向了错误的rootFolderOrFile,并且includeRootFolder必须设置为false,因为作业将在根文件夹中查找host.json文件。

- task: ArchiveFiles@2
  displayName: '创建构件'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
英文:

The problem was that ArchiveFiles was directing to the wrong rootFolderOrFile and that the includeRootFolder must be put to false, because the job will look for a host.json file in the root folder.

- task: ArchiveFiles@2
  displayName: 'Create artifact'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

huangapple
  • 本文由 发表于 2021年9月18日 19:21:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/69234178.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定