[ci/cd] 컨테이너가 실행중이지 않을경우 발생하던 CI/CD 에러 해결 #231
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
개요
컨테이너가 실행중이지 않을경우 발생하던 CI/CD 잠재적인 에러를 방지했습니다.
본문
docker ps는 실행중인 컨테이너만 반환하므로, 이전버전의 컨테이너가 실행중이지 않다면 걸러낼 수 없었습니다. 그 상태로 `%CONTAINER_NAME을 사용하여 같은 이름의 컨테이너를 docker run을 통해 만드려고 할 경우, 에러가 발생하게 됩니다. 따라서 -a 파라미터로 실행중이지 않은 컨테이너까지 검색하도록 하였습니다.
변경 - optional
dev-deploy의 경우 컨테이너가 존재한다면 [(중지 or 무시) -> 삭제]
prod-deploy의 경우 [실행중인 컨테이너 중지 -> 존재하는 컨테이너 삭제]
하도록 변경되었습니다.
피드백 - optional
prod-deploy도 dev-deploy처럼 짧게 만들수 있었는데,
docker stop $CONTAINER_NAME || true
가 발생하는 에러를 무시하기 때문에 문제가 생길수도 있다고 생각해서 if문 두개로 처리하도록 하였는데 코드가 좀 더러워 보여서 피드백 가능한 부분이 있다면 받고싶습니다.그런데 또 if문 없이 그냥 이렇게 하시는분들도 있긴하더라구요..
기타 - optional
백엔드 과제 하던중 실제로 겪어본 문제입니다.. ㅜㅜ