【发布时间】:2026-01-01 09:00:01
【问题描述】:
我正在使用代码管道为在 Elastic Beanstalk 中运行的 Ruby on Rails 应用程序创建 CI\CD。我的代码构建成功,但部署到 EBS 提供程序失败并出现以下错误
+ cd /var/app/ondeck
+ su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb db:migrate' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler20211229-11836-pzl6dq11836' as your home directory temporarily.
+ '[' false = true ']'
+ su -s /bin/bash -c 'leader_only bundle exec rake db:migrate' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler20211229-11840-9hxmcz11840' as your home directory temporarily.
rake aborted!
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
/opt/rubies/ruby-2.6.7/bin/bundle:23:in `load'
/opt/rubies/ruby-2.6.7/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace) (Executor::NonZeroExitStatus)
我有
mysql --version
mysql Ver 14.14 Distrib 5.5.62, for Linux (x86_64) using readline 5.1
并且可以连接到外部 RDS MySQL Aurora 数据库。
我的 Buildspec.yml:
version: 0.2
phases:
install:
runtime-versions:
ruby: 2.6
commands:
- echo Installing Bundler...
- gem install bundler
- bundle install
pre_build:
commands:
- echo Preparing database to run tests...
- bundle exec rails db:create --trace RAILS_ENV=production
build:
commands:
- echo Running tests...
- bundle exec rails test/test_helper.rb
artifacts:
files:
- '**/*'
我的数据库.yml:
default: &default
adapter: mysql2
encoding: utf8mb4
collation: utf8mb4_unicode_ci
pool: 5
timeout: 5000
username: <%= ENV['DB_USER'] %>
password: <%= ENV['DB_PASSWORD'] %>
host: <%= ENV['DB_HOST'] %>
port: <%= ENV['DB_PORT'] %>
development:
<<: *default
database: <%= ENV['DB'] %>
test:
<<: *default
database: <%= ENV['DB_TEST'] %>
production:
<<: *default
database: <%= ENV['DB'] %>`
【问题讨论】:
-
如果是外部数据库,为什么要连接到本地?将您的应用设置为连接到远程主机,而不是本地主机。
-
是的..我可以理解,但是当我运行我的代码管道以部署到 aws elastic beanstalk 时,它会因提到的错误而失败。
-
我在 ec2 实例中尝试了以下配置,但问题仍然存在。 [ec2-user@ip-xx.xx.xx 等]$ cat my.cnf [mysqld] datadir=/var/lib/mysql #socket=/var/lib/mysql/mysql.sock
标签: mysql ruby-on-rails amazon-web-services amazon-elastic-beanstalk amazon-rds