Kintone Rails 7 開発環境構築 (コミクり) === * [name=@masarinn], [name=@fuchikami] &nbsp; 目次 [toc] :::success @masarinn 20240202 更新する。 TODO 1. Oracle Linux インストールやり方, 写真 2. ロカールのVagrantのやり方 ::: &nbsp; 必要なこと --- 1. Ruby 3.2 2. Postgresql 16 3. Git 4. Ruby on Rails 7.2 5. Docker &nbsp; インストール手順 --- ### Ruby インストール 1. RubyのVersion管理はRVMを使用してますから、先にRVMをダウンロードする。 gpg2 を追加する。 ``` gpg2 --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB ``` &nbsp; 2. RVMをダウンロード、インストールする。 ``` \curl -sSL https://get.rvm.io | bash -s stable ``` &nbsp; 3. 環境をバンドルする。 ``` source /home/vagrant/.rvm/scripts/rvm 本番 source /home/comcre/.rvm/scripts/rvm ``` &nbsp; 4. RVMを使って、好きなRuby Versionを選ぶ。(3.2) * RVMを更新する。 ``` rvm get master ``` * RVMの中に、Rubyを確定する。 ``` rvm list known ``` * ダウンロードする前に,libyamlファイルのロケーションを追加する。 ``` 前提条件 Oracleシステムは元々libyamlファイルはないですから、 別側に追加しないといけないです。 libyaml はRubyにインストールする前の前提パケット。 sudo dnf config-manager --set-enabled ol9_codeready_builder ``` * Ruby 3.2 をダウンロードする。 ``` rvm install 3.2 rvm install "ruby-3.2.2" rvm list (rvm use ruby_version) rvm use ruby-3.2.2 rvm --default use ruby-3.2.2 ruby -v ``` ``` dtrace problem sudo chmod -s /usr/sbin/dtrace sudo chmod +s /usr/sbin/dtrace rbenv での例 RUBY_CONFIGURE_OPTS="--disable-dtrace" rbenv install 2.4.3 rvm での例 rvm install --disable-dtrace ruby-2.4.3 我是用 rvm install "ruby-3.2.2" --disable-dtrace ``` &nbsp; ### PostgreSql 16 インストール 1. リポジトリを追加する。 ``` sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y ``` &nbsp; 2. Postgresql16をインストールする。 ``` sudo dnf install postgresql16-server -y ``` &nbsp; 3. データベースを初期化する。 ``` sudo /usr/pgsql-16/bin/postgresql-16-setup initdb ``` &nbsp; 4. Postgresql を起動する。 ``` sudo systemctl start postgresql-16 ``` &nbsp; 5. 毎回サーバーを起動する時、自動に起動するため、設定する。 ``` sudo systemctl enable postgresql-16 ``` &nbsp; 6. PostgreSql をテストする。 ``` sudo systemctl status postgresql-16 psql -V ``` [参考リンク](https://www.linuxtechi.com/how-to-install-postgresql-on-rhel/) &nbsp; 7. 他の人を接続するため、2つファイルを修正する。 * ファイルはここに--> /var/lib/pgsql/16/data * /var/lib/pgsql/16/data/postgresql.conf * listen_addresses = '*' <--設定する。 sudo vi /var/lib/pgsql/16/data/postgresql.conf ``` # - Connection Settings - listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) #port = 5432 # (change requires restart) max_connections = 100 # (change requires restart) #reserved_connections = 0 # (change requires restart) #superuser_reserved_connections = 3 # (change requires restart) #unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories # (change requires restart) ``` sudo vi /var/lib/pgsql/16/data/pg_hba.conf * /var/lib/pgsql/16/data/pg_hba.conf * host all all 127.0.0.1/32 trust * host all all 0.0.0.0/0 trust ``` # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 scram-sha-256 # Allow replication connections from localhost, by a user with the # replication privilege. local replication all peer host replication all 127.0.0.1/32 scram-sha-256 host replication all ::1/128 scram-sha-256 host all all 0.0.0.0/0 trust ``` &nbsp; 8. Postgresql リスタート ``` sudo systemctl restart postgresql-16 psql -U postgres -h 127.0.0.1 ``` &nbsp; 9. ファイヤーウォールを設定する。(ポート 5432, 3000) * ファイヤ ォールの状況を確定する。 ``` sudo firewall-cmd --state sudo systemctl start firewalld sudo systemctl status firewalld ``` * ファイヤーウォールを3000, 5432ポートを開放する。 ``` sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent sudo firewall-cmd --zone=public --add-port=3000/tcp --permanent ``` * ファイヤーウォールをリロードする。 ``` sudo firewall-cmd --reload sudo firewall-cmd --list-ports ``` &nbsp; 10. Postgresql-devel(開発パケット)をインストール。 * Postgresql-develをダウンロードする。 ``` wget https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-9-x86_64/postgresql16-devel-16.1-2PGDG.rhel9.x86_64.rpm ``` * Postgresql-develをインストール ``` sudo dnf install postgresql16-devel-16.1-2PGDG.rhel9.x86_64.rpm ``` &nbsp; ### Git インストール 1. 先に確認してます。もし既にある場合、無視する。 ``` git -v ``` &nbsp; 2. dnf を更新する。 ``` sudo dnf update ``` &nbsp; 3. Git インストール ``` sudo dnf install git ``` &nbsp; ### Ruby on rails インストール 1. 先ず、rootから新しいフォルダーに作成する。 ``` cd / mkdir new_folder ``` &nbsp; 2. フォルダーに入れて、サーバー側のデータを全部コーロンする。 * git cloneする前に、アクセストークンが必要するので、リンクから確認をお願い致します。 [GitLab Access Token](https://gitlab.office-service.comcre.co.jp/-/profile/personal_access_tokens) git clone http://@gitlab.office-service.comcre.co.jp/kintone-group/canox/canox-rails.git ``` cd new_folder git clone http://{username}:{token}@{URL} 目前在用的 不知道要不要加s git clone https://my_username:my_token@gitlab.office-service.comcre.co.jp/kintone-group/canox/canox-rails.git git clone https://oauth2:my_token@gitlab.office-service.comcre.co.jp/kintone-group/canox/canox-rails.git ``` &nbsp; 3. gem をインストールする。 * 先にpg gemをインストールする。 ``` gem install pg -v 1.5.4 -- --with-pg-config=/usr/pgsql-16/bin/pg_config ``` * 次に全体gemをインストールする。 ``` bundle install ``` 4. プロジェクトをテストする。 ``` bundle exec pumactl start ``` &nbsp; ### Docker インストール :::info 作成中。 ::: [Dockerインストール](https://techviewleo.com/install-use-docker-ce-on-oracle-linux/) &nbsp; エラーの解決 --- :::info 確認中。 ::: ![image](https://hackmd.io/_uploads/r1AL2k72a.png) ``` git config --global --add safe.directory /canox-rails/canox-rails ``` Canox-Rrails building --- #### Ruby usefull command Create migration ``` rails generate migration <Name> ``` ![image](https://hackmd.io/_uploads/S1rLp2Yi6.png) Create controller ``` rails generate controller <name> ``` ![image](https://hackmd.io/_uploads/SywPOMiip.png) Create controller with views ``` rails g controller <name> <argument> e.g. rails g controller <name> index ``` ![image](https://hackmd.io/_uploads/HJkPdfjia.png) ![image](https://hackmd.io/_uploads/ryieT1Qnp.png) ![image](https://hackmd.io/_uploads/H1IfTJQ26.png) ![image](https://hackmd.io/_uploads/rkuXpJmh6.png) session ![image](https://hackmd.io/_uploads/r1mSOxJ6T.png) devices ![image](https://hackmd.io/_uploads/SyJ8OxyTT.png) ![image](https://hackmd.io/_uploads/r1AUue1a6.png) ![image](https://hackmd.io/_uploads/SyfDugkpp.png) ![image](https://hackmd.io/_uploads/B1JOdxy66.png) ![image](https://hackmd.io/_uploads/rytOOekp6.png) ![image](https://hackmd.io/_uploads/SkGQFg1aT.png) db:migrate ![image](https://hackmd.io/_uploads/rk2lqxkpa.png) INSERT INTO m_accounts (rec_id, account_id, account_pw, account_name_kana, account_name_disp, authority_kbn, language, comp_cd, email, encrypted_password, reset_password_token, reset_password_sent_at, remember_created_at, created_at, updated_at) VALUES (1, 'test1', 'test1', 'test_kana', 'Test Account', '1', '0', '123', 'test@example.com', 'encrypted_password', NULL, NULL, NULL, current_timestamp, current_timestamp); INSERT INTO users (rec_id, account_id, encrypted_password, account_name_kana, account_name_disp, authority_kbn, language, comp_cd, last_disp, created_at, updated_at) VALUES (1, 'test1', '', '', '', 1, 0, 1234, '', now(), now());