appleboy 사용 시 남을 수 있는 Drone SSH 임시 환경변수 삭제#52
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR 타입
구현한 기능
기존 문제
GitHub Actions에서 EC2에 접속해 생성한 .env.user 파일에 Drone CI 관련 환경변수가 남아 경고가 발생하는 이슈가 있었습니다.

이로 인해 .env.user 파일의 길이가 비정상적으로 길어졌고,


환경변수 인자(argument) 개수가 초과되어 argument list too long 에러가 발생, Spring 서버가 배포되지 않는 문제가 있었습니다.
-> 문제 발생 시마다 EC2에 직접 접속해 .env.user 파일을 수동으로 재생성해야 했습니다.
수정 이후 (테스트 결과)
GitHub Actions에서 Drone SSH 플러그인 흔적이 남아 있을 경우 이를 자동으로 삭제하도록 수정하였습니다.
-> 이후 배포 시 더 이상 에러가 발생하지 않고, 자동으로 정상 배포가 완료되는 것을 확인하였습니다.

문제였던 이유
appleboy/ssh-action을 통해 접속한 EC2에 .env.user 파일을 생성하도록 합니다. appleboy/ssh-action은 원래 Drone 플러그인으로 먼저 개발된 ssh-action로, GitHub Actions에서도 사용할 수 있도록 확장되었지만, 여전히 Drone 관련 코드 일부를 공유하고 있습니다.
Drone에서 SSH 명령어를 실행할 경우, 내부적으로 항상 DRONE_SSH_PREV_COMMAND_EXIT_CODE라는 환경변수를 남겨 명령어 종료 상태를 추적합니다.
그래서 appleboy/ssh-action이 EC2에 .env.user 파일을 만들 때,
DRONE_SSH_PREV_COMMAND_EXIT_CODE 메세지가 줄마다 삽입되었었고, echo를 통해 .env 파일을 만들 때 문자열 전체를 파일로 저장하다 보니, 실제 환경 변수 파일에 불필요한 메시지가 포함되었었습니다.
이렇게 잘못된 라인이 .env.user 파일에 다수 존재하면,

docker-compose나 Spring이 환경변수를 읽어올 때 'export $(cat .env.user | xargs)' 여기에 인자가 너무 많아져서 "too many arguments" 에러가 발생하게 된 것입니다..!!
현재 export $(cat .env.user | xargs)가 사용됨을 확인한 상태이지만, 어디서 사용되었는지는 발견하지 못했습니다.
내용 정리
https://persi0815.tistory.com/157
관련 이슈
appleboy/drone-ssh#175
일정