Ruby on Rails6

Chapter2
環境構築

- 「環境」とはOSの種類やバージョン、あるいはOS上で動くソフトウェアやライブラリのこと
- 開発と本番で環境が異なることで動かなくなる問題が発生する
- Rails自体はWindowsでもMac、Linuxでも動作する
- しかしRails拡張のためのGemなどは必ずしもそうではない
- 仮想環境を使用することで解決させる
- デスクトップOS上のWebブラウザからRailsにアクセスし動作確認
- railsのソースコードはデスクトップOS上で開いて編集できる
- デスクトップOS上のWebブラウザからRailsにアクセスし動作確認

/bin/sh
WEBPACKER_DEV_SERVER_HOST
RAILS_SERVE_STATIC_FILES
左がホストで右がゲスト
ARG UID=1000
ARG GID=1000

rails new
実行
error http-proxy-middleware@2.0.6: The engine "node" is incompatible with this module. Expected version ">=12.0.0". Got "10.14.2"
error Found incompatible module
まあ出ると思った
issue
対応
node.jsのバージョンを上げる
$ sudo apk upgrade nodejs

========================================
Your Yarn packages are out of date!
Please run `yarn install --check-files` to update.
========================================
文字通りyarn packageが古くなってるからアップデートしろと
対応
bash-4.4$ yarn install --check-files
yarn install v1.12.3
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.45s.
bash-4.4$ yarn install
yarn install v1.12.3
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.36s.
bash-4.4$

https://qiita.com/__fff/items/2df7fb111954fd0db4ed

多分webコンテナでなんか起こってる
% docker-compose up
[+] Building 0.0s (0/0) docker:desktop-linux
[+] Running 4/0
✔ Network rails6-compose_default Created 0.0s
✔ Container rails6-compose-db-1 Created 0.0s
✔ Container rails6-compose-web-1 Created 0.0s
! web The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested 0.0s
Attaching to rails6-compose-db-1, rails6-compose-web-1
M1起因の問題っぽい(警告だから多分対応しなくてもよしなにやってくれるだろうけど)
対応
web:
build: .
command: /bin/sh
environment:
WEBPACKER_DEV_SERVER_HOST: "0.0.0.0"
RAILS_SERVE_STATIC_FILES: "1"
EDITOR: "vim"
platform: linux/amd64
platform: linux/amd64
でlinux環境下と同様にした

あとdbコンテナも正しく起動していないっぽいと思ったけど、これは正常に起動し、PostgreSQLがクライアントからの接続を待っている状態らしい(MySQLしかいじったことないから知らんかった)
rails6-compose-db-1 | 2023-10-09 04:48:28.912 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
rails6-compose-db-1 | 2023-10-09 04:48:28.912 UTC [1] LOG: listening on IPv6 address "::", port 5432
rails6-compose-db-1 | 2023-10-09 04:48:28.920 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
rails6-compose-db-1 | 2023-10-09 04:48:28.950 UTC [19] LOG: database system was shut down at 2023-10-09 04:48:21 UTC
rails6-compose-db-1 | 2023-10-09 04:48:28.968 UTC [1] LOG: database system is ready to accept connections

yarnのバージョンが古いのでエラーが出てrails newがコケる
warning Integrity check: Top level patterns don't match
error Integrity check failed
error Found 1 errors.
========================================
Your Yarn packages are out of date!
Please run `yarn install --check-files` to update.
========================================
To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).
yarn check v1.12.3
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.
yarn install
しても解決しない
あんま釈然としないが、無視することにしてみる
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: false

apt パッケージマネージャを使って最新版の Node.js をインストールしようとすると、v10.19.0 になってしまいます。これは Ubuntu App Store にある最新版ですが、Node.js の最新版ではありません。
これは、あるソフトウェアの新バージョンがリリースされた場合、Ubuntu チームがテストして、公式の Ubuntu App Store でリリースするまで数ヶ月かかることがあるためです。その結果、どんなソフトウェアでも最新版を入手するためには、開発者が公開しているプライベートパッケージを使用しなければならない場合があります。