LoginSignup
0

More than 3 years have passed since last update.

posted at

updated at

RailsプロジェクトのDockerをクローンして、RefineryCMSを追加した際の手順

当記事について

  • タイトルの通り。その際に行ったことをひたすら羅列している。

参考サイト

RailsプロジェクトDockerイメージ関係の手順

  • 任意のフォルダで下記コマンド実行
git clone https://github.com/kawasin73/rails_docker_template.git .
git checkout origin/base/ruby-2.5.1-rails-5.2.0
git branch -d master && git checkout -b master

  • GemfileのRailsバージョンを5.2.0から5.1.7に編集
Gemfile
source 'https://rubygems.org'
ruby '2.5.1'

gem 'rails', '5.1.7'   # ← 編集後
  • 下記コマンドを実行
script/init && script/bootstrap

script/init実行時、こんなエラーメッセージが出たら、私の環境ではDockerを再起動すると解消しました

ERROR: for xxxx_db_1  Cannot start service db: b'driver failed programming external connectivity on endpoint xxxx_db_1 (849e14279bfc5461a0a142fb24b7581b72a2bf962abbd0fa09af529ccf1f7f1c): Bind for 0.0.0.0:5432 failed: port is already allocated'
  • 必要な場合のみ
    script/bootstrap実行時にyarn install・・・を実行するようにログが出たので、下記を実行
docker-compose run rails yarn install --check-files

必要な場合のみ
上記を実行すると下記コマンドを実行するよう、ログに出力があったので、実行

下記はbashにログイン後、実行した

docker-compose run rails bash
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
  • Rails環境作成後の起動確認
docker-compose up

image.png

Refinery環境作成

既存のRailsプロジェクトにRefineryCMSを追加

gem 'refinerycms'
gem 'refinerycms-authentication-devise' # 認証機能が必要な場合のみ
gem 'refinerycms-wymeditor'  # WYMエディタ 無くてもRefineryCMSは動くっぽい
  • bundle install 実行
docker-compose run rails bundle install

実行すると、下記の状態が続き、1晩経っても完了しなかった

bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies..................................................

control + c で強制終了し、いくつかコマンドを実行した後、
再度bundle installを実行すると普通に正常終了した。
コマンド実行で解決したのか、時間経過で解決したのか、原因は不明なまま。
その際に実行したコマンドは下記の通り。
docker-compose run rails bash
でbashを起動した実行したり、しなかったり。

gem install bundler --pre
gem install 'refinerycms' #追加したgemの個別インストール
gem install 'refinerycms-authentication-devise' #追加したgemの個別インストール
gem install 'refinerycms-wymeditor' #追加したgemの個別インストール
bundle update
  • こんなエラーも複数のgemに対して出てた
xxxxxx because its extensions are not built.  Try: gem pristine xxxxxx

下記コマンドで解消した

gem pristine --all
  • 既存RailsプロジェクトにRefineryCMS機能を付与(マイグレーションとか)
docker-compose run rails rails generate refinery:cms --fresh-installation
  • ひとまずrailsを起動してみたら、postgresqlのエラーが出力された
$ docker-compose up
  :
PG::ConnectionBad (could not connect to server: Connection refused
rails_1  |      Is the server running on host "db" (127.0.0.1) and accepting
rails_1  |      TCP/IP connections on port 5432?
rails_1  | could not connect to server: Cannot assign requested address
rails_1  |      Is the server running on host "db" (::1) and accepting
rails_1  |      TCP/IP connections on port 5432?

エラーメッセージでググってみて、ここのサイトのCase3 を参考に、
下記ファイルを修正した

/etc/hosts
#before
127.0.0.1       localhost
↓
#after
127.0.0.1       localhost db

rails db:migrate:resetを実行すると、
「data directoryがイニシャライズされたバージョンが、互換性の無いバージョンだよ」
みたいなログが出力されたので、
下記ファイルのdb imageの指定を自分の環境のバージョンに合わせて修正した

docker-compose.yml
# before
  db:
    image: "postgres:10.3"
↓
# after
  db:
    image: "postgres:11.5"

  • マイグレーションのリセットとシード
docker-compose run rails rails db:migrate:reset
docker-compose run rails rails db:seed      
  • 下記コマンドで起動し、 http://localhost:3000/ でRefineryCMSのデフォルト画面が表示された
docker-compose up

image.png

この状態でリモートにプッシュしとく

  • railsプロジェクトのdockerイメージをcloneしているので、
    リモートリポジトリのurlを変更したい
  • 今後利用するリモートリポジトリはすでに作成してあるので、
    別の任意フォルダに一旦cloneし、.git/configファイルを今まで開発していたフォルダの.git/configに上書きした
  • 上記を済ませた後、下記コマンド実行
git add .
git commit -am "xxxxx"
git push

git push 実行時下記のエラーが出たので、

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://takanori_yoshioka@bitbucket.org/takanori_yoshioka/lambellweb.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

ローカルリポジトリを強制的にリモートリポジトリにpushした
(ローカルリポジトリの内容をリモートリポジトリに上書き)

git push -f origin master 

おしまい

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0