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

[refactor] #256 - Jenkinsfile의 sshPut 명령어 삭제 및 deploy 스크립트 자체에서 dangling 이미지를 삭제하도록 변경 완료 #302

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

hoonyworld
Copy link
Member

@hoonyworld hoonyworld commented Jan 13, 2025

Related issue 🛠

Work Description ✏️

Jenkinsfile의 sshPut 명령어 삭제

  • deploy 스크립트를 애플리케이션 서버로 복사하지 않고, 각 애플리케이션에 sshCommand로 접속해서 직접 실행하도록 변경

sshPut 명령어 삭제 및 deploy 스크립트 자체에서 dangling 이미지를 삭제하도록 변경

  • 기존에는 Jenkinsfile에서 명령어로 애플리케이션 배포 후 삭제를 하도록 했는데 deploy 스크립트 내에서 한번에 관리하면 좋을 것 같아서 deploy.sh에 dangling 이미지 삭제 과정을 포함시켰습니다.

스크립트를 젠킨스 내 Managed files 섹션에서 관리하도록 변경

  • 이번에 bug/fix 작업을 진행하면서, Jenkinsfile을 GitHub에서 의존적으로 관리하다 보니, Jenkinsfile을 수정할 때마다 PR을 생성하고 CI/CD를 실행하는 과정이 확인하는데 시간도 오래걸리고 번거로웠습니다.
  • 그래서 Pipeline: Multibranch with Defaults 플러그인을 사용해서 Jenkinsfile을 Git 레포지토리에 두지 않고도 Jenkins에서 직접 관리하는 스크립트를 사용할 수 있도록 변경하였습니다.
    • 이 과정에서 레포지토리에 있는 Jenkinsfile을 삭제할 지 말 지 고민이 되었는데, 코드를 보기 편하게 아카이빙 용으로 두는게 나을 것 같아서 삭제하지는 않았습니다! (이 부분에 대해서 혜린님의 생각이 궁금해요 😊)

Trouble Shooting ⚽️

sshPut 명령어와 sshCommand의 메커니즘 차이

image
image

  • sshPut 명령을 이용하여, Jenkins 서버에서 원격 서버로 파일 복사를 수행하려고 했습니다.
  • 하지만 배포 서버에 있는 deploy 스크립트를 찾지 못하는 오류가 발생하였습니다. (결국 오류는 아니였습니다 😭)
  • 알아본 결과 sshPut과 sshCommand는 명령어를 실행하는 위치가 다르다는 것을 알게되었습니다.
    • sshPut는 A 서버에서 원격 B 서버로 파일을 전송하는 역할을 하며, 전송 대상은 B 서버이지만 명령어는 A 서버에서 실행
    • sshCommand는 Jenkins에서 원격 서버에 SSH로 연결하여 명령어를 실행할 때 사용하며, B 서버에 SSH로 접속하여 B 서버에서 명령어 실행
  • 따라서, sshPut 명령어를 통해 파일 복사를 수행할 때 A 서버는 깃허브 액션 서버였습니다.
    • 그래서 sshPut으로 파일 복사를 하려면 깃허브 레포지토리에 deploy 스크립트를 업로드 해야합니다!
  • 하지만, 깃허브 레포지토리에 deploy 스크립트를 올리는 것은 보안 측면에서도, 확장성 측면에서도 좋지 않는 부분이라고 판단하였습니다.
  • 그래서, 각 어플리케이션 서버(dev, prod)에서 직접 deploy 스크립트를 관리하고 이를 sshCommand 명령어로 실행할 수 있도록 하는 것이 유지보수 측면에서도 도움이 될 것 같아 해당 방법으로 진행하였습니다.

Related ScreenShot 📷

스크립트 젠킨스 내로 이동

AS-IS

image

  • 깃허브에 올라온 Jenkinsfile 이용

TO-BE

image
image

  • Jenkins 자체 스크립트를 저장하고 실행

Uncompleted Tasks 😅

To Reviewers 📢

Copy link
Collaborator

@hyerinhwang-sailin hyerinhwang-sailin left a comment

Choose a reason for hiding this comment

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

트러블 슈팅까지 고생하셨습니다!!
확인을 위해 매번 pr을 올리는 것보다 jenkins에서 직접 확인하고 관리하는 방식 좋다고 생각합니다!
코드 아카이빙 목적으로 잘 적용된 것으로 확인된 Jenkinsfile만 깃허브에 업로드하는 방식도 괜찮을 것 같은데, 어떻게 생각하시나요?

Copy link
Member Author

@hoonyworld hoonyworld left a comment

Choose a reason for hiding this comment

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

네네 저도 그 목적으로 말씀드렸습니다 ㅎㅎ
의견이 일치해서 다행이네요

@hoonyworld hoonyworld merged commit e9f53af into develop Jan 13, 2025
1 check passed
@hoonyworld hoonyworld deleted the refactor/#256 branch January 13, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants