javaamazon-web-servicesamazon-elastic-beanstalktravis-ciautomated-deploy

Travis deploys a zip instead of a jar


I'm trying to automatically deploy a jar from travis ci to aws elastic beanstalk. It looks to me like travis is uploading a zip file with the contents of the source code, rather than uploading the built jar. It isn't clear to me based on the documentation how to instruct travis to upload the jar instead of the raw source code.

.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

Here is the output from beanstalk. It details the problems it encountered when trying to execute the file travis uploaded:

Beanstalk Error Log

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).

Please note I have also tried running it without the file parameter, since it isn't clear to me what that parameter does. I got the same result. As you can see here I am assuming the parameter is used to name the file that travis is deploying, but based on the behavior I'm getting I think I could be wrong. It occurs to me that it could be for the developer to specify the location of the file to upload, but I have no idea where travis is placing the built jar.


Solution

  • Ultimately, there were two problems here. The first was that gradle wasn't actually outputting a jar. I modified build.gradle to do that. Secondly, it appears that the elasticbeanstalk support was not created with java (or any compiled language) in mind. That said, it is still possible to get it to work. The key field is zip_file. This field would better be named archive or even file, because you can pass jars, wars, zips, or whatever you like. The below .travis.yml worked for me:

    .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
    

    Note that the path specified in zip_file is the path to which gradle outputs the built jar relative to the working directory.