我有一个java spark web服务,我正在使用gradle构建。我正在尝试使用circleci构建和部署jar到azure应用服务。在我的circleci任务中添加中间'ls'后,我可以看到构建时jar文件的大小足够大,并且涵盖了jar中的所有依赖项。然而,当我在部署完成后ssh到我的appservice主机时,我在/home/site/wwwroot下找到的jar文件相当小,并且没有覆盖我的所有依赖项,而是只包含我的原始源代码文件。
这是我的circleci配置
version: 2.1
orbs:
gradle: circleci/gradle@3.0.0
jobs:
build:
docker:
- image: circleci/openjdk:11-jdk
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- gradle-dependencies-{{ checksum "build.gradle" }}
- gradle-dependencies-
- run: gradle dependencies
- save_cache:
paths:
- ~/.gradle
key: gradle-dependencies-{{ checksum "build.gradle" }}
- run: gradle test
- run:
name: "Build and Package JAR"
command: |
./gradlew customFatJar
ls -rlt ~/repo/build/libs/app.jar
- persist_to_workspace:
root: ~/repo
paths:
- build
deploy:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run:
name: Install azure-cli
command: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
- run:
name: Login to Azure
command: |
az login --service-principal -u $AZURE_CLIENT_ID -p $APP_SECRET --tenant $AZURE_TENANT_ID
- attach_workspace:
at: ~/repo
- run:
name: Deploy to Azure App Service
command: |
az webapp up --sku F1 -n 'CikService' -l 'East US' --runtime 'JAVA:11-java11' --resource-group 'Cik' -p 'P1v2' --os-type 'Linux'
- run:
name: Deploy Code
command: |
ls -rlt ~/repo/build/libs/app.jar
az webapp deployment source config-zip -g 'Cik' -n 'CikService' --src ~/repo/build/libs/app.jar
workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: main
字符串
下面是来自circleci的构建日志
#!/bin/bash -eo pipefail
ls -rlt ~/repo/build/libs/app.jar
az webapp deployment source config-zip -g 'Cik' -n 'CikService' --src ~/repo/build/libs/app.jar
**-rw-r--r-- 1 circleci circleci 7401147 Jun 29 08:03 /home/circleci/repo/build/libs/app.jar**
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
{
"active": true,
"author": "N/A",
"author_email": "N/A",
"build_summary": {
"errors": [],
"warnings": []
},
"complete": true,
"deployer": "Push-Deployer",
"end_time": "2023-06-29T08:06:30.6786105Z",
"id": "ec11ce4a-71d7-42b2-836f-f01c74015916",
"is_readonly": true,
"is_temp": false,
"last_success_end_time": "2023-06-29T08:06:30.6786105Z",
"log_url": "https://cikservice.scm.azurewebsites.net/api/deployments/latest/log",
"message": "Created via a push deployment",
"progress": "",
"received_time": "2023-06-29T08:05:22.3944098Z",
"site_name": "cikservice",
"start_time": "2023-06-29T08:05:23.9412019Z",
"status": 4,
"status_text": "",
"url": "https://cikservice.scm.azurewebsites.net/api/deployments/latest"
}
CircleCI received exit code 0
型
当我ssh到应用程序服务主机时,我看到jar的大小要小得多
d8af2b6b9e31:/home# ls -rlt /home/site/wwwroot/app.jar
-rwxrwxrwx 1 nobody nobody 10562 Jun 28 06:49 /home/site/wwwroot/app.jar
d8af2b6b9e31:/home#
d8af2b6b9e31:/home# jar -tf /home/site/wwwroot/app.jar
Picked up JAVA_TOOL_OPTIONS: -Xmx2300M -Djava.net.preferIPv4Stack=true
META-INF/
META-INF/MANIFEST.MF
org/
org/example/
org/example/repository/
org/example/repository/CikRepository.class
org/example/repository/SECRepository.class
org/example/enumeration/
org/example/enumeration/ReportType.class
org/example/http/
org/example/http/HttpHelper.class
org/example/external/
org/example/external/ExternalUrl.class
org/example/Main.class
log4j2.xml
d8af2b6b9e31:/home#
型
你可以看到上面没有包含任何依赖项。关于展开后可能导致罐收缩的原因,有什么看法吗?
试着在网上查找答案,但没有得到任何具体的问题。
还在我的circleci build中添加了一堆调试消息,以确保我正在构建正确的jar,并在circleci build中运行gradle后确认jar的内容。
1条答案
按热度按时间uxhixvfz1#
不要使用
az webapp deployment source config-zip
将应用程序部署为zip,而是尝试使用下面命令reference:-
字符串
完整的CircleCI yml脚本:-
型
在
az webapp up
命令中,请确保您正在传递整个文件夹,并且您已经配置了yml脚本以从根运行命令,我从根运行命令,并且我的所有JAR文件都成功部署在Azure Web应用程序中,请参阅下面:-型
x1c 0d1x的数据
在
az webapp deploy
中,请确保将类型选择为JAR和src-path
到您的jar文件并检查它是否成功部署,您可以在测试应用中通过CirceCI管道部署之前在本地运行这些命令。的