最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to delete homesitewwwrootlib folder content before zip deployment? - Stack Overflow

programmeradmin4浏览0评论

I'm deploying a Java Azure Function using zip deployment, and the dependencies are managed through the pom.xml file. These dependencies are packaged as JAR files into the /lib folder within /home/site/wwwroot during deployment.

The issue is that when I update dependencies in the pom.xml (e.g., upgrading versions of JARs), the new JARs are added to the /lib folder, but the old JARs remain. This causes conflicts because the function ends up with multiple versions of the same dependency.

Currently, I have to manually delete the old JARs from the /home/site/wwwroot/lib folder using the Azure Kudu Console (rm -rf /home/site/wwwroot/lib) or similar methods. This is not ideal for automation or scalability.

Is there a way to automatically clean up the /lib folder to remove outdated JARs during zip deployment?

Github action workflow:

name: Deploy Azure Functions to Stage

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Login via Az module
        uses: azure/[email protected]
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      - name: Deploy Azure Functions in Stage
        uses: Azure/[email protected]
        id: fa
        with:
          app-name: ${{ env.AZURE_STAGE_FUNCTIONAPP_NAME }}
          package: publish-target/target/azure-functions/${{ env.POM_FUNCTIONAPP_NAME }}

I'm deploying a Java Azure Function using zip deployment, and the dependencies are managed through the pom.xml file. These dependencies are packaged as JAR files into the /lib folder within /home/site/wwwroot during deployment.

The issue is that when I update dependencies in the pom.xml (e.g., upgrading versions of JARs), the new JARs are added to the /lib folder, but the old JARs remain. This causes conflicts because the function ends up with multiple versions of the same dependency.

Currently, I have to manually delete the old JARs from the /home/site/wwwroot/lib folder using the Azure Kudu Console (rm -rf /home/site/wwwroot/lib) or similar methods. This is not ideal for automation or scalability.

Is there a way to automatically clean up the /lib folder to remove outdated JARs during zip deployment?

Github action workflow:

name: Deploy Azure Functions to Stage

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Login via Az module
        uses: azure/[email protected]
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      - name: Deploy Azure Functions in Stage
        uses: Azure/[email protected]
        id: fa
        with:
          app-name: ${{ env.AZURE_STAGE_FUNCTIONAPP_NAME }}
          package: publish-target/target/azure-functions/${{ env.POM_FUNCTIONAPP_NAME }}
Share Improve this question edited Jan 20 at 17:46 Denis Kisina asked Jan 20 at 8:26 Denis KisinaDenis Kisina 4027 silver badges23 bronze badges 8
  • Did you deploy the package using vs code? If so, vs code has a option to exclude folder from zipping/publishing. – qkfang Commented Jan 20 at 8:42
  • Do you want to override the package versions during the deployment? – Pravallika KV Commented Jan 20 at 13:58
  • @PravallikaKV Yes, I want to override the package versions during deployment. – Denis Kisina Commented Jan 20 at 16:08
  • You can achieve this by deploying the function using VS code. – Pravallika KV Commented Jan 20 at 16:46
  • Hi @PravallikaKV, deployment isn't handled directly via VS Code in this case, as it's part of a stage in our CI/CD pipeline. – Denis Kisina Commented Jan 20 at 17:09
 |  Show 3 more comments

1 Answer 1

Reset to default 1

Add a step in your GitHub workflow(.yml file) to restore the dependencies:

name: 'Restore Project Dependencies Using Mvn'
        shell: pwsh
        run: |
          pushd './${{ env.PACKAGE_DIRECTORY }}'
          mvn clean package
          popd

I have created a simple Java function and deployed it to staging slot using GitHub actions.

Complete GitHub workflow:

name: Build and deploy Java project to Azure Function App - function_app_name 

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_NAME: function_app_name # set this to your function app name on Azure
  PACKAGE_DIRECTORY: '.' # set this to the directory which contains pom.xml file
  JAVA_VERSION: '17' # set this to the java version to use

jobs:
  build-and-deploy:
    runs-on: windows-latest
    
    steps:
      - name: 'Checkout GitHub Action'
        uses: actions/checkout@v4

      - name: Setup Java Sdk ${{ env.JAVA_VERSION }}
        uses: actions/setup-java@v4
        with:
          java-version: ${{ env.JAVA_VERSION }}
          distribution: 'microsoft'

      - name: 'Restore Project Dependencies Using Mvn'
        shell: pwsh
        run: |
          pushd './${{ env.PACKAGE_DIRECTORY }}'
          mvn clean package
          popd
      
      - name: 'Run Azure Functions Action'
        uses: Azure/functions-action@v1
        id: fa
        with:
          app-name: 'javafn21'
          slot-name: 'staging'
          package: '${{ env.PACKAGE_DIRECTORY }}'
          respect-pom-xml: true
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_E2E70DE88E9D4XXX4C0792E53D2 }}

Initially, I have added a sample dependency guava with version 30.1.jre in POM.XML.

<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>30.1-jre</version>
    </dependency>
</dependencies>

Deployed the function to Azure using GitHub actions.

Deployed files in KUDU under site/wwwroot/lib folder.

Updated the version of guava to 31.0-jre in POM.XML:

<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>31.0-jre</version> 
    </dependency>
</dependencies>

Deployed the updated function to Azure and the updated versions of the dependencies overridden the existing ones as highlighted below:

发布评论

评论列表(0)

  1. 暂无评论