Travis CI 部署到 AWS ElasticBeanstalk
Posted
技术标签:
【中文标题】Travis CI 部署到 AWS ElasticBeanstalk【英文标题】:Travis CI Deploy to AWS ElasticBeanstalk 【发布时间】:2020-07-01 05:57:54 【问题描述】:您好,我目前尝试通过 travis CI 将我的反应应用程序部署到 AWS Elastic Bean Stalk。但它失败了..我应该在我的 travis yml 中更改什么?
这是我的 .travis.yml
sudo: required
services:
- docker
before_install:
- docker build -t sample:dev .
script:
- docker run -e CI=true sample:dev npm run test -- --coverage
deploy:
provider: elasticbeanstalk
region: "us-west-1"
app: "my-app"
env: "MyApp-env"
bucket_name: "xxxx"
bucket_path: "xxx"
on:
branch: master
access_key_id: $AWS_ACCESS_KEY
secret_access_key:
secure: "$AWS_SECRET_KEY"
但我未能将其部署在 aws elastic bean stalk 中。以下是来自 travis ci 的信息:
命令 "docker run -e CI=true sample:dev npm run test -- --coverage" 以 0 退出。
dpl_0
1.27s$ rvm $(travis_internal_ruby) --fuzzy do ruby -S gem install dpl
dpl.1
安装部署依赖项
成功安装jmespath-1.4.0
成功安装 aws-eventstream-1.0.3
成功安装 aws-sigv4-1.1.1
更新版本可用:请升级到适用于 Ruby V3 的 AWS 开发工具包
成功安装 aws-sdk-core-2.11.471
更新版本可用:请升级到适用于 Ruby V3 的 AWS 开发工具包
成功安装 aws-sdk-resources-2.11.471
更新版本可用:请升级到适用于 Ruby V3 的 AWS 开发工具包
成功安装 aws-sdk-2.11.471
成功安装rubyzip-1.3.0
成功安装dpl-elastic_beanstalk-1.10.15
安装了 8 个宝石
!!! AWS Elastic Beanstalk 支持是实验性的!!!
dpl.2
准备部署
使用git stash --all
清理 git 存储库。如果您需要构建工件进行部署,请设置deploy.skip_cleanup: true
。见https://docs.travis-ci.com/user/deployment#Uploading-Files-and-skip_cleanup。
没有要保存的本地更改
更新版本可用:请升级到适用于 Ruby V3 的 AWS 开发工具包
dpl.3
部署应用程序
未找到隐藏条目。
/home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/seahorse/client/plugins/raise_response_errors.rb:15:in call': The request signature we calculated does not match the signature you provided. Check your key and signing method. (Aws::S3::Errors::SignatureDoesNotMatch)
from /home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/aws-sdk-core/plugins/s3_sse_cpk.rb:19:in
call'
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/aws-sdk-core/plugins/s3_dualstack.rb:24:in call'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/aws-sdk-core/plugins/s3_accelerate.rb:34:in
call '
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in call'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/aws-sdk-core/plugins/idempotency_token.rb:18:in
call '
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/aws-sdk-core/plugins/param_converter.rb:20:in call'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/seahorse/client/plugins/response_target.rb:21:in
call '
来自 /home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/seahorse/client/request.rb:70:in send_request'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-core-2.11.471/lib/seahorse/client/base.rb:207:in
block(2 级)在定义操作方法'
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-resources-2.11.471/lib/aws-sdk-resources/request.rb:24:in call'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-resources-2.11.471/lib/aws-sdk-resources/operations.rb:41:in
call'
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/aws-sdk-resources-2.11.471/lib/aws-sdk-resources/operation_methods.rb:19:in block in add_operation'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-elastic_beanstalk-1.10.15/lib/dpl/provider/elastic_beanstalk.rb:131:in
upload'
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-elastic_beanstalk-1.10.15/lib/dpl/provider/elastic_beanstalk.rb:49:in push_app'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-1.10.15/lib/dpl/provider.rb:199:in
block in deploy'
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-1.10.15/lib/dpl/cli.rb:41:in fold'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-1.10.15/lib/dpl/provider.rb:199:in
deploy'
来自/home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-1.10.15/lib/dpl/cli.rb:32:in run'
from /home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-1.10.15/lib/dpl/cli.rb:7:in
run'
来自 /home/travis/.rvm/gems/ruby-2.4.5/gems/dpl-1.10.15/bin/dpl:5:in <top (required)>'
from /home/travis/.rvm/gems/ruby-2.4.5/bin/dpl:23:in
load'
来自 /home/travis/.rvm/gems/ruby-2.4.5/bin/dpl:23:in `'
部署失败
【问题讨论】:
【参考方案1】:基于新版Travis CI,以下几行代码,需要更新
secret_access_key:
secure: "$AWS_SECRET_KEY"
将其更改为:
secret_access_key: "$AWS_SECRET_KEY"
还需要在 deploy 下添加“skip_cleanup: true”:
因为 Travis CI 现在认为默认变量是安全的。
【讨论】:
【参考方案2】:查看输出中的第一个错误:
call': The request signature we calculated does not match the signature you provided. Check your key and signing method. (Aws::S3::Errors::SignatureDoesNotMatch)
我遇到了同样的错误,这是由 access_key_id
和 secret_access_key
不匹配引起的。我通过运行解决了它:
travis encrypt --add deploy.access_key_id <access_key_id>
travis encrypt --add deploy.secret_access_key <secret_access_key>
【讨论】:
以上是关于Travis CI 部署到 AWS ElasticBeanstalk的主要内容,如果未能解决你的问题,请参考以下文章
带有 docker 的 AWS Elastic Beanstalk 版本不正确
AWS CodePipeline - 使用现有 Dockerrun.aws.json 部署到 Elastic Beanstalk