简体   繁体   English

如何部署预打包的 Quarkus Azure Functions 应用程序

[英]How can I deploy a prepackaged Quarkus Azure Functions app

Quarkus Azure function apps currently rely on the Maven azure-functions-maven-plugin plugin to perform a deployment of the function. However, this means that I need to package the application source code and rebuild it with each deployment. Quarkus Azure function 应用程序目前依赖 Maven azure-functions-maven-plugin插件来执行 function 的部署。但是,这意味着我需要 package 应用程序源代码并在每次部署时重建它。 This is not ideal, as I really want an immutable package that I can deploy, promote, and roll back without rebuilding.这并不理想,因为我真的想要一个不可变的 package,我可以部署、提升和回滚而无需重建。

Is there any way to deploy a prepackaged Quarkus app without the Maven plugin?有没有办法在没有 Maven 插件的情况下部署预打包的 Quarkus 应用程序?

The reality is that Microsoft has done a poor job of supporting Java developers deploying to Azure functions.事实上,微软在支持 Java 开发人员部署到 Azure 功能方面做得很差。 The requirement to recompile the app with each deployment, which is the only option available to you when using the Maven plugin, is an anti-pattern for repeatable and reliable deployments.每次部署都需要重新编译应用程序,这是使用 Maven 插件时唯一可用的选项,是可重复和可靠部署的反模式。

Digging through the source code of the Maven plugin eventually leads you to the RunFromBlobFunctionDeployHandler class, which uploads a ZIP file as a blob, creates a long lived SAS token, and then sets the WEBSITE_RUN_FROM_PACKAGE setting to the SAS URL. Digging through the source code of the Maven plugin eventually leads you to the RunFromBlobFunctionDeployHandler class, which uploads a ZIP file as a blob, creates a long lived SAS token, and then sets the WEBSITE_RUN_FROM_PACKAGE setting to the SAS URL.

To recreate this process, we first need a function.json file, which will redirect all requests to the Quarkus io.quarkus.azure.functions.resteasy.runtime.Function.run class. You can get this class by generating a sample Quarkus project, as documented here : To recreate this process, we first need a function.json file, which will redirect all requests to the Quarkus io.quarkus.azure.functions.resteasy.runtime.Function.run class. You can get this class by generating a sample Quarkus project, as记录在这里

{
  "scriptFile" : "../products-microservice-runner.jar",
  "entryPoint" : "io.quarkus.azure.functions.resteasy.runtime.Function.run",
  "bindings" : [ {
    "type" : "httpTrigger",
    "direction" : "in",
    "name" : "req",
    "route" : "{*path}",
    "methods" : [ "GET", "POST", "HEAD", "PUT", "OPTIONS", "DELETE" ],
    "dataType" : "binary",
    "authLevel" : "ANONYMOUS"
  }, {
    "type" : "http",
    "direction" : "out",
    "name" : "$return"
  } ]
}

You then need a host.json file, again generated by the sample Quarkus project:然后您需要一个host.json文件,同样由示例 Quarkus 项目生成:

{
  "version": "2.0"
}

Once we build your Quarkus Azure function app, you'll have a self contained JAR file.一旦我们构建了您的 Quarkus Azure function 应用程序,您将拥有一个独立的 JAR 文件。 In my case it was called products-microservice-runner.jar .在我的例子中,它被称为products-microservice-runner.jar The next step is to recreate the directory structure documented here :下一步是重新创建此处记录的目录结构:

rm -rf /tmp/octopubproductservice
mkdir /tmp/octopubproductservice
mkdir /tmp/octopubproductservice/octopubproductservice
cp target/products-microservice-runner.jar /tmp/octopubproductservice
cp azure-config/host.json /tmp/octopubproductservice
cp azure-config/function.json /tmp/octopubproductservice/octopubproductservice
pushd /tmp/octopubproductservice
zip -r $ZIP_FILE .
popd

This produces a ZIP file like this:这会生成一个 ZIP 文件,如下所示:

在此处输入图像描述 在此处输入图像描述

Now create the resource group, storage account, and function as documented here :现在创建资源组、存储帐户和function ,如下所述:

REGION=australiaeast
RESOURCE_GROUP=octopubproductservice
FUNCTION_NAME=octopubproductservice
STORAGE_ACCOUNT=octopubproductservice
STORAGE_SKU="Standard_LRS"
ZIP_FILE=product-service-azure.zip
CURRENT_DATE=$(date +%Y%m%d)
SAS_EXPIRY=$(date -d "$CURRENT_DATE +10 years" +%Y-%m-%d)

# Create a resource group
az group create --location $REGION --name $RESOURCE_GROUP
# Create a storage account
az storage account create --name $STORAGE_ACCOUNT --resource-group $RESOURCE_GROUP --sku $STORAGE_SKU
# Create a function app
az functionapp create \
  --name $FUNCTION_NAME \
  --resource-group $RESOURCE_GROUP \
  --storage-account $STORAGE_ACCOUNT \
  --consumption-plan-location $REGION \
  --functions-version 4 \
  --os-type linux \
  --runtime java \
  --runtime-version 11.0

Next upload the function package and generate an SAS token:接下来上传 function package 并生成一个 SAS 令牌:

# Upload the function package
az storage blob upload \
  --account-name $STORAGE_ACCOUNT \
  --container-name java-functions-run-from-packages \
  --name product-service-azure.zip \
  --file /tmp/octopubproductservice/product-service-azure.zip \
  --overwrite \
  --auth-mode key
# Create a SAS key for the function package
URL=$(az storage blob generate-sas \
  --account-name $STORAGE_ACCOUNT \
  --container-name java-functions-run-from-packages \
  --name product-service-azure.zip \
  --permissions r \
  --expiry $SAS_EXPIRY \
  --auth-mode key \
  --full-uri)
# The URL is quoted. We treat this as a JSON string, and use jq to return the raw string
FIXED_URL=$(echo $URL | jq -r '.')

Finally, set the WEBSITE_RUN_FROM_PACKAGE setting to the SAS URL, which is required when deploying Linux functions :最后,将WEBSITE_RUN_FROM_PACKAGE设置设置为 SAS URL,这是部署 Linux 函数时需要的

# The raw string is set as the WEBSITE_RUN_FROM_PACKAGE value, which indicates Azure
# must download the function from the URL.
az functionapp config appsettings set \
  --name $FUNCTION_NAME \
  --resource-group $RESOURCE_GROUP \
  --settings "WEBSITE_RUN_FROM_PACKAGE=$FIXED_URL"

At that point your Quarkus app should be working.届时您的 Quarkus 应用程序应该可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Azure Functions部署到内部数据中心? - How can I deploy Azure Functions to in-house datacenters? Azure:如何使用 tensorflow 部署函数应用程序 - Azure: How to deploy a functions app with tensorflow 如何使用msbuild部署Azure Api App - How can I deploy Azure Api App using msbuild 如何在VPC上部署Azure应用服务 - How can I deploy an Azure App Service on VPC 如何使用身份模型将应用程序部署到Azure上的生产环境? - How can I deploy an app using Identity Model to Production on Azure? 如何使用应用程序服务对Azure函数应用程序进行身份验证/授权? - How can I authenticate/authorize an Azure functions app with an app service? 如何将两个压缩函数部署到同一个 Azure Function App? - How to deploy two zipped Functions to the same Azure Function App? 如何将 React 应用程序的生产 npm 构建部署到 Azure 应用服务 - How can I deploy production npm build of react app to Azure App Service 当应用程序在子文件夹中时,如何通过git将node.js应用程序部署到azure? - How can I deploy a node.js app to azure via git when the app is in a subfolder? 如何通过VSC将PowerShell api部署到Azure Functions? - How can one deploy a PowerShell api to Azure Functions thru VSC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM