Skip to content

Merge pull request #54 from miminashi/53-specify-postgres-version #20

Merge pull request #54 from miminashi/53-specify-postgres-version

Merge pull request #54 from miminashi/53-specify-postgres-version #20

name: Deploy demo site
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create ssh config
env:
SSH_USER: ${{ secrets.DEMO_SITE_SSH_USER }}
SSH_HOSTNAME: ${{ secrets.DEMO_SITE_SSH_HOSTNAME }}
SSH_PRIVATE_KEY: ${{ secrets.DEMO_SITE_SSH_PRIVATE_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.DEMO_SITE_SSH_KNOWN_HOSTS }}
run: |
mkdir ~/.ssh
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
echo "${SSH_KNOWN_HOSTS}" > ~/.ssh/known_hosts && chmod 600 ~/.ssh/known_hosts
cat > ~/.ssh/config <<EOF
Host production
HostName ${SSH_HOSTNAME}
User ${SSH_USER}
EOF
- name: Create docker context
run: |
docker context create --docker host=ssh://production production
docker context use production
- name: Deploy to host
env:
COMPOSE_PROJECT_NAME: ytdlor_demo_site
SECRET_KEY_BASE: ${{ secrets.DEMO_SITE_SECRET_KEY_BASE }}
YTDLOR_WEB_PORT: 8001
run: |
docker compose -f docker-compose.yml -f docker-compose-production.yml -f docker-compose-demo-site.yml build
#docker compose -f docker-compose.yml -f docker-compose-production.yml -f docker-compose-demo-site.yml down
# ssh経由のcontextで docker compose down がうまく動かない問題のワークアラウンド
ssh production -- docker compose -p "${COMPOSE_PROJECT_NAME}" down
docker compose -f docker-compose.yml -f docker-compose-production.yml -f docker-compose-demo-site.yml run --rm web rails db:migrate
docker compose -f docker-compose.yml -f docker-compose-production.yml -f docker-compose-demo-site.yml up -d --remove-orphans