๐Ÿฅณ ์นด์šฐํ”„๋งŒ๋ด‡ v 2.0.0 ๐Ÿฅณ

18334 ๋‹จ์–ด kayfmanbottelegramreleasenestjs

์—ฐ๊ฒฐ



https://github.com/EndyKaufman/kaufman-bot - ๋ด‡์˜ ์†Œ์Šค ์ฝ”๋“œ

https://telegram.me/KaufmanBot - ์ „๋ณด์˜ ํ˜„์žฌ ๋ด‡

https://telegram.me/DevelopKaufmanBot - ํ…”๋ ˆ๊ทธ๋žจ์˜ ํ˜„์žฌ ๋ด‡(develop-branch)

github์—์„œ ์ƒˆ ํ™˜๊ฒฝ "prod" ๋งŒ๋“ค๊ธฐ



Dialogflow ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ







- ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— Dialogflow๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•

์„œ๋ฒ„ ํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ



ํ˜ธ์ŠคํŠธ ์ถ”๊ฐ€


SSH ํ‚ค ์ถ”๊ฐ€


- ssh ํ‚ค ์ƒ์„ฑ ๋ฐฉ๋ฒ•

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์˜ต์…˜ ์ƒ์„ฑ



๋ฃจํŠธ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ถ”๊ฐ€


์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด ์ถ”๊ฐ€


- ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ž‘์—… ์„ค์ • ๋ฐฉ๋ฒ•

ํ…”๋ ˆ๊ทธ๋žจ ํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ



ํ”„๋กœ๋•์…˜์šฉ ๋„๋ฉ”์ธ ์ถ”๊ฐ€


์›นํ›… ๊ฒฝ๋กœ ์ถ”๊ฐ€


๊ฐœ๋ฐœ ๋‹จ๊ณ„์—์„œ ํ˜ธ์ŠคํŠธ ๋ณ€๊ฒฝ


VPS์˜ dokku ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ํ…”๋ ˆ๊ทธ๋žจ ํ† ํฐ ์ œ๊ฑฐ

dokku config:unset kaufman-bot TELEGRAM_BOT_TOKEN --no-restart



github์˜ ๊ฐœ๋ฐœ ๋‹จ๊ณ„์— ํ…”๋ ˆ๊ทธ๋žจ ํ† ํฐ ์ถ”๊ฐ€


github์˜ prod ๋‹จ๊ณ„์— ํ…”๋ ˆ๊ทธ๋žจ ํ† ํฐ ์ถ”๊ฐ€


- ํ…”๋ ˆ๊ทธ๋žจ์—์„œ ์›นํ›… ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•

๋ด‡ ๊ด€๋ฆฌ์ž ID ์ถ”๊ฐ€


- ๊ด€๋ฆฌ์ž ID ์ถ”๊ฐ€ ๋ฐฉ๋ฒ•

๋‹ค๋ฅธ ์ด๋ฆ„ ๋ด‡์— ๋Œ€ํ•œ ํ™˜๊ฒฝ ์ถ”๊ฐ€



์ƒ์‚ฐ ์ค‘


ํ”„๋กœ๋•์…˜ ๋Ÿฌ์‹œ์•„์–ด


๊ฐœ๋ฐœ ์ค‘


๊ฐœ๋ฐœ ๋Ÿฌ์‹œ์•„์–ด

VPS์—์„œ ์ƒˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ



- dokku์—์„œ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ



dokku apps:create develop-kaufman-bot



root@vps17825:~# dokku apps:create develop-kaufman-bot
-----> Creating develop-kaufman-bot...


dokku ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋„๋ฉ”์ธ ์—ฐ๊ฒฐ



domains:add develop-kaufman-bot develop-kaufman-bot.site15.ru



root@vps17825:~# dokku domains:add develop-kaufman-bot develop-kaufman-bot.site15.ru
-----> Added develop-kaufman-bot.site15.ru to develop-kaufman-bot
 !     No web listeners specified for develop-kaufman-bot


๋งํฌ SSL ์ธ์ฆ์„œ์˜ ๊ฒฝ์šฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐฐํฌํ•ด์•ผ ํ•˜๋ฉฐ ์ƒˆ ๋ฒ„์ „์˜ ๊ฐœ๋ฐœ ๋‹จ๊ณ„๋ฅผ ๋ฐฐํฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.



๊ฐœ๋ฐœ CI ๊ตฌ์„ฑ ์—…๋ฐ์ดํŠธ



.github/workflows/develop.deploy.yml

name: 'deploy'

# yamllint disable-line rule:truthy
on:
  push:
    branches:
      - develop

jobs:
  migrate:
    runs-on: [self-hosted, develop-vps]
    environment: dev
    steps:
      - name: Cloning repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Apply migrations
        run: |
          curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
          . ~/.nvm/nvm.sh
          nvm --version
          nvm install v16.13.2
          nvm use v16.13.2
          npm i --force
          export POSTGRES_HOST=$(dokku postgres:info global-postgres --internal-ip)
          export ROOT_POSTGRES_URL=postgres://postgres:${{secrets.ROOT_POSTGRES_PASSWORD}}@${POSTGRES_HOST}:5432/postgres?schema=public
          export SERVER_POSTGRES_URL=${{secrets.SERVER_POSTGRES_URL}}
          npm run rucken -- postgres
          export DATABASE_URL=$SERVER_POSTGRES_URL && npm run migrate
          export DEPLOY_DATE=$(date +'%Y-%m-%d %H:%M:%S')
          export DEPLOY_COMMIT=$GITHUB_SHA
          export DEPLOY_VERSION=$(node -pe "require('./package.json')['version']")
          dokku config:set --no-restart develop-kaufman-bot SERVER_POSTGRES_URL=$SERVER_POSTGRES_URL
          dokku config:set --no-restart --global POSTGRES_HOST=global-postgres
          dokku config:set --no-restart develop-kaufman-bot GOOGLE_APPLICATION_CREDENTIALS=google-credentials.json
          dokku config:set --no-restart develop-kaufman-bot GOOGLE_CREDENTIALS=${{secrets.GOOGLE_CREDENTIALS}}
          dokku config:set --no-restart develop-kaufman-bot DIALOGFLOW_PROJECT_ID=${{secrets.DIALOGFLOW_PROJECT_ID}}
          dokku config:set --no-restart develop-kaufman-bot TELEGRAM_BOT_WEB_HOOKS_DOMAIN=${{secrets.TELEGRAM_BOT_WEB_HOOKS_DOMAIN}}
          dokku config:set --no-restart develop-kaufman-bot TELEGRAM_BOT_WEB_HOOKS_PATH=${{secrets.TELEGRAM_BOT_WEB_HOOKS_PATH}}
          dokku config:set --no-restart develop-kaufman-bot TELEGRAM_BOT_ADMINS=${{secrets.TELEGRAM_BOT_ADMINS}}
          dokku config:set --no-restart develop-kaufman-bot TELEGRAM_BOT_TOKEN=${{secrets.TELEGRAM_BOT_TOKEN}}
          dokku config:set --no-restart develop-kaufman-bot DEPLOY_DATE="$DEPLOY_DATE"
          dokku config:set --no-restart develop-kaufman-bot DEPLOY_COMMIT=$DEPLOY_COMMIT
          dokku config:set --no-restart develop-kaufman-bot DEPLOY_VERSION=$DEPLOY_VERSION
          dokku config:set --no-restart develop-kaufman-bot BOT_NAMES=${{secrets.BOT_NAMES}}
          dokku config:set --no-restart develop-kaufman-bot BOT_NAMES_RU=${{secrets.BOT_NAMES_RU}}

  deploy:
    needs: [migrate]
    runs-on: ubuntu-latest
    environment: dev
    steps:
      - name: Cloning repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Push to dokku
        uses: dokku/github-action@master
        with:
          branch: 'develop'
          git_remote_url: 'ssh://dokku@${{secrets.HOST}}:22/develop-kaufman-bot'
          ssh_private_key: ${{secrets.SSH_PRIVATE_KEY}}



ํ”„๋กœ๋•์…˜ ๋ฐฐํฌ ๊ตฌ์„ฑ ๋งŒ๋“ค๊ธฐ



.github/workflows/master.deploy.yml

name: 'deploy'

# yamllint disable-line rule:truthy
on:
  push:
    branches:
      - master

jobs:
  migrate:
    runs-on: [self-hosted, develop-vps]
    environment: prod
    steps:
      - name: Cloning repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Apply migrations
        run: |
          curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
          . ~/.nvm/nvm.sh
          nvm --version
          nvm install v16.13.2
          nvm use v16.13.2
          npm i --force
          export POSTGRES_HOST=$(dokku postgres:info global-postgres --internal-ip)
          export ROOT_POSTGRES_URL=postgres://postgres:${{secrets.ROOT_POSTGRES_PASSWORD}}@${POSTGRES_HOST}:5432/postgres?schema=public
          export SERVER_POSTGRES_URL=${{secrets.SERVER_POSTGRES_URL}}
          npm run rucken -- postgres
          export DATABASE_URL=$SERVER_POSTGRES_URL && npm run migrate
          export DEPLOY_DATE=$(date +'%Y-%m-%d %H:%M:%S')
          export DEPLOY_COMMIT=$GITHUB_SHA
          export DEPLOY_VERSION=$(node -pe "require('./package.json')['version']")
          dokku config:set --no-restart kaufman-bot SERVER_POSTGRES_URL=$SERVER_POSTGRES_URL
          dokku config:set --no-restart --global POSTGRES_HOST=global-postgres
          dokku config:set --no-restart kaufman-bot GOOGLE_APPLICATION_CREDENTIALS=google-credentials.json
          dokku config:set --no-restart kaufman-bot GOOGLE_CREDENTIALS=${{secrets.GOOGLE_CREDENTIALS}}
          dokku config:set --no-restart kaufman-bot DIALOGFLOW_PROJECT_ID=${{secrets.DIALOGFLOW_PROJECT_ID}}
          dokku config:set --no-restart kaufman-bot TELEGRAM_BOT_WEB_HOOKS_DOMAIN=${{secrets.TELEGRAM_BOT_WEB_HOOKS_DOMAIN}}
          dokku config:set --no-restart kaufman-bot TELEGRAM_BOT_WEB_HOOKS_PATH=${{secrets.TELEGRAM_BOT_WEB_HOOKS_PATH}}
          dokku config:set --no-restart kaufman-bot TELEGRAM_BOT_ADMINS=${{secrets.TELEGRAM_BOT_ADMINS}}
          dokku config:set --no-restart kaufman-bot TELEGRAM_BOT_TOKEN=${{secrets.TELEGRAM_BOT_TOKEN}}
          dokku config:set --no-restart kaufman-bot DEPLOY_DATE="$DEPLOY_DATE"
          dokku config:set --no-restart kaufman-bot DEPLOY_COMMIT=$DEPLOY_COMMIT
          dokku config:set --no-restart kaufman-bot DEPLOY_VERSION=$DEPLOY_VERSION
          dokku config:set --no-restart kaufman-bot BOT_NAMES=${{secrets.BOT_NAMES}}
          dokku config:set --no-restart kaufman-bot BOT_NAMES_RU=${{secrets.BOT_NAMES_RU}}

  deploy:
    needs: [migrate]
    runs-on: ubuntu-latest
    environment: prod
    steps:
      - name: Cloning repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Push to dokku
        uses: dokku/github-action@master
        with:
          branch: 'master'
          git_remote_url: 'ssh://dokku@${{secrets.HOST}}:22/kaufman-bot'
          ssh_private_key: ${{secrets.SSH_PRIVATE_KEY}}



ํ˜„์žฌ ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์ปค๋ฐ‹





git push



๊ธฐ๋Šฅ/73 ๋ถ„๊ธฐ๋ฅผ ๋ณ‘ํ•ฉํ•˜์—ฌ ๊ฐœ๋ฐœ



git checkout develop
git merge feature/73
git push



ํ”„๋กœ๋•์…˜ ๋ฐฐํฌ



๋ฆด๋ฆฌ์Šค ๋งŒ๋“ค๊ธฐ



npm run app:create-release



๋ฆด๋ฆฌ์Šค๋ฅผ ๋งˆ์Šคํ„ฐ์— ๋ณ‘ํ•ฉ



git checkout merge
git merge develop
git push



ํ…”๋ ˆ๊ทธ๋žจ์—์„œ ์ƒ์‚ฐ ๋ด‡ ํ™•์ธ





๋‹ค์Œ ํฌ์ŠคํŠธ์—์„œ๋Š” ๋ชจ๋“  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ npm ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์— ๊ฒŒ์‹œํ•˜๊ณ  ์ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ˜ํ”Œ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค...

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ