概要
railsのアプリでrubyのバージョンを上げようと思って.circleci/config.yml
のimageを変更したらmysqlに接続できなくなってちょっとはまったので共有しておきます。
結論
-
mysql-client
パッケージ名がdefault-mysql-client
に変わったので変更する。 -
bundle install
のキャッシュの消さないとmysql-client
のパッケージが変わったので接続できない。
やったこと
config.ymlを以下のように変更してpush。
※ config.ymlは関係ない部分を省略してます。
.circleci/config.yml
version: 2.1
jobs:
build:
docker:
- - image: circleci/ruby:2.6.1-node-browsers
+ - image: circleci/ruby:2.6.3-node-browsers
- image: circleci/mysql:5.7-ram
steps:
- run:
name: Install depencies
command: |
sudo apt-get install -y mysql-client
- restore_cache:
keys:
- cache-bundle-{{ checksum "Gemfile.lock" }}
- cache-bundle-
- run:
name: bundle
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: cache-bundle-{{ checksum "Gemfile.lock" }}
CirclCIでInstall depencies
のところでこんなエラーでこけました。
Package mysql-client is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'mysql-client' has no installation candidate
Exited with code 100
こちらが参考になりましたが、パッケージ名がmysql-client
からdefault-mysql-client
に変わったので変更します。
.circleci/config.yml
version: 2.1
jobs:
build:
docker:
- image: circleci/ruby:2.6.3-node-browsers
- image: circleci/mysql:5.7-ram
steps:
- run:
name: Install depencies
command: |
- sudo apt-get install -y mysql-client
+ sudo apt-get install -y default-mysql-client
これでインストールは成功しますが、今度はbundle exec rails db:migrate --trace
してるところで下記のようなエラーで止まります。
#!/bin/bash -eo pipefail
bundle exec rails db:migrate --trace
rails aborted!
LoadError: libmariadbclient.so.18: cannot open shared object file: No such file or directory - /home/circleci/test_dir/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.so
/home/circleci/test_dir/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/home/circleci/test_dir/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
...以下長いバックトレース
mysql-client
が変わったのでbundle install
をやり直してmysql2
のnative extensions
コンパイルをやり直さないといけません。bundle install
は時間がかかるので大抵の人がキャッシュしてると思います。多分皆さんここではまるんじゃないかと。
今回はキャッシュの名前を変更して対応しました。
.circleci/config.yml
- restore_cache:
keys:
- - cache-bundle-{{ checksum "Gemfile.lock" }}
+ - cache-bundle-v1-{{ checksum "Gemfile.lock" }}
- - cache-bundle-
+ - cache-bundle-v1-
- run:
name: bundle
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
- key: cache-bundle-{{ checksum "Gemfile.lock" }}
+ key: cache-bundle-v1-{{ checksum "Gemfile.lock" }}