[英]How to run a Prisma migration with Mysql on Docker with Github-actions
我的應用程序使用 Docker 運行 MySQL DB,並使用 Prisma 連接到它。 我正在編寫一個 gh-action,它會在每次推送后測試應用程序。 我已經按照這里的指南了解如何在 gh-actions 上運行 docker。 我也在用act測試這個動作。
我的.github/workflows/main.yml看起來像這樣:
name: NestJS CI/CD
on:
push:
branches:
- feature/gh-actions
jobs:
runner-job:
runs-on: ubuntu-latest
container: node:latest
services:
mysql:
image: mysql
ports:
- '3306:3306'
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: db
options: >-
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Install dependencies
run: npm ci
- name: Apply migrations
run: npx prisma migrate dev
env:
DATABASE_URL: mysql://root:password@mysql:3306/db
- name: Apply seed
run: npx prisma db seed
- name: Test the project
run: npm run test
但我不斷得到:
| Error: P1001: Can't reach database server at `mysql`:`3306`
我錯過了什么嗎?
我可能是錯的,但我認為你應該
DATABASE_URL: mysql://root:password@localhost:3306/db
?
對於任何堅持同一件事的人。 為了讓行為識別連接,您應該使用localhost
而不是mysql
。 同時,當您在 github 上實際使用它時,這將不起作用,您必須在這種情況下使用mysql
。 真的很令人沮喪,因為您必須更改某些內容才能在本地對其進行測試,這在開發過程中毫無意義。 也許我錯過了表演中的一些東西
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.