以下を参照する
https://github.com/kakudou3/private-projects
sudo apt-get update
sudo apt-get install postgresql
dpkg -l | grep postgresql
systemctl status postgresql.service
sudo -u postgres psql -c "SELECT version();"
sudo -u postgres psql
loginとcreatedbの権限を追加するcreate user budgiii with password 'password'
alter role budgiii with login;
alter role budgiii with CREATEDB;
\du
デフォルトの DB(postgres)にログインする
postgresDBにログインして、ユーザーが正しく作成されているかを確認する。
psql -U budgiii postgres
緩いが、設定した時の例を貼っておく。
sudo vi /etc/postgresql/16/main/postgresql.conf
listen_addresses = "*"
sudo vi /etc/postgresql/16/main/pg_hba.conf
passwordにする# "local" is for Unix domain socket connections only
local all all password
host all all 0.0.0.0/0 scram-sha-256
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all password
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# 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 scram-sha-256
DB サーバーを再起動する
sudo service postgresql restart
https://zenn.dev/hdmt/articles/8b242a8c78f7f1
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl status docker
sudo systemctl start docker
https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
credentialsファイルの作成(ローカル)
EDITOR="vi" bin/rails credentials:edit
vpsにログイン
ip -4 addr show scope global | awk '/inet/ {print $2}' | cut -d/ -f1 | grep -E '^(10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)' | head -n1
DB_HOST をホストマシンの Private IP に設定する
/config/deploy.yml に以下を追記する
env:
clear:
DB_HOST: ホストマシンのPrivate IP
ローカルからデプロイ対象の環境にmigrationを実行したい場合
kamal app exec --primary -i './bin/rails db:create'
kamal app exec --primary -i './bin/rails db:migrate'
https://www.reddit.com/r/rails/comments/1dle5xj/kamal_and_database_migrations/
デプロイ
git commit -m "変更内容をコミットしておく"
kamal deploy
ログの確認
kamal logs