WordPressのAdvanced Custom Fieldsでwidgetを作る話
docker & rails6で開発を始める
rails5.2とDockerとwebpackerとbootstrap4【設定編】
docker-composeのサンプル
docker-composeのサンプルポイントは以下の点
- bundle installしたディレクトリを永続化する じゃないとコンテナ立ち上げるたびにbundle installが必要になる
- depends_onでdbを先に起動させる
- dbのdataディレクトリも永続化させる
version: '3'
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
- bundle-data:/usr/local/bundle
ports:
- 3000:3000
depends_on:
- db
tty: true
stdin_open: true
db:
image: mysql:5.7
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
db-data:
driver: local
bundle-data:
driver: local
rails5.2とDockerとwebpackerとbootstrap4【インストール編】
タイトルの通り、この記事ではDocker上で動くrails+webpackerのちょっとした経験を記述しようと思う。
探してみるとwebpackerをrails上で動かす記事はまぁまぁある。
だがしかし、webpackerがcssをjsにbundleする関係で単純にそのまま使うとFOUC問題が起きる。
何故かそれに触れているサイトはほぼ皆無。
なので自分でなんとかしてみた、というのがこの記事の趣旨である。
ちなみにFOUCとは別サイトでは下記のように説明されている。
FOUC(Flash of Unstyled Content)とは、Webページへアクセスした直後、CSSによるデザインが有効でないページが一瞬だけ表示される現象のことです。
結論から言うと、webpackerのjsにbundleされるcssを分離してstaticファイルとして読み込めるようにするのが肝である
そうだ。Dockerを入れよう
anyenvインストール済みのmacでbrew doctorを実行したらwarningが出る場合
[xxxxx@MacBook-Air:~]$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Users/xxxxx/.anyenv/envs/pyenv/shims/python2-config
/Users/xxxxx/.anyenv/envs/pyenv/shims/python3.6m-config
/Users/xxxxx/.anyenv/envs/pyenv/shims/python2.7-config
/Users/xxxxx/.anyenv/envs/pyenv/shims/python-config
/Users/xxxxx/.anyenv/envs/pyenv/shims/python3-config
/Users/xxxxx/.anyenv/envs/pyenv/shims/python3.6-config
上記のようなwarningが出た。
原因はbrewが参照するパスにpythonのconfigが複数あるせいとのことでbrewコマンドのaliasを作って余計なパスを見ないようにするのがスマートな解決策だと思う
.bashrcなどに下記を追加してターミナルの再起動かsource .bashrc
(.bash_profileで.bashrcを読み込む設定にしていない人は.bash_profileに直接書くか.bashrcを読むようにしよう)
alias brew="PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin brew"
anyenvインストール時にハマった話
anyenvをインストールしたのにrbenvがインストールできない。そんな減少に陥った話
確かに確認してみると下記のように出る。
$ anyenv install rbenv
anyenv-install: definition not found: rbenv
$ anyenv install --list
Available **envs:
*
unicornのworkerプロセスが再起動を繰り返す話
Rails5.2 + capistrano + unicorn + nginxでデプロイがうまくいくようになってもunicornを起動した後にunucornのエラーログがものすごい勢いで肥大化していった。
原因はunicornのworkerプロセスが起動したそばから死に、再生成を繰り返しているためだった。
この問題の場合、どこがクリティカルだったのかは結局分からなかったがとりあえず取った対策として
(nginxを終了してみても状況は変わらずだったのでnginx周りの調査は割愛する)