AWS

EC2 CodeDeploy Agent 설치 Ruby version 2.x needs to be installed.

초코민트냠냠 2023. 1. 10. 11:14
728x90
반응형

EC2에 CodeDeploy Agent 설치해보자

 EC2에 CodeDeploy로 배포 자동화를 만들기 위해 Ubuntu 22.04.1 LTS 환경에 CodeDeply Agent를 설치했습니다. 

https://docs.aws.amazon.com/ko_kr/codedeploy/latest/userguide/codedeploy-agent-operations-install-ubuntu.html

 

Ubuntu Server용 CodeDeploy 에이전트 설치 - AWS CodeDeploy

출력을 임시 로그 파일에 쓰는 것은 Ubuntu 20.04에서 install 스크립트를 사용하여 알려진 버그를 해결하는 동안 사용해야 하는 해결 방법입니다.

docs.aws.amazon.com

공식 홈페이지에 나와 있는 방법을 사용해서 설치를 진행했습니다. 우선 루비와 wget을 설치해줍니다.

$ sudo apt update
$ sudo apt install ruby-full
$ sudo apt install wget

 

그리고 /home/ubuntu 디렉토리로 이동한 다음

$ cd /home/ubuntu

 

wget을 사용해서 설치파일을 받아옵니다. 'bucket name'과 'region-identifer'는 위 공식 홈페이지에 잘 나와있으니 해당하는걸로 찾아서 하면 됩니다. 

$ wget https://bucket-name.s3.region-identifier.amazonaws.com/latest/install
$ wget https://aws-codedeploy-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/latest/install

루비 버전이 맞지 않는다

 

그 다음 wget으로 받은 파일을 실행해서 설치하니다. 로그를 확인해보면 Ruby 2.x가 필요한데 현재 3.x가 설치되어 있다고 합니다. 

$ sudo chmod +x ./install
$ sudo ./install auto > /tmp/logfile
$ sudo service codedeploy-agent start
Failed to start codedeploy-agent.service: Unit codedeploy-agent.service not found.
ubuntu@ip-172-31-5-0:~$ sudo ./install auto
I, [2022-12-12T19:00:50.710135 #4493]  INFO -- : Starting Ruby version check.
E, [2022-12-12T19:00:50.710532 #4493] ERROR -- : Current running Ruby version for root is 3.0.2, but Ruby version 2.x needs to be installed.
E, [2022-12-12T19:00:50.710714 #4493] ERROR -- : If you already have the proper Ruby version installed, please either create a symlink to /usr/bin/ruby2.x,
E, [2022-12-12T19:00:50.710872 #4493] ERROR -- : or run this install script with right interpreter. Otherwise please install Ruby 2.x for root user.
E, [2022-12-12T19:00:50.711076 #4493] ERROR -- : You can get more information by running the script with --help option.

 

찾아보니 Ubuntu 22버전은 apt로 받는 Ruby의 버전이 3.x 라고 합니다. 현재 AWS EC2에 있는 우분투 버전이 22.04이기 때문에 apt로 받은 루비 버전은 3.0.2입니다.

$ ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]

rbenv로 맞는 버전을 설치해보자

그래서 rbenv를 사용해서 루비 2.x를 설치하기로 했습니다. https://github.com/rbenv/rbenv

 

GitHub - rbenv/rbenv: Manage your app's Ruby environment

Manage your app's Ruby environment. Contribute to rbenv/rbenv development by creating an account on GitHub.

github.com

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc

 

rbenv 레포를 참고하여 설치를 진행하고 AWS Code-Deploy Agent 요구사항인 루비 2버전을 설치했습니다. ruby -v를 통해서 확인해보면 잘 설치된 것을 확인할 수 있습니다.

$ rbenv install 2.6.3
$ rbenv global 2.6.3
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

그래도 안되네?

루비를 설치했으니 다시 코드디플로이 에이전트 설치를 진행했습니다. 그런데 마지막에 보면

This package is uninstallable
Dependency is not satisfiable: ruby2.0|ruby2.1|ruby2.2|ruby2.3|ruby2.4|ruby2.5|ruby2.6|ruby2.7

이런 로그가 뜨면서 설치가 진행이 안됩니다. 분명 요구사항에 맞는 루비를 설치했는데?? 그 뒤로 루비 삭제 재설치도 해보고 코드 디플로이 에이전트도 다시 받아서 설치 해보고 하였는데 계속 같은 이유로 진행되지 않았습니다.

$ sudo ./install auto
I, [2022-12-12T20:44:44.671035 #85934]  INFO -- : Starting Ruby version check.
W, [2022-12-12T20:44:44.671372 #85934]  WARN -- : The Ruby version in /home/ubuntu/.rbenv/versions/2.6.3/bin/ruby is 2.6.3, . Attempting to install anyway.
I, [2022-12-12T20:44:44.671574 #85934]  INFO -- : Starting update check.
I, [2022-12-12T20:44:44.671756 #85934]  INFO -- : Attempting to automatically detect supported package manager type for system...
I, [2022-12-12T20:44:44.680249 #85934]  INFO -- : Checking AWS_REGION environment variable for region information...
I, [2022-12-12T20:44:44.680476 #85934]  INFO -- : Checking EC2 metadata service for region information...
I, [2022-12-12T20:44:44.696315 #85934]  INFO -- : Checking AWS_DOMAIN environment variable for domain information...
I, [2022-12-12T20:44:44.696501 #85934]  INFO -- : Checking EC2 metadata service for domain information...
I, [2022-12-12T20:44:44.703852 #85934]  INFO -- : Downloading version file from bucket aws-codedeploy-ap-northeast-1 and key latest/LATEST_VERSION...
I, [2022-12-12T20:44:44.704116 #85934]  INFO -- : Endpoint: https://aws-codedeploy-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/latest/LATEST_VERSION
dpkg-query: package 'codedeploy-agent' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files.
I, [2022-12-12T20:44:44.760909 #85934]  INFO -- : Running version No running version
I, [2022-12-12T20:44:44.761389 #85934]  INFO -- : Downloading package from bucket aws-codedeploy-ap-northeast-1 and key releases/codedeploy-agent_1.4.1-2244_all.deb...
I, [2022-12-12T20:44:44.761693 #85934]  INFO -- : Endpoint: https://aws-codedeploy-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/releases/codedeploy-agent_1.4.1-2244_all.deb
I, [2022-12-12T20:44:44.872707 #85934]  INFO -- : Executing `/usr/bin/gdebi -n -o Dpkg::Options::=--force-confdef -o Dkpg::Options::=--force-confold /tmp/codedeploy-agent_1.4.1-2244_all.tmp-20221212-85934-bm2jus.deb`...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Reading state information... Done
This package is uninstallable
Dependency is not satisfiable: ruby2.0|ruby2.1|ruby2.2|ruby2.3|ruby2.4|ruby2.5|ruby2.6|ruby2.7

E, [2022-12-12T20:44:45.817754 #85934] ERROR -- : Error installing /tmp/codedeploy-agent_1.4.1-2244_all.tmp-20221212-85934-bm2jus.deb.

답은 깃허브 이슈에

깃허브 이슈를 찾아보니 해결한 사람이 있었습니다. 

https://github.com/aws/aws-codedeploy-agent/issues/301#issuecomment-1129912011

 

CodeDeploy agent is not supporting ruby v3.0.1 · Issue #301 · aws/aws-codedeploy-agent

When I tried to install codedeploy agent on my server: $ bundle install Fetching gem metadata from http://rubygems.org/........... Resolving dependencies... Bundler found conflicting requirements f...

github.com

 

우선 rbenv를 삭제하고 나서 apt install ruby-full로 3버전 루비를 설치하였습니다.

$ rm -rf .rbenv/

 

그리고 깃허브 이슈에 있는 방법대로 설치를 진행하였습니다. 

$ mkdir codedeploy-agent_1.3.2-1902_ubuntu22
$ dpkg-deb -R codedeploy-agent_1.3.2-1902_all.deb codedeploy-agent_1.3.2-1902_ubuntu22
$ sed 's/Depends:.*/Depends:ruby3.0/' -i ./codedeploy-agent_1.3.2-1902_ubuntu22/DEBIAN/control
$ dpkg-deb -b codedeploy-agent_1.3.2-1902_ubuntu22/
$ sudo dpkg -i codedeploy-agent_1.3.2-1902_ubuntu22.deb
$ systemctl list-units --type=service | grep codedeploy
$ sudo service codedeploy-agent status
● codedeploy-agent.service - LSB: AWS CodeDeploy Host Agent
     Loaded: loaded (/etc/init.d/codedeploy-agent; generated)
     Active: active (running) since Mon 2022-12-12 21:24:26 KST; 12s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 2035 ExecStart=/etc/init.d/codedeploy-agent start (code=exited, status=0/SUCCESS)
      Tasks: 2 (limit: 1143)
     Memory: 62.8M
        CPU: 1.158s
     CGroup: /system.slice/codedeploy-agent.service
             ├─2041 "codedeploy-agent: master 2041" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             └─2043 "codedeploy-agent: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller of master 2041"

Dec 12 21:24:26 ip-172-31-5-0 systemd[1]: Starting LSB: AWS CodeDeploy Host Agent...
Dec 12 21:24:26 ip-172-31-5-0 codedeploy-agent[2035]: Starting codedeploy-agent:
Dec 12 21:24:26 ip-172-31-5-0 systemd[1]: Started LSB: AWS CodeDeploy Host Agent.

결론

드디어 설치가 완료 되었네요. 같은 이유로 고통받는 분들이 있으면 참고가 되길 바랍니다.

반응형