์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[VVUE] CI/CD ๋ฐฐํฌ ํŒŒ์ดํ”„๋ผ์ธ ์ˆ˜์ •

๋ณธ๋ฌธ

728x90

์ƒํ™ฉ

Github์œผ๋กœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์˜ฎ๊ธฐ๊ณ , Github Actions๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ํ•จ

 

๊ณผ๊ฑฐ ๊ตฌ์กฐ

Gitlab(Webhook) => Jenkins => AWS EC2 (๋‚ด๋ถ€์—์„œ Docker Image ์ƒ์„ฑ & Run)

 


๋ฐฉ๋ฒ•1 :   Github Actions + AWS S3 + AWS Code Deploy +AWS EC2  

๋”๋ณด๊ธฐ

์žฅ์ ) 

1. Docker Hub์— ์˜์กดํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค.

 

๋‹จ์ ) 

1. ๋ณต์žกํ•˜๋‹ค

2. ๋ˆ์ด ์—†๋‹ค

- Github Action -

https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions

 

Understanding GitHub Actions - GitHub Docs

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged

docs.github.com

 

- AWS S3 ๋ฅผ ๋„์ปค ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋กœ ๊ตฌ์ถ•ํ•ด์„œ ์‚ฌ์šฉํ•˜๊ธฐ -

https://pyrasis.com/jHLsAlwaysUpToDateDocker/Unit06/01#amazon-s3%EC%97%90-%EC%9D%B4%EB%AF%B8%EC%A7%80-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%A0%80%EC%9E%A5

 

PYRASIS.COM: ์ด์žฌํ™์˜ ์–ธ์ œ๋‚˜ ์ตœ์‹  Docker - Unit 6. Docker ์ข€๋” ํ™œ์šฉํ•˜๊ธฐ

์ €์ž‘๊ถŒ ์•ˆ๋‚ด ์ฑ… ๋˜๋Š” ์›น์‚ฌ์ดํŠธ์˜ ๋‚ด์šฉ์„ ๋ณต์ œํ•˜์—ฌ ๋‹ค๋ฅธ ๊ณณ์— ๊ฒŒ์‹œํ•˜๋Š” ๊ฒƒ์„ ๊ธˆ์ง€ํ•ฉ๋‹ˆ๋‹ค.์ฑ… ๋˜๋Š” ์›น์‚ฌ์ดํŠธ์˜ ๋‚ด์šฉ์„ ๋ฐœ์ทŒ, ์š”์•ฝํ•˜์—ฌ ๊ฐ•์˜ ์ž๋ฃŒ, ๋ฐœํ‘œ ์ž๋ฃŒ, ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ๋“ฑ์œผ๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ๊ธˆ

pyrasis.com

 

-  Github Actions + AWS S3 + AWS Code Deploy + AWS EC2 -

https://dkswnkk.tistory.com/674

 

Spring Boot + GitHub Actions + AWS CodeDeploy๋ฅผ ํ™œ์šฉํ•œ CI/CD ๊ตฌ์ถ•

์„œ๋ก  ์ง€๊ธˆ๊นŒ์ง€ ๋งค๋ฒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์ถ•ํ•  ๋•Œ๋งˆ๋‹ค ์ด์ „ ์ฝ”๋“œ๋“ค์„ ๋ฒˆ๊ฑฐ๋กญ๊ฒŒ ๋ด๊ฐ€๋ฉด์„œ CI/CD๋ฅผ ๊ตฌ์ถ•ํ–ˆ์—ˆ๋Š”๋ฐ, ์ด๋ฒˆ ๊ธฐํšŒ์— ํ•œ๋ฒˆ ๋ฌธ์„œํ™”๋ฅผ ํ•ด๋ณด๊ณ ์ž ๊ธ€์„ ์ž‘์„ฑํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. [CI/CD] CI/CD๋ž€?, ์ง€์†์ 

dkswnkk.tistory.com

 

๋ฐฉ๋ฒ•2 : Github Actions + Docker Hub + AWS EC2

๋”๋ณด๊ธฐ

์žฅ์ )

1. Docker Hub์œผ๋กœ ๊ฐ„ํŽธํ•˜๊ฒŒ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋‹ค

2. (๋‚˜์—๊ฒŒ๋Š”) ๋ฌด๋ฃŒ๋‹ค

 

๋‹จ์ )

1. Public Repo ..

2. Docker Hub์— ์˜์กดํ•œ๋‹ค 


์•„๋ž˜๋Š” ๋ฐฉ๋ฒ• 2 ์ ์šฉ๊ณผ์ •์ด๋‹ค

 

 

1. Github Secret ์„ค์ •

Settings -> Secrets and variables -> Actions

DOCKERHUB_PASSWORD : ๋ณธ์ธ์˜ Docker Hub Username
DOCKERHUB_USERNAME  : ๋ณธ์ธ์˜ Docker Hub Password
EC2_HOST : AWS EC2 ์ธ์Šคํ„ด์Šค์˜ ํผ๋ธ”๋ฆญ IPv4 DNS 
EC2_KEY : AWS EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์ €์žฅ๋œ pem ํ‚ค
EC2_PORT :  
EC2_USERNAME : ubuntu
ENV_PATH : .env ํŒŒ์ผ ๊ฒฝ๋กœ
SERVER_PORT : ํ•ด๋‹น ์„œ๋ฒ„ ๋Œ์•„๊ฐ€๋Š” ํฌํŠธ

2. Docker File ์ž‘์„ฑ

FROM openjdk:17
ARG IDLE_PROFILE
ARG JAR_FILE=build/libs/*.jar
ENV ENV_IDLE_PROFILE=$IDLE_PROFILE
COPY ${JAR_FILE} app.jar
RUN echo $ENV_IDLE_PROFILE
ENTRYPOINT ["java", "-Dspring.profiles.active=${ENV_IDLE_PROFILE}", "-jar","/app.jar"]

IDLE_PROFILE์€ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์‹œ๋„ํ•˜๋А๋žด ์žˆ์Œ

 

3. github work flow ์ž‘์„ฑ

๋ฐœ์ƒํ–ˆ๋˜ ๋ฌธ์ œ

1) ์„œ๋กœ ๋‹ค๋ฅธ job๊ฐ„์— ํ™˜๊ฒฝ์ด ๊ณต์œ ๋˜์ง€ ์•Š์Œ์„ ๊ฐ„๊ณผํ•˜๊ณ , ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ์˜ค๋ฅ˜๋‚จ

- ls ๋กœ checkout ํ•ด์˜จ code์˜ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ–ˆ๋”๋‹ˆ ์—†์Œ > ์ž˜๋ชป ๋˜์—ˆ์Œ์„ ๊นจ๋‹ฌ์Œ

 

2) ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

[ ๋˜‘๊ฐ™์€ ์—๋Ÿฌ ] 

https://github.com/marketplace/actions/ssh-remote-commands#if-you-are-using-openssh

 

SSH Remote Commands - GitHub Marketplace

Executing remote ssh commands

github.com

[ํ•ด๊ฒฐ ๋ฐฉ์•ˆ]

https://github.com/appleboy/ssh-action#setting-up-a-ssh-key

 

GitHub - appleboy/ssh-action: GitHub Actions for executing remote ssh commands.

GitHub Actions for executing remote ssh commands. Contribute to appleboy/ssh-action development by creating an account on GitHub.

github.com

// workflow ๋ถ™์—ฌ๋„ฃ๊ธฐ

[ ์ „์ฒด์ ์ธ ๋กœ์ง ] 

https://chb2005.tistory.com/191

 

[CI/CD] Github Actions๋ฅผ ํ™œ์šฉํ•œ CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ• (+ Docker hub)

Github Actions๋ฅผ ํ™œ์šฉํ•œ CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ• ๊ฐœ๋… EC2 Instance ์ƒ์„ฑ, EC2 Instance์— Docker ์„ค์น˜, Docker Hub ํšŒ์›๊ฐ€์ž…์ด ๋˜์–ด์žˆ๋‹ค๊ณ  ๊ฐ€์ • Github Repository์— ํ”„๋กœ์ ํŠธ์˜ ์ถ”๊ฐ€์‚ฌํ•ญ์ด๋‚˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ push ํ˜น์€ merge Git

chb2005.tistory.com

[ IDLE_PROFILE / ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ] 

https://soojong.tistory.com/entry/Docker%EB%A1%9C-Spring-%EC%95%A0%ED%94%8C%EB%A6%AC%EC%BC%80%EC%9D%B4%EC%85%98-%EB%B0%B0%ED%8F%AC%ED%95%98%EA%B8%B0

 

Docker๋กœ Spring ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌํ•˜๊ธฐ

์ด์ „์— ๊ตฌ์ถ•ํ–ˆ๋˜ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ํ”„๋กœ์ ํŠธ์— Docker๋ฅผ ์ ์šฉํ•˜๋ ค๊ณ ํ•œ๋‹ค. ์ตœ์ข…์ ์ธ ์•„ํ‚คํ…์ณ ๋ชจ์Šต์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. Dockerfile๊ณผ ๋ฐฐํฌ Script๋Š” ์•„๋ž˜ ์ €์žฅ์†Œ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š” GitHub - 92SooJong/Toy-Project-Board Contri

soojong.tistory.com

 

728x90

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ