update:Readme #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Production | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 3.2.3 # 使用するRubyのバージョンを指定 | |
bundler-cache: true # Bundlerのキャッシュを有効に | |
- name: Install dependencies | |
run: | | |
gem install bundler | |
bundle install | |
- name: Set environment variables | |
env: | |
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} | |
BOOK_LOG_LIST_DATABASE_USER: ${{ secrets.BOOK_LOG_LIST_DATABASE_USER }} | |
BOOK_LOG_LIST_DATABASE_PASSWORD: ${{ secrets.BOOK_LOG_LIST_DATABASE_PASSWORD }} | |
DATABASE_HOST: ${{ secrets.DATABASE_HOST }} | |
run: | | |
echo "SECRET_KEY_BASE set" | |
echo "BOOK_LOG_LIST_DATABASE_USER set" | |
echo "BOOK_LOG_LIST_DATABASE_PASSWORD set" | |
echo "DATABASE_HOST set" | |
- name: Run migrations | |
env: | |
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} | |
BOOK_LOG_LIST_DATABASE_USER: ${{ secrets.BOOK_LOG_LIST_DATABASE_USER }} | |
BOOK_LOG_LIST_DATABASE_PASSWORD: ${{ secrets.BOOK_LOG_LIST_DATABASE_PASSWORD }} | |
DATABASE_HOST: ${{ secrets.DATABASE_HOST }} | |
run: | | |
bundle exec rails db:migrate RAILS_ENV=production | |
- name: Deploy to Server | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
USER: ${{ secrets.SSH_USER }} | |
HOST: ${{ secrets.SSH_HOST }} | |
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} | |
run: | | |
echo "$SSH_PRIVATE_KEY" > private_key.pem | |
chmod 600 private_key.pem | |
ssh -o StrictHostKeyChecking=no -i private_key.pem $USER@$HOST "cd /home/ubuntu/www/book_log_list && git pull origin main && bundle install && RAILS_ENV=production bundle exec rake db:migrate && puma -C config/puma.rb -e production" |