Travis 部署 zip 而不是 jar
Posted
技术标签:
【中文标题】Travis 部署 zip 而不是 jar【英文标题】:Travis deploys a zip instead of a jar 【发布时间】:2017-03-24 00:28:47 【问题描述】:我正在尝试将一个 jar 从 travis ci 自动部署到 aws elastic beanstalk。在我看来,travis 正在上传包含源代码内容的 zip 文件,而不是上传构建的 jar。根据文档,我不清楚如何指示 travis 上传 jar 而不是原始源代码。
.travis.yml
language: java
jdk:
- oraclejdk8
deploy:
provider: elasticbeanstalk
skip_cleanup: true
app: OptionsTradeAnalysis
env: ota-api-env
file: "ota.jar"
bucket_name: elasticbeanstalk-us-west-2-302145366589
region: us-west-2
access_key_id:
secure: key
secret_access_key:
secure: key
on:
repo: melchoir55/OptionsAnalysis
branch: master
这是 beantalk 的输出。详细介绍了尝试执行travis上传的文件时遇到的问题:
Beanstalk 错误日志
Application update failed at 2016-11-10T03:52:56Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/01_configure_application.sh failed.
Executing: /usr/bin/unzip -o -d /var/app/staging /opt/elasticbeanstalk/deploy/appsource/source_bundle
Archive: /opt/elasticbeanstalk/deploy/appsource/source_bundle
inflating: /var/app/staging/.gitignore
inflating: /var/app/staging/.gradle/2.13/taskArtifacts/cache.properties
inflating: /var/app/staging/.gradle/2.13/taskArtifacts/cache.properties.lock
inflating: /var/app/staging/.gradle/2.13/taskArtifacts/fileHashes.bin
inflating: /var/app/staging/.gradle/2.13/taskArtifacts/fileSnapshots.bin
inflating: /var/app/staging/.gradle/2.13/taskArtifacts/taskArtifacts.bin
inflating: /var/app/staging/.travis.yml
inflating: /var/app/staging/LICENSE
inflating: /var/app/staging/README.md
inflating: /var/app/staging/build.gradle
inflating: /var/app/staging/gradle/wrapper/gradle-wrapper.jar
inflating: /var/app/staging/gradle/wrapper/gradle-wrapper.properties
inflating: /var/app/staging/gradlew
inflating: /var/app/staging/gradlew.bat
inflating: /var/app/staging/settings.gradle
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/Application.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/api/ApiConstants.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/api/resourceController/OptionTransactionController.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/api/resourceController/VersionController.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/database/dao/OptionDao.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/database/dao/OptionTransactionDao.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/database/dao/PriceDao.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/database/dao/StockDao.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/Analysis/PercentageGain.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/Analysis/TimeRange.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/ModelUtils.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/Option.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/OptionPrice.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/OptionTransaction.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/Price.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/Stock.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/StockPrice.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/TransactionAnalysis.java
inflating: /var/app/staging/src/main/java/com/zowda/optionsAnalysis/model/User.java
inflating: /var/app/staging/src/main/resources/application.properties
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/api/ApiTestUtils.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/api/resourceController/OptionTransactionControllerTest.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/api/resourceController/VersionControllerTest.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/database/DatabaseBasicsTest.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/model/analysis/PercentageGainTest.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/model/analysis/TimeRangeTest.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/model/testFactories/OptionTransactionTestFactory.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/model/testFactories/PercentageGainTestFactory.java
inflating: /var/app/staging/src/test/java/com/zowda/optionsAnalysis/test/model/testFactories/TimeRangeTestFactory.java
inflating: /var/app/staging/src/test/resources/application.properties
Unable to launch application as the source bundle does not contain either a file named application.jar or a Procfile.
Unable to launch application as the source bundle does not contain either a file named application.jar or a Procfile.
Incorrect application version "travis-d1bff950714be0a82e46a827346ada041aa71aad-1478749923" (deployment 6). Expected version "Sample Application" (deployment 1).
请注意,我也尝试在不使用 file
参数的情况下运行它,因为我不清楚该参数的作用。我得到了同样的结果。正如您在此处看到的,我假设该参数用于命名 travis 正在部署的文件,但根据我得到的行为,我认为我可能是错误的。我突然想到,可能是开发人员指定要上传的文件的位置,但我不知道 travis 将构建的 jar 放在哪里。
【问题讨论】:
弹性豆茎支持在 Travis 中是实验性的吗?到目前为止,这就是我所看到的。如果您有相关文档,也许我们可以提供进一步帮助。不过,我想我会避免使用实验性功能。您可以使用 Travis S3 功能将文件 zip 或 jar 推送到 S3。然后设置 AWS CodePipeline 以部署到 ElasticBeanstalk。这都是本机功能,易于设置。 这很公平,不过,AWS CodeDeploy 也会存在同样的问题(我假设您指的是 CodeDeploy 而不是 CodePipeline)。 CodeDeploy 配置似乎希望您指定包(jar 的位置)。我不知道 travis 将构建的 jar 存储在哪里,文档并没有给我一种方法来弄清楚我可以看到。 【参考方案1】:最终,这里有两个问题。首先是 gradle 实际上并没有输出 jar。我修改了 build.gradle 来做到这一点。其次,似乎在创建 elasticbeanstalk 支持时并未考虑到 java(或任何编译语言)。也就是说,仍然有可能让它工作。关键字段是zip_file
。这个字段最好命名为archive
甚至file
,因为你可以传递罐子、战争、拉链或任何你喜欢的东西。以下.travis.yml
为我工作:
.travis.yml
language: java
jdk:
- oraclejdk8
deploy:
provider: elasticbeanstalk
skip_cleanup: true
app: OptionsTradeAnalysis
env: ota-api-env
zip_file: 'build/libs/OptionsAnalysis-1.0.jar'
bucket_name: elasticbeanstalk-us-west-2-302145366589
region: us-west-2
access_key_id:
secure: key
secret_access_key:
secure: key
on:
repo: melchoir55/OptionsAnalysis
branch: master
注意zip_file
中指定的路径是gradle输出构建的jar相对于工作目录的路径。
【讨论】:
以上是关于Travis 部署 zip 而不是 jar的主要内容,如果未能解决你的问题,请参考以下文章
如何在 travis 部署脚本中运行 aws configure?