Azure JAVA Functions + DevOps pipeline for different environment

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

Azure JAVA Functions + DevOps pipeline for different environment

问题

我在JAVA中有一个Azure函数项目。不幸的是,java的支持不是很好 )-: 所以,一切都有点不同。那么,你能指点我参考示例或文档,教我如何将用java编写的函数项目部署到Azure吗?因为我想要的一切只显示了问题的一部分 - 而且这些部分不契合在一起 )-:

  • Java使用azure-function-maven-plugin(这是func核心工具的包装器)
  • 这个插件会准备一个暂存文件夹,然后将其压缩为ZIP文件,并部署为"package"
  • 不幸的是,这个暂存文件夹的名称是基于函数名称的。因此,ZIP包是依赖于目标Azure资源名称的。

不可能构建独立的包(ZIP文件),然后将其部署到几个不同的环境(阶段/开发/测试/生产)。 是这样吗?

尤其是当你使用CI/CD流水线时,这变得特别奇怪。不可能有一个构建流水线,然后有几个部署流水线。因为构建必须基于目标部署名称进行命名(内部目录)- 所以不是独立的。这与基本原则相悖,即一个构建对应每个环境的多个配置。

有没有办法在不构建多个构建的情况下解决这个问题?谢谢。

编辑:
Maven命令"mvn package (+azure-function:package)"会准备带有目录结构的构建:

${projectRoot}/target/azure-functions/${functionResourceName}/...

其中

/...

被压缩为最终的Azure包,名称为:${functionResourceName}.zip

所以,"functionResourceName"仅出现在ZIP文件的名称中(包括相同名称的jar文件)。但是......

... 如果你尝试将此ZIP部署到具有不同名称的Azure函数资源上 - 将会失败。

英文:

I have Azure Function project in JAVA. Unfortunately, java is not supported very well )-: So, everything is a "little" bit different. So, could you point me to reference example or documentation how to deploy a function project written in java to azure? Since all what I want shows just part of the problem - and the parts does not fit together )-:

  • java uses azure-function-maven-plugin (which is wrapper to func core tools)
  • this plugin prepares stagging folder which is compressed to ZIP and deployed as "package"
  • unfortunately, this stagging folder is named based of function name. So, ZIP package IS DEPENDENT on target azure RESOURCE name.

It is impossible to build independent package (ZIP) and deploy it to several different environment (stages/dev/test/prod). Or is it?

It is especially wierd when you use CI/CD pipeline. It is not possible to have one BUILD pipeline and than several DEPLOY pipeline. Because the build HAVE TO be named (internal directories) based on target deployment name - so not independent. Which goes against the basic principle to have one build and several configuration for each environment.

Any idea how to solve it without building several builds? Thank you.

EDIT:
maven "mvn package (+azure-function:package)" prepare build with directories

${projectRoot}/target/azure-functions/${functionResourceName}/...

where

/... 

is compressed to final azure package named: ${functionResourceName}.zip

So, the "functionResourceName" is just in the name of ZIP file (+ containing jar with the same name). But ...

... if you try deploy this ZIP to azure function resource with another name - it fails.

答案1

得分: 2

是的,我确实手动准备了该软件包(使用“发布构建工件任务”)。

我想分享一下我将Java函数包部署到Azure函数的步骤。

以下是我的步骤:

在构建流程中:

steps:
- task: Maven@3
  displayName: 'Maven pom.xml'
  inputs:
    mavenPomFile: '$(Parameters.mavenPOMFile)'
    options: 'azure-functions:package'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
  inputs:
    SourceFolder: '$(system.defaultworkingdirectory)'
    Contents: '**/azure-functions/**'
    TargetFolder: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

- task: ArchiveFiles@2
  displayName: 'Archive $(Build.ArtifactStagingDirectory)/target/azure-functions/kishazureappfunction'
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/target/azure-functions/kishazureappfunction'
    includeRootFolder: false

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

在发布流程中:

我使用Azure应用服务部署任务。(为了清晰起见,我将其转换为YAML格式)

- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: kevin1014'
  inputs:
    azureSubscription: kevintest
    appType: functionApp
    WebAppName: kevin1014
    packageForLinux: '$(System.DefaultWorkingDirectory)/_123-Maven-CI/drop/1.zip'
    enableCustomDeployment: true
    DeploymentType: runFromZip

结果:

Azure JAVA Functions + DevOps pipeline for different environment

Azure函数的名称和软件包的名称是不同的。但它已成功部署到Azure函数中。

英文:

Yes. I indeed manually prepare the package(using Publish Build Artifacts Task.)

I would like to share my steps to deploy the Java Function Package to Azure Function.

Here are my steps:

In Build Pipeline:

steps:
- task: Maven@3
  displayName: 'Maven pom.xml'
  inputs:
    mavenPomFile: '$(Parameters.mavenPOMFile)'
    options: 'azure-functions:package'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
  inputs:
    SourceFolder: '$(system.defaultworkingdirectory)'
    Contents: '**/azure-functions/**'
    TargetFolder: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

- task: ArchiveFiles@2
  displayName: 'Archive $(Build.ArtifactStagingDirectory)/target/azure-functions/kishazureappfunction'
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/target/azure-functions/kishazureappfunction'
    includeRootFolder: false

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

In Release Pipeline:

I use the Azure App Service Deploy Task. (For clear, I converted it to yaml format)

- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: kevin1014'
  inputs:
    azureSubscription: kevintest
    appType: functionApp
    WebAppName: kevin1014
    packageForLinux: '$(System.DefaultWorkingDirectory)/_123-Maven-CI/drop/1.zip'
    enableCustomDeployment: true
    DeploymentType: runFromZip

Result:

Azure JAVA Functions + DevOps pipeline for different environment

The azure function name and the package name is different. But it could be deployed to Azure Function successfully.

huangapple
  • 本文由 发表于 2020年10月9日 19:44:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/64279410.html
匿名

发表评论

匿名网友

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

确定