Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL 컨테이너 시작 후 api 서버가 시작되도록 설정 #409

Merged
merged 5 commits into from
Oct 10, 2023

Conversation

withSang
Copy link
Member

@withSang withSang commented Oct 6, 2023

요약 *

It fixes #407, resolves #408

  1. MySQL 컨테이너가 시작된 이후 실제로 tcp 연결을 받기 시작할 때까지 수 초의 시간이 소요되는데, 그 사이에 api 서버의 Prisma ORM이 데이터베이스와 연결을 시도하면 연결 실패 오류가 발생합니다. 이를 개선하기 위해 두 가지 해결 방법을 도입하였습니다.

    1. 배포용 docker compose 파일에서 depends_on 조건 강화하기: Docker compose의 api 서버 명세에 "condition: service_completed_successfully" 조건을 추가하여, MySQL 컨테이너가 연결을 수락하기 시작한 시점에 api 서버가 시작될 수 있게 개선합니다.
      • 제가 문서를 잘못 읽었군요ㅠㅠ "condition: service_healthy"로 대체하였습니다.
    2. 개발용 docker compose 파일에서 docker compose up--wait 옵션 추가하기: MySQL 컨테이너가 연결을 수락하기 시작한 시점까지 docker compose up 명령어가 종료되지 않도록 개선합니다.
  2. PR 템플릿을 추가하고, 커밋 메시지 길이 제한을 60자로 늘립니다.

스크린샷

화면 기록 2023-10-09 오전 2 59 24
db 컨테이너의 상태가 healthy가 되어야 해당 컨테이너에 의존하는 컨테이너(api, web)이 시작됩니다.
히히 페라리 예쁘죠

이후 Task *

  • 없음

@withSang withSang linked an issue Oct 6, 2023 that may be closed by this pull request
2 tasks
@netlify
Copy link

netlify bot commented Oct 6, 2023

Deploy Preview for biseo-preview ready!

Name Link
🔨 Latest commit 8865618
🔍 Latest deploy log https://app.netlify.com/sites/biseo-preview/deploys/6522ec55c8a49000089a538f
😎 Deploy Preview https://deploy-preview-409--biseo-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@withSang withSang self-assigned this Oct 6, 2023
@withSang withSang requested a review from SnowSuno October 8, 2023 15:23
@withSang withSang marked this pull request as ready for review October 8, 2023 15:23
@withSang withSang requested a review from minjoo0729 October 8, 2023 15:24
"prod": "prisma migrate deploy && node dist/index.js",
"db": "docker compose -f docker-compose.dev.yml",
"typecheck": "prisma generate && tsc --noEmit",
"typegen": "prisma generate",
"migrate": "pnpm db up -d && prisma migrate dev",
"studio": "pnpm db up -d && prisma studio",
"migrate:dev": "pnpm db up --wait && prisma migrate dev",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--wait 옵션을 설정해 MySQL 컨테이너의 healthcheck 조건이 만족될 때까지 다음 커맨드의 실행을 지연시킵니다.
https://docs.docker.com/engine/reference/commandline/compose_up/

docker-compose.yml Outdated Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SnowSuno

This comment was marked as duplicate.

SnowSuno
SnowSuno previously approved these changes Oct 8, 2023
Copy link
Member

@SnowSuno SnowSuno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@withSang withSang marked this pull request as draft October 8, 2023 17:51
@withSang withSang marked this pull request as ready for review October 8, 2023 17:53
Copy link
Member

@SnowSuno SnowSuno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Comment on lines +48 to +52
healthcheck:
test: "mysql -uroot -p$$MYSQL_ROOT_PASSWORD $$MYSQL_DATABASE -e 'select 1'"
start_period: 0s
interval: 1s
retries: 3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이로써 디스크 용량 부족 등으로 DB가 죽게 된다면 그 시점도 기록할 수 있습니당

@withSang withSang merged commit 18e7a68 into main Oct 10, 2023
@withSang withSang deleted the feat/api-depends-on-mysql branch October 10, 2023 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants