Coder Social home page Coder Social logo

orumin / enju_leaf Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 3.0 44 KB

Project-L Enju Leaf (https://github.com/next-l/enju_leaf) を円滑に運用するための Docker イメージ

Home Page: https://hub.docker.com/r/orumin/enju_leaf

License: MIT License

Dockerfile 34.99% Shell 18.55% Ruby 46.45%

enju_leaf's Introduction

docker image for enju_leaf

これは何ですか

  • 公式では VM が用意されていますがより手軽に試すために作成したイメージです
  • なるべく docker way な感じに継続的な運用が可能なイメージを目指しました
  • Alpine ベースの比較的軽量なイメージです

はじめに

以降の説明は,次のコマンド

git clone https://github.com/orumin/enju_leaf.git
cd enju_leaf

を行ない,enju_leaf ディレクトリをワーキングディレクトリとして作業するものとして説明します。

インストール(初回起動)

初回の起動は以下の手順で行います。

イメージの取得

docker-compose pull

環境変数の設定とシークレットの設定

cp .env.production.sample .env.production # ファイル中の UID と GID を変更する際には docker-compose build が必要。後述。
echo SECRET_KEY_BASE=`docker-compose run --rm web bundle exec rake secret` >> .env.production

デフォルトのカバー画像・書誌形態画像,マイグレーションファイルの保存

id=`docker create orumin/enju_leaf:1.3.3`
docker cp $id:/enju_leaf/db/migrate .
docker cp $id:/enju_leaf/private/system .
docker rm -v $id

mkdir solr
sudo chown 991:991 -R ./system ./migrate ./solr # .env.production の UID と GID の値に合わせる

データベースの初期設定

export DB_USER=enju_leaf DB_NAME=enju_leaf_production DB_PASS=admin # .env.production に合わせる
export POSTGRES_PASSWORD=admin # DB の初期化に必要
docker-compose up -d db \
  && sleep 10 \
  && docker-compose exec -u postgres db sh -c "echo create user ${DB_USER} with password \'${DB_PASS}\' createdb\; | psql -f -" \
  && docker-compose exec -u postgres db createdb -U ${DB_USER} ${DB_NAME}
export POSTGRES_PASSWORD= # 不要な環境変数のリセット
docker-compose up -d solr
docker-compose run --rm web bundle exec rake db:migrate
docker-compose run --rm web bundle exec rake enju_leaf:setup
docker-compose run --rm web bundle exec rake enju_circulation:setup
docker-compose run --rm web bundle exec rake enju_subject:setup
docker-compose run --rm web bundle exec rake db:seed

アセットファイルのプリコンパイル

mkdir -p assets
sudo chown 991:991 -R ./assets # .env.production の UID と GID の値に合わせる
docker-compose run --rm web bundle exec rake assets:precompile

データベース更新とアセットのロード

docker-compose run --rm web bundle exec rake enju_leaf:upgrade
docker-compose run --rm web bundle exec rake enju_leaf:load_asset_files

起動

docker-compose up -d
sleep 30 && docker-compose exec solr bundle exec rake environment sunspot:reindex

ログイン

初期設定ではユーザー名 enjuadmin パスワード adminpassword でログインできます。 以降のシステム設定や OPAC 運用方法などは 公式マニュアル をご覧ください。

毎回の起動方法と終了方法

起動

docker-compose up -d
sleep 30 && docker-compose exec solr bundle exec rake environment sunspot:reindex

終了

docker-compose down

アップデート(1.2.2 から 1.3.1 で動作確認)

初回起動時に作成した ./migrate ディレクトリとその中身のマイグレーションファイルが同じディレクトリに配置されていること, 既に一度システムが起動済であり PostgreSQL のロールやデータベース・テーブルなどが設定されていること, そのデータベースが ./postgres に存在していることが前提です。

Dockerfile の更新とコンテナの更新(ビルド)

git pull
docker-compose pull # コンテナのビルドの際には sudo docker-compose build --pull

マイグレーションの実行

# 1.2.1 以下から 1.2.2 以上へのアップデートの時はおそらく
# docker-compose run --rm web bundle exec rake railties:install:migrations
# でマイグレーションファイルを追加する必要がある。
# ほかにも migrate に先立って必要な作業が随時発生する可能性があるため,
# 公式ドキュメント https://github.com/next-l/enju_leaf/wiki/Update を参考の上で実施すること
docker-compose run --rm web bundle exec rake db:migrate
docker-compose run --rm web bundle exec rake enju_leaf:upgrade

アセットのプリコンパイル

docker-compose run --rm web bundle exec rake assets:precompile

システムを停止と再起動

docker-compose stop && docker-compose up -d
sleep 30 && docker-compose exec solr bundle exec rake environment sunspot:reindex

バックアップと他マシンでの起動

バックアップ

この作業ディレクトリをまるごとバックアップしてください。

他マシンでの起動

まずバックアップしたディレクトリを移動し,その中で新しいマシンでの作業を行います。

以下のように権限を修正してください。

chown 70:0 -R ./postgres
sudo chown 991:991 -R ./system ./assets ./migrate # .env.production の UID と GID の値に合わせる

最後に起動を行います。

docker-compose up -d
sleep 30 && docker-compose exec sorl bundle exec rake environment sunspot:reindex

.env.production について

UID と GID ならびに DB_USER の変更はコンテナのビルドを伴う必要があります。 具体的には以下のようにビルドを行った後に .env.production に変更を反映させてください。

docker-compose build \
    --build-arg UID=1000 \
    --build-arg GID=1000 \
    --build-arg DB_USER=enju

また,DB_USER, DB_NAME, DB_PASS の変更の際にはデータベースの再設定が必要です。

# OLD_DB_USER は DB_USER を変更する前の値
# OLD_DB_NAME は DB_NAME を変更する前の値
export OLD_DB_USER=enju_leaf DB_USER=enju \
       OLD_DB_NAME=enju_leaf_production DB_NAME=production \
       DB_PASS=root
docker-compose up -d db \
  && sleep 10 \
  && docker-compose exec -u postgres db sh -c "pg_dump ${OLD_DB_NAME} > enju_dump.sql" \
  && docker-compose exec -u postgres db dropdb ${OLD_DB_NAME} \
  && docker-compose exec -u postgres db sh -c "echo drop user ${OLD_DB_USER} | psql -f -" \
  && docker-compose exec -u postgres db sh -c "echo create user ${DB_USER} with password \'${DB_PASS}\' createdb\; | psql -f -" \
  && docker-compose exec -u postgres db createdb -U ${DB_USER} ${DB_NAME}
  && docker-compose exec -u postgres db psql ${DB_NAME} -f enju_dump.sql

おそらく,運用上では,.env.production で設定した UID, GID と同じ値を持つユーザーを作成し, そのユーザーのホームディレクトリ以下で運用するといちいち chown などで権限を変更する手間が省けると思われます。

同梱のシェルスクリプトについて

install.sh, update.sh, start.sh, stop.sh は本 README で解説したそれぞれの手順をシェルスクリプトにしたものです。 とくにエラーチェックなどは一切しない簡易なものなので参考程度にしてください。 また, install.shsudo をつけて実行することが好ましいと思われます。

enju_leaf's People

Contributors

boronology avatar orumin avatar yufushiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

enju_leaf's Issues

Postgres12ではデータベースの初期設定時にPOSTGRES_PASSWORD環境変数が必要

READMEにある手順

export DB_USER=enju_leaf DB_NAME=enju_leaf_production DB_PASS=admin # .env.production に合わせる
docker-compose up -d db \
  && sleep 10 \
  && docker-compose exec -u postgres db sh -c "echo create user ${DB_USER} with password \'${DB_PASS}\' createdb\; | psql -f -" \
  && docker-compose exec -u postgres db createdb -U ${DB_USER} ${DB_NAME}

を実行すると

Error response from daemon: Container *** is restarting, wait until the container is running

となり失敗する。
docker-compose logsによると

db_1 | Error: Database is uninitialized and superuser password is not specified.
db_1 | You must specify POSTGRES_PASSWORD to a non-empty value for the
db_1 | superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
db_1 |
db_1 | You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
db_1 | connections without a password. This is not recommended.
db_1 |
db_1 | See PostgreSQL documentation about "trust":
db_1 | https://www.postgresql.org/docs/current/auth-trust.html

となっているため、一時的にdocker-compose.ymlで

    environment:
      - POSTGRES_PASSWORD=admin

する等の対応が必要になる。

DBの初期設定でSolrに依存する処理がある

事象

README中のデータベースの初期設定において

docker-compose run --rm web bundle exec rake enju_leaf:setup

を実行すると失敗する。

ログ

RSolr::Error::ConnectionRefused: Connection refused - {:data=>"[{"id":"Shelf 1","type":["Shelf","ApplicationRecord","ActiveRecord::Base"],"class_name":"Shelf","shelf_name_s":"web","library_s":"web","position_i":"1","name_text":["web","web","ja: web","World Wide Web"]}]", :headers=>{"Content-Type"=>"application/json"}, :method=>:post, :params=>{:wt=>:json}, :query=>"wt=json", :path=>"update", :uri=>#<URI::HTTP http://solr:8983/solr/default/update?wt=json>}

Caused by:
Faraday::ConnectionFailed: Failed to open TCP connection to solr:8983 (getaddrinfo: Name does not resolve)

等となっており、Solrとの通信が必要だったことがわかる。

対応案

export DB_USER=enju_leaf DB_NAME=enju_leaf_production DB_PASS=admin # .env.production に合わせる
docker-compose up -d db \
  && sleep 10 \
  && docker-compose exec -u postgres db sh -c "echo create user ${DB_USER} with password \'${DB_PASS}\' createdb\; | psql -f -" \
  && docker-compose exec -u postgres db createdb -U ${DB_USER} ${DB_NAME}
docker-compose up -d solr # <- new
docker-compose run --rm web bundle exec rake db:migrate
docker-compose run --rm web bundle exec rake enju_leaf:setup
docker-compose run --rm web bundle exec rake enju_circulation:setup
docker-compose run --rm web bundle exec rake enju_subject:setup
docker-compose run --rm web bundle exec rake db:seed

ISBNだけ指定したときのTSVインポートに失敗する

TSVインポート時にISBNを指定するとexecution_expiredでインポートに失敗する。

docker-compose.yml でresqueのnetworkにexternal_networkを足したところ解決した。

環境

  • dockerを実行しているOS: Windows 10 pro 64bitのvirtualbox上に建てたubuntu-server 17.10
  • ubuntu-serverのネットワーク: NATとホストオンリーアダプタ

resqueに出ていたエラーの詳細

Exception: Net::OpenTimeout
Error: execution expired
/usr/local/lib/ruby/2.6.0/net/http.rb:947:in `initialize'
/usr/local/lib/ruby/2.6.0/net/http.rb:947:in `open'
/usr/local/lib/ruby/2.6.0/net/http.rb:947:in `block in connect'
/usr/local/lib/ruby/2.6.0/timeout.rb:103:in `timeout'
/usr/local/lib/ruby/2.6.0/net/http.rb:945:in `connect'
/usr/local/lib/ruby/2.6.0/net/http.rb:930:in `do_start'
/usr/local/lib/ruby/2.6.0/net/http.rb:919:in `start'
/usr/local/lib/ruby/2.6.0/open-uri.rb:337:in `open_http'
/usr/local/lib/ruby/2.6.0/open-uri.rb:756:in `buffer_open'
/usr/local/lib/ruby/2.6.0/open-uri.rb:226:in `block in open_loop'
/usr/local/lib/ruby/2.6.0/open-uri.rb:224:in `catch'
/usr/local/lib/ruby/2.6.0/open-uri.rb:224:in `open_loop'
/usr/local/lib/ruby/2.6.0/open-uri.rb:165:in `open_uri'
/usr/local/lib/ruby/2.6.0/open-uri.rb:736:in `open'
/usr/local/lib/ruby/2.6.0/open-uri.rb:744:in `read'
/usr/local/lib/ruby/2.6.0/rss/parser.rb:122:in `normalize_rss'
/usr/local/lib/ruby/2.6.0/rss/parser.rb:108:in `initialize'
/usr/local/lib/ruby/2.6.0/rss/parser.rb:85:in `new'
/usr/local/lib/ruby/2.6.0/rss/parser.rb:85:in `parse'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_ndl-0.3.0/lib/enju_ndl/ndl_search.rb:266:in `search_ndl'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_ndl-0.3.0/lib/enju_ndl/ndl_search.rb:279:in `return_xml'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_ndl-0.3.0/lib/enju_ndl/ndl_search.rb:30:in `import_from_ndl_search'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_ndl-0.3.0/lib/enju_ndl/ndl_search.rb:10:in `import_isbn'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_biblio-0.3.1/app/models/resource_import_file.rb:163:in `block in import'
/usr/local/lib/ruby/2.6.0/csv/parser.rb:699:in `emit_row'
/usr/local/lib/ruby/2.6.0/csv/parser.rb:259:in `parse'
/usr/local/lib/ruby/2.6.0/csv.rb:1171:in `each'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_biblio-0.3.1/app/models/resource_import_file.rb:80:in `import'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_biblio-0.3.1/app/models/resource_import_file.rb:49:in `import_start'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/enju_biblio-0.3.1/app/jobs/resource_import_file_job.rb:5:in `perform'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/execution.rb:37:in `block in perform_now'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:108:in `block in run_callbacks'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/i18n-1.5.3/lib/i18n.rb:284:in `with_locale'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/translation.rb:7:in `block (2 levels) in <module:Translation>'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:117:in `instance_exec'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/logging.rb:24:in `block (4 levels) in <module:Logging>'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/notifications.rb:166:in `block in instrument'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/notifications.rb:166:in `instrument'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/logging.rb:23:in `block (3 levels) in <module:Logging>'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/logging.rb:44:in `block in tag_logger'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/tagged_logging.rb:69:in `block in tagged'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/tagged_logging.rb:26:in `tagged'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/tagged_logging.rb:69:in `tagged'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/logging.rb:44:in `tag_logger'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/logging.rb:20:in `block (2 levels) in <module:Logging>'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:117:in `instance_exec'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:135:in `run_callbacks'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/execution.rb:33:in `perform_now'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/execution.rb:22:in `block in execute'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:108:in `block in run_callbacks'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/railtie.rb:26:in `block (4 levels) in <class:Railtie>'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/execution_wrapper.rb:85:in `wrap'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/reloader.rb:68:in `block in wrap'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/execution_wrapper.rb:85:in `wrap'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/reloader.rb:67:in `wrap'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/railtie.rb:25:in `block (3 levels) in <class:Railtie>'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:117:in `instance_exec'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6.1/lib/active_support/callbacks.rb:135:in `run_callbacks'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/execution.rb:20:in `execute'
/enju_leaf/vendor/bundle/ruby/2.6.0/gems/activejob-5.1.6.1/lib/active_job/queue_adapters/resque_adapter.rb:45:in `perform'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.