๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿคท๐Ÿผ‍โ™€๏ธ Etc.../- linux, aws, docker, k8s

[AWS CodeDeploy] EC2์— Travis ๊ฐ€ ์ ‘๊ทผํ•  IAM ์ •์ฑ… ์ถ”๊ฐ€ํ•˜๊ณ  CodeDeploy Agent ์„ค์น˜ ๋ฐ ์„ค์ •

by Wonit 2020. 12. 6.

์ด์ œ ๋“œ๋””์–ด EC2์— ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  IAM ์ •์ฑ…์„ ์ ์šฉ์‹œํ‚ฌ ๋‹จ๊ณ„์ด๋‹ค.

์ˆœ์„œ

์ˆœ์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  1. EC2 ์—ญํ•  ์ถ”๊ฐ€.
  2. EC2 ์ธ์Šคํ„ด์Šค ์ ‘์†
  3. Travis์˜ IAM ๋กœ๊ทธ์ธ
  4. AWS CodeDeploy Agent ์‹คํ–‰

์šฐ์„  EC2 ํƒญ์œผ๋กœ ๊ฐ€์„œ

EC2 ์—ญํ•  ์ถ”๊ฐ€

EC2์— ์šฐ๋ฆฌ๊ฐ€ ๊ธฐ์กด์— ๋งŒ๋“ค์—ˆ๋˜ IAM์„ ์ถ”๊ฐ€ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

์—ญํ•  ์ˆ˜์ • ํด๋ฆญํ•˜๊ณ  ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  EC2 ์ „์šฉ IAM์„ ์ถ”๊ฐ€์‹œํ‚ค์ž

๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋†“์€ ์—ญํ•  ์ถ”๊ฐ€ ํ›„ ์ €์žฅํ•œ๋‹ค.

C2 ์ธ์Šคํ„ด์Šค ์ ‘์†

๊ทธ๋ฆฌ๊ณ  ssh ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ„ฐ๋ฏธ๋„์—์„œ EC2 ์ธ์Šคํ„ด์Šค์— ์ ‘๊ทผํ•ด๋ณด์ž.

Travis์˜ IAM ๋กœ๊ทธ์ธ

Travis๊ฐ€ ์ ‘๊ทผํ•  CodeDeploy์™€ S3 ์ •์ฑ…์„ ๊ฐ–๊ณ  ์žˆ๋Š” IAM ๊ณ„์ •์„ ํ†ตํ•ด ๋กœ๊ทธ์ธ์„ ์ˆ˜ํ–‰ํ•ด์•ผ๋˜๋Š”๋ฐ, ์šฐ์„  AWSCLI๋ฅผ ์ถ”๊ฐ€์‹œ์ผœ๋ณด์ž.

Ubuntu

sudo apt-get install awscli

sudo aws configure

Cent OS

sudo aws configure

์„ ์ˆ˜ํ–‰ํ•ด๊ณ , ๊ทธ๋ฆฌ๊ณ  ์•„๊นŒ IAM ์„ค์ •ํ•˜๊ณ  ๋ฐ›์•˜๋˜ .csv ํŒŒ์ผ์— Access Key Id๋ž‘ Secret Access Key ๋ฅผ ์ ์–ด์ค€๋‹ค.

 

.csv ํŒŒ์ผ์„ ๋‚˜๋Š” excel๋กœ ์‹คํ–‰์‹œ์ผฐ๋Š”๋ฐ, ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ์‹คํ–‰ํ•ด๋„ ๋ฌด๋ฐฉํ•˜๋‹ค.

 

ํ™•์ธํ•  ์ˆ˜๋งŒ ์žˆ๋‹ค๋ฉด ๋‹ค OK

์•„๊นŒ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ 4๊ฐœ์˜ ํ•„๋“œ๊ฐ€ ๋‚˜์˜จ๋‹ค.

๊ฐ๊ฐ .csv ํŒŒ์ผ์—์„œ ๋Œ€์‘์‹œ์ผœ ์ ์–ด์ฃผ๊ณ 

AWS Access Key ID [None]: [????]
AWS Secret Access Key [None]: [????]
Default region name [None]: ap-northeast-2
Default output format [None]: json
[ec2-user@ip-172-31-34-77 ~]$ 
  • region name
  • output format

์—๋Š” ๊ฐ๊ฐ

  • region name: ap-northeast-2
  • output format: json

์ด๋ผ๊ณ  ์ ์œผ๋ฉด ๋œ๋‹ค.

AWS CodeDeploy Agent ์‹คํ–‰

์„ค์ • ๋งˆ์ณค์œผ๋ฉด codedeploy agent ๋‹ค์šด๋ฐ›์•„์•ผํ•œ๋‹ค.


codedeploy agent๋ฅผ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด์ž.

Ubuntu

aws s3 cp s3://aws-codedeploy-ap-northeast-2/latest/install . --region ap-northeast-2

CentOS

wget https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install

๋ช…๋ น์–ด ์ณ์„œ codedeploy agent install์„ ๋‹ค์šด ๋ฐ›๋Š”๋ฐ,

์œ„์˜ ๊ณผ์ •์„ ๊ฑฐ์น˜๋ฉด ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ ๋ณด๋ฉด install ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

ํŒŒ์ผ ์‹คํ–‰ ๊ถŒํ•œ์„ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด์„œ chmod ๋ช…๋ น์–ด๋กœ ํŒŒ์ผ ์‹คํ–‰ ๊ถŒํ•œ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

chmod +x ./install

์ด์ œ ๋‹ค์Œ์œผ๋กœ install ํŒŒ์ผ์„ ์‹คํ–‰์‹œํ‚ค์ž.

install ํŒŒ์ผ ์‹คํ–‰์‹œ์ผœ์•ผ๋˜๋Š”๋ฐ ruby ๋Ÿฐํƒ€์ž„์ด ์žˆ์–ด์•ผํ•œ๋‹ค.

 

๊ทธ๋ž˜์„œ ๋ฃจ๋น„ ๋‹ค์šด ๋จผ์ € ๋ฐ›๊ณ  ์ถ”๊ฐ€ํ•˜์ž.

Ubuntu

sudo apt-get install ruby

sudo ./install auto

CentOS

sudo yum install ruby

sudo ./install auto

ํ•ด์ฃผ๋ฉด agent ๋‹ค์šด์ด ์™„๋ฃŒ๋˜์—ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น daemon ์‹คํ–‰์‹œ์ผœ์ฃผ์ž.

Ubuntu

sudo service codedeploy-agent start

sudo service codedeploy-agent status

๋กœ ์‹คํ–‰ํ•˜๊ณ  ํ™•์ธ

CentOS

sudo systemctl start codedeploy-agent

sudo systemctl status codedeploy-agent

๋Œ“๊ธ€