dokku infra에 데이터베이스 생성 및 github runner에서 flyway 마이그레이션 실행 설정
16971 단어 kaufmanbotmigrationsgithubpostgres
연결
https://github.com/EndyKaufman/kaufman-bot - 봇의 소스 코드
https://telegram.me/DevelopKaufmanBot - 텔레그램의 현재 봇
https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners - github 러너를 위한 지침
vps에 자체 호스트 러너 추가
https://github.com/YOU_NAME/YOU_REPOSITORY_NAME/settings/actions/runners/new?arch=x64&os=linux으로 이동하여 설치 단계에 대해 읽어보십시오.
mkdir actions-runner && cd actions-runner
curl -o actions-runner-linux-x64-2.288.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.288.1/actions-runner-linux-x64-2.288.1.tar.gz
echo "CUSTOM_NUMBERS actions-runner-linux-x64-2.288.1.tar.gz" | shasum -a 256 -c
tar xzf ./actions-runner-linux-x64-2.288.1.tar.gz
export RUNNER_ALLOW_RUNASROOT=true && ./config.sh --url https://github.com/EndyKaufman/kaufman-bot --token TOKEN_FOR_RUNNER
결과
root@vps17825:~/actions-runner# ./config.sh --url https://github.com/EndyKaufman/kaufman-bot --token TOKEN_FOR_RUNNER
--------------------------------------------------------------------------------
| ____ _ _ _ _ _ _ _ _ |
| / ___(_) |_| | | |_ _| |__ / \ ___| |_(_) ___ _ __ ___ |
| | | _| | __| |_| | | | | '_ \ / _ \ / __| __| |/ _ \| '_ \/ __| |
| | |_| | | |_| _ | |_| | |_) | / ___ \ (__| |_| | (_) | | | \__ \ |
| \____|_|\__|_| |_|\__,_|_.__/ /_/ \_\___|\__|_|\___/|_| |_|___/ |
| |
| Self-hosted runner registration |
| |
--------------------------------------------------------------------------------
# Authentication
√ Connected to GitHub
# Runner Registration
Enter the name of the runner group to add this runner to: [press Enter for Default]
Enter the name of runner: [press Enter for vps17825] develop-vps
This runner will have the following labels: 'self-hosted', 'Linux', 'X64'
Enter any additional labels (ex. label-1,label-2): [press Enter to skip] develop-vps
√ Runner successfully added
√ Runner connection is good
# Runner settings
Enter name of work folder: [press Enter for _work]
√ Settings Saved.
root@vps17825:~/actions-runner#
자체 호스팅 러너 애플리케이션을 서비스로 구성
sudo ./svc.sh install
sudo ./svc.sh start
결과
root@vps17825:~/actions-runner# sudo ./svc.sh install
Creating launch runner in /etc/systemd/system/actions.runner.EndyKaufman-kaufman-bot.develop-vps.service
Run as user: root
Run as uid: 0
gid: 0
Created symlink /etc/systemd/system/multi-user.target.wants/actions.runner.EndyKaufman-kaufman-bot.develop-vps.service → /etc/systemd/system/actions.runner.EndyKaufman-kaufman-bot.develop-vps.service.
root@vps17825:~/actions-runner# sudo ./svc.sh start
/etc/systemd/system/actions.runner.EndyKaufman-kaufman-bot.develop-vps.service
● actions.runner.EndyKaufman-kaufman-bot.develop-vps.service - GitHub Actions Runner (EndyKaufman-kaufman-bot.develop-vps)
Loaded: loaded (/etc/systemd/system/actions.runner.EndyKaufman-kaufman-bot.develop-vps.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-03-26 12:06:28 MSK; 21ms ago
Main PID: 2266387 (runsvc.sh)
Tasks: 2 (limit: 2253)
Memory: 784.0K
CGroup: /system.slice/actions.runner.EndyKaufman-kaufman-bot.develop-vps.service
├─2266387 /bin/bash /root/actions-runner/runsvc.sh
└─2266397 ./externals/node16/bin/node ./bin/RunnerService.js
Mar 26 12:06:28 vps17825 systemd[1]: Started GitHub Actions Runner (EndyKaufman-kaufman-bot.develop-vps).
Mar 26 12:06:28 vps17825 runsvc.sh[2266387]: .path=/root/.vscode-server/bin/c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/s…ames:/snap/bin
Hint: Some lines were ellipsized, use -l to show in full.
Github UI에서 생성된 러너 보기
vps 데이터베이스에 지원 적용 마이그레이션 추가
github에 새 env 값 추가
데이터베이스 루트 사용자의 비밀번호 추가
ROOT_POSTGRES_PASSWORD=postgres
필요한 모든 애플리케이션에 대한 연결 문자열 추가
SERVER_POSTGRES_URL=postgres://admin_develop:password_develop@${POSTGRES_HOST}:5432/kaufman_bot_develop?schema=public
배포 스크립트 업데이트
.github/workflows/develop.deploy.yml
name: "deploy"
# yamllint disable-line rule:truthy
on:
push:
branches:
- feature/73
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
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: "feature/73"
git_remote_url: "ssh://dokku@${{secrets.HOST}}:22/kaufman-bot"
ssh_private_key: ${{secrets.SSH_PRIVATE_KEY}}
호스트 이름 변경 지원을 위한 이동 경로 구성 업데이트
.flyway.js
...
const cs = new ConnectionString(
(process.env.POSTGRES_URL || process.env.DATABASE_URL).replace(
'${POSTGRES_HOST}',
process.env['POSTGRES_HOST']
)
);
...
Github UI에서 배포 확인
마이그레이션을 적용하고 배포하면 Github UI에 결과가 표시됩니다.
https://github.com/EndyKaufman/kaufman-bot/actions/runs/2044314338
마이그레이션 완료를 보려면 필요한 작업 단계를 확장하세요.
https://github.com/EndyKaufman/kaufman-bot/runs/5702849615?check_suite_focus=true
vps 서버에서 데이터베이스 확인
데이터베이스에 연결
데이터베이스 전환
\connect kaufman_bot_develop
텔레그램 사용자 선택
select * from "User";
root@vps17825:~# dokku postgres:connect global-postgres
psql (13.3 (Debian 13.3-1.pgdg100+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
global_postgres=# \connect kaufman_bot_develop
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
You are now connected to database "kaufman_bot_develop" as user "postgres".
kaufman_bot_develop=# select * from "User";
id | telegramId | langCode
--------------------------------------+------------+----------
7fa21a25-60a9-4d69-86d9-13770bd467fd | testId | en
(1 row)
다음 포스팅에서는 프로젝트에 prisma를 추가하여 사용자의 언어를 데이터베이스에 저장하도록 하겠습니다...
Reference
이 문제에 관하여(dokku infra에 데이터베이스 생성 및 github runner에서 flyway 마이그레이션 실행 설정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/endykaufman/create-a-database-in-dokku-infra-and-set-up-run-flyway-migration-from-github-runner-3p06텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)