aws / aws-codedeploy-agent

Host Agent for AWS CodeDeploy
https://aws.amazon.com/codedeploy
Apache License 2.0
329 stars 187 forks source link

Support for ruby 2.5 (Ubuntu 18.04) #158

Closed carlnordenfelt closed 5 years ago

carlnordenfelt commented 6 years ago

I'm trying to install the aws-codedeploy-agent on Ubuntu 18.04. Ubuntu 18.04 comes with ruby 2.5.1

./install auto
I, [2018-05-02T15:39:46.472855 #4588]  INFO -- : Starting Ruby version check.
E, [2018-05-02T15:39:46.472978 #4588] ERROR -- : Current running Ruby version for root is 2.5.1, but Ruby version 2.x needs to be installed.
E, [2018-05-02T15:39:46.473012 #4588] ERROR -- : If you already have the proper Ruby version installed, please either create a symlink to /usr/bin/ruby2.x,
E, [2018-05-02T15:39:46.473034 #4588] ERROR -- : or run this install script with right interpreter. Otherwise please install Ruby 2.x for root user.
E, [2018-05-02T15:39:46.473055 #4588] ERROR -- : You can get more information by running the script with --help option.

ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

I followed the advice and create a symlink from ruby2.4 => ruby2.5 and re-ran installation:

ln -sf /usr/bin/ruby2.5 /usr/bin/ruby2.4

./install auto
I, [2018-05-02T15:42:59.087490 #4603]  INFO -- : Starting Ruby version check.
W, [2018-05-02T15:42:59.087611 #4603]  WARN -- : The Ruby version in /usr/bin/ruby2.4 is 2.5.1, . Attempting to install anyway.
I, [2018-05-02T15:42:59.087647 #4603]  INFO -- : Starting update check.
I, [2018-05-02T15:42:59.087670 #4603]  INFO -- : Attempting to automatically detect supported package manager type for system...
I, [2018-05-02T15:42:59.094237 #4603]  INFO -- : Checking AWS_REGION environment variable for region information...
dpkg-query: package 'codedeploy-agent' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
I, [2018-05-02T15:42:59.105933 #4603]  INFO -- : Running version No running version
I, [2018-05-02T15:42:59.106015 #4603]  INFO -- : Downloading version file from bucket aws-codedeploy-eu-west-1 and key latest/VERSION...
I, [2018-05-02T15:42:59.153223 #4603]  INFO -- : Downloading version file from bucket aws-codedeploy-eu-west-1 and key latest/VERSION...
I, [2018-05-02T15:42:59.175399 #4603]  INFO -- : Downloading package from bucket aws-codedeploy-eu-west-1 and key releases/codedeploy-agent_1.0-1.1458_all.deb...
I, [2018-05-02T15:42:59.303860 #4603]  INFO -- : Executing `/usr/bin/gdebi -n -o Dpkg::Options::=--force-confdef -o Dkpg::Options::=--force-confold /tmp/codedeploy-agent_1.0-1.1458_all.tmp-20180502-4603-2fpoe0.deb`...
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Reading state information... Done
This package is uninstallable
Dependency is not satisfiable: ruby2.0|ruby2.1|ruby2.2|ruby2.3

E, [2018-05-02T15:44:46.732781 #4672] ERROR -- : Error installing /tmp/codedeploy-agent_1.0-1.1458_all.tmp-20180502-4672-hj5g9h.deb.

At this point I rather desperately created a symlink between ruby2.5 and ruby2.3 without actually expecting it to work and as I suspected, no luck, same error.

ln -sf /usr/bin/ruby2.5 /usr/bin/ruby2.3

Any suggestions other than trying to install ruby2.4 via rvm which I have also tried and failed (don't have the logs from that attempt)?

carlnordenfelt commented 6 years ago

I've trudged along a little bit with this and found that installing it from git appears to work on a clean Ubuntu 18.04 instance (AMI ID: ami-0b91bd72)

git clone https://github.com/aws/aws-codedeploy-agent.git
gem install bundler
gem install rake
cd aws-codedeploy-agent
bundle install
rake clean && rake

At least it builds and the tests passes. I haven't actually started the agent because I have no configuration but the error message is promising

bin/codedeploy-agent start
error: The config file /opt/codedeploy-agent/conf/codedeployagent.yml does not exist or is not readable
salmonte commented 6 years ago

Hi @carlnordenfelt,

I was able to get aws-codedeploy-agent running on Ubuntu Bionic working using your idea to install the gems using bundler. Here is a snippet of what I used. I haven't had a chance to do a codedeploy release yet, so I can't verify if all the Lifecycle hooks work fine.

# Install aws-codedeploy-agent and required gems
sudo apt-get install -y git
codedeploy_git_url='https://github.com/aws/aws-codedeploy-agent.git'
git clone "$codedeploy_git_url"
sudo gem install bundler
sudo mv aws-codedeploy-agent /opt/codedeploy-agent
cd /opt/codedeploy-agent
bundle install --system

# Setup permissions
sudo chown -R root.root /opt/codedeploy-agent
sudo chmod 644 /opt/codedeploy-agent/conf/codedeployagent.yml
sudo chmod 755 /opt/codedeploy-agent/init.d/codedeploy-agent
sudo chmod 644 /opt/codedeploy-agent/init.d/codedeploy-agent.service

# Create symlink to match ./install setup
sudo mkdir -p /etc/codedeploy-agent
sudo ln -s /opt/codedeploy-agent/conf /etc/codedeploy-agent/conf

# Move init scripts
sudo mv /opt/codedeploy-agent/init.d/codedeploy-agent /etc/init.d/codedeploy-agent
sudo mv /opt/codedeploy-agent/init.d/codedeploy-agent.service \
        /lib/systemd/system/codedeploy-agent.service

# Delete RHEL init info since this is for Ubuntu Bionic
sudo sed -i.bak '2,8d' /etc/init.d/codedeploy-agent && \
sudo rm -f /etc/init.d/codedeploy-agent.bak

# Enable init.d scripts to start at boot
sudo /etc/init.d/codedeploy-agent start && echo ''
sudo /usr/sbin/update-rc.d codedeploy-agent defaults
sudo /usr/sbin/update-rc.d codedeploy-agent enable

# Cleanup
files=(.git
    CODE_OF_CONDUCT.md
    CONTRIBUTING.md
    Gemfile.lock
    LICENSE
    NOTICE
    README.md
    Rakefile
    buildspec-agent-rake.yml
    coverage
    deployment
    features
    spec
    test)

cd /opt/codedeploy-agent

for f in "${files[@]}";do
    sudo rm -rf "$f"
done
JorisBolsens commented 6 years ago

installing 2.4 via rvm only partially works, it fails later with

I, [2018-06-05T23:53:19.422673 #14835]  INFO -- : Executing `/usr/bin/gdebi -n -o Dpkg::Options::=--force-confdef -o Dkpg::Options::=--force-confold /tmp/codedeploy-agent_1.0-1.1458_all.tmp-20180605-14835-coa00t.deb`...
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading state information... Done
This package is uninstallable
Dependency is not satisfiable: ruby2.0|ruby2.1|ruby2.2|ruby2.3

E, [2018-06-05T23:53:20.638750 #14835] ERROR -- : Error installing /tmp/codedeploy-agent_1.0-1.1458_all.tmp-20180605-14835-coa00t.deb.
hrmmmwhynot commented 6 years ago

@salmonte your script worked perfect without any modifications for my Ubuntu 18.04 in AWS, even confirmed codedeploy was able to deploy to the instance afterward and the lifecycle hooks worked fine for me.

srv-stack commented 6 years ago

+1 on this request

ghost commented 6 years ago

Would anyone happened that errors are not shown in the deployments?

jshethforce commented 6 years ago

I've noticed that it only copies folders properly in the "files" section of the appspec.yml file. Files are incorrectly marked as folders, and unreadable.

ghost commented 6 years ago

After 2 days of testing I managed to make it work in a clean installation of Ubuntu 18 with rvm:

(sudo su)
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

\curl -sSL https://get.rvm.io | bash -s stable --ruby=2.3.0

echo 'source /usr/local/rvm/scripts/rvm' >> /etc/profile
echo 'source /usr/local/rvm/scripts/rvm' >> ~/.bashrc
exec $SHELL

ruby -v

gem install bundler

cd /opt
git clone https://github.com/aws/aws-codedeploy-agent.git codedeploy-agent
cd codedeploy-agent
bundle install
rake clean && rake

cp /opt/codedeploy-agent/init.d/codedeploy-agent /etc/init.d/
systemctl daemon-reload
systemctl start codedeploy-agent
systemctl enable codedeploy-agent
commx commented 6 years ago

Another idea to get codedeploy-agent running on Ubuntu 18.04 (bionic):

# remove ruby 2.5/rake if installed
apt purge libruby ruby rake

# add repositories for xenial and xenial-updates
cat << EOF > /etc/apt/sources.list.d/xenial.list
deb http://archive.ubuntu.com/ubuntu/ xenial main
deb http://archive.ubuntu.com/ubuntu/ xenial-updates main
EOF

# priorise ruby/rake from xenial repository
cat << EOF > /etc/apt/preferences.d/ruby-xenial
Package: ruby
Pin: release v=16.04, l=Ubuntu
Pin-Priority: 1024

Package: rake
Pin: release v=16.04, l=Ubuntu
Pin-Priority: 1024
EOF

# install ruby and dependent packages
apt update
apt install ruby gdebi-core

# download and run codedeploy-agent installer
curl -o /tmp/codedeploy-installer https://aws-codedeploy-eu-west-1.s3.amazonaws.com/latest/install
chmod +x /tmp/codedeploy-installer
/tmp/codedeploy-installer auto

# delete installer script
rm -f /tmp/codedeploy-installer

# create systemd service file and enable it
mv /etc/init.d/codedeploy-agent.service /lib/systemd/system/codedeploy-agent.service
systemctl enable codedeploy-agent.service

This approach ensures that your system is receiving security updates for ruby, and this won't break anything (unless any of your applications require ruby >= 2.4). Also, this uses "official" stable releases of the AWS CodeDeploy agent.

kingthrillgore commented 6 years ago

Trying to setup the codedeploy-agent on a new 18.04 image using rodrigodev94's method, and the GPG server is returning connection timed out. Are there options to install it without needing to validate the keys? Or just confirmation that they key agent here isn't failing?

gslin commented 6 years ago

I created fake package (ruby2.3) and modify install script to workaround this issue:

# Ruby 2.5
sudo apt -y install ruby

# Ruby 2.3 (fake)
sudo apt -y install equivs
cd /tmp
equivs-control ruby2.3.control
perl -pi -e 's{^Package.*}{Package: ruby2.3}' ruby2.3.control
equivs-build ruby2.3.control
sudo dpkg -i ruby2.3_1.0_all.deb

# AWS CodeDeploy (us-east-1)
cd /tmp
wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/latest/install
perl -pi -e "s{\\['2.4', '2.3', '2.2', '2.1', '2.0'\\]}{['2.5', '2.4', '2.3', '2.2', '2.1', '2.0']}" install
chmod 755 install
sudo ./install auto
mixxx73 commented 6 years ago

any chance to fix that one ?

kadihf commented 6 years ago

Ubuntu 18.04 has released in April. But this agent is not supporting it now. It's too late.

yardensachs commented 6 years ago

Any news on this?

blackelk commented 6 years ago

+1 to the request

tatobi commented 6 years ago

+1 it is a shame that AWS supports Ubuntu 18.04LTS officially from their repository and quick launch page, the 18.04 is out for 5 months BUT nobody is there from 10k+ engineers who could fix it.

fleaz commented 6 years ago

Hi @rohkat-aws, I just saw dc221297c0219f68c6a3d58f0cdae13117912bff was pushed to master. Does this mean that your internal testing is done and the CD-agent is ready for Ruby 2.5?

rohkat-aws commented 6 years ago

Yes its , but the agent needs to released . Will keep the issue open till we dont start releasing it.

say8425 commented 6 years ago

When will be released?

say8425 commented 6 years ago
#!/bin/bash
apt update
apt install ruby -y
gem install bundler
git clone https://github.com/aws/aws-codedeploy-agent.git /opt/codedeploy-agent
sudo chown -R root.root /opt/codedeploy-agent
sudo chmod 644 /opt/codedeploy-agent/conf/codedeployagent.yml
sudo chmod 755 /opt/codedeploy-agent/init.d/codedeploy-agent
sudo chmod 644 /opt/codedeploy-agent/init.d/codedeploy-agent.service
cd /opt/codedeploy-agent
bundle install --system
rake clean && rake
cp /opt/codedeploy-agent/init.d/codedeploy-agent /etc/init.d/
systemctl daemon-reload
systemctl start codedeploy-agent
systemctl enable codedeploy-agent

I compose the @salmonte and @ghost scripts. This scripts is tested many times. Of course, you can install the ruby with rvm or rbenv.

@vetermanve oops I fixed it up. Thanks 👍

vetermanve commented 6 years ago
#!/bin/bash
apt update
apt install ruby -y
gem install bundler
git clone https://github.com/aws/aws-codedeploy-agent.git /opt/codedeploy-agent
sudo chown -R root.root /opt/codedeploy-agent
sudo chmod 644 /opt/codedeploy-agent/conf/codedeployagent.yml
sudo chmod 755 /opt/codedeploy-agent/init.d/codedeploy-agent
sudo chmod 644 /opt/codedeploy-agent/init.d/codedeploy-agent.service
cd /opt/codedeploy-agent
bundle install --system
rake clean && rake
cp /opt/codedeploy-agent/init.d/codedeploy-agent /etc/init.d/
systemctl daemon-reload
systemctl start codedeploy-agent
systemctl enable codedeploy-agent

I compose the @salmonte and @ghost scripts. This scripts is tested many times. Of course, you can install the ruby with rvm or rbenv.

You missed first slash in cd /opt/codedeploy-agent! Great work! Thanks!

morafde commented 6 years ago

Hello All,

I had the same issues and after battling for almost 2 days, i finally raised the complaint on AWS support centre. This is what they sent to me that worked effortlessly.

The agent installation failed because the CodeDeploy agent does not support Ruby 2.5 (shipped by Ubuntu 18.04 repositories) [2] yet.

Workaround

You can still install the CodeDeploy agent on Ubuntu 18.04 by downgrading Ruby to version 2.3 (shipped by Ubuntu 16.04 repositories) [3].

Please follow these steps to downgrade Ruby to version 2.3:

remove ruby 2.5/rake if installed

sudo apt purge libruby ruby rake

add repositories for Ubuntu 16.04

sudo cat << EOF > /etc/apt/sources.list.d/xenial.list deb http://archive.ubuntu.com/ubuntu/ xenial main deb http://archive.ubuntu.com/ubuntu/ xenial-updates main EOF

priorise ruby/rake from Ubuntu 16.04 repository

sudo cat << EOF > /etc/apt/preferences.d/ruby-xenial Package: ruby Pin: release v=16.04, l=Ubuntu Pin-Priority: 1024

Package: rake Pin: release v=16.04, l=Ubuntu Pin-Priority: 1024 EOF

install ruby and dependent packages

sudo apt update sudo apt install ruby gdebi-core

You can proceed to the CodeDeploy agent installation following the same documentation [1] after downgrading Ruby.

I hope this helps someone.

morafde commented 6 years ago

Hello All,

I had the same issues and after battling for almost 2 days, i finally raised the complaint on AWS support centre. This is what they sent to me that worked effortlessly.

The agent installation failed because the CodeDeploy agent does not support Ruby 2.5 (shipped by Ubuntu 18.04 repositories) [2] yet.

Workaround

You can still install the CodeDeploy agent on Ubuntu 18.04 by downgrading Ruby to version 2.3 (shipped by Ubuntu 16.04 repositories) [3].

Please follow these steps to downgrade Ruby to version 2.3:

remove ruby 2.5/rake if installed

sudo apt purge libruby ruby rake

add repositories for Ubuntu 16.04

sudo cat << EOF > /etc/apt/sources.list.d/xenial.list deb http://archive.ubuntu.com/ubuntu/ xenial main deb http://archive.ubuntu.com/ubuntu/ xenial-updates main EOF

priorise ruby/rake from Ubuntu 16.04 repository

sudo cat << EOF > /etc/apt/preferences.d/ruby-xenial Package: ruby Pin: release v=16.04, l=Ubuntu Pin-Priority: 1024

Package: rake Pin: release v=16.04, l=Ubuntu Pin-Priority: 1024 EOF

install ruby and dependent packages

sudo apt update sudo apt install ruby gdebi-core

You can proceed to the CodeDeploy agent installation following the same documentation [1] after downgrading Ruby.

I hope this helps someone.

Ensure you specify the path in the right ruby installation once you download the package from the right sim bucket.. mine was - sudo /usr/share/rvm/rubies/ruby-2.3.5/bin/ruby ./install auto

commx commented 6 years ago

It's kind of funny that support proposes something we added as recommendation in this issue some time ago. However, that may break software that relies on newer Ruby releases - use it with caution.

morafde commented 6 years ago

Thanks @commx Codedeploy is the only ruby dependent solution we intend to run on this server but your advice is well noted.

gregkonushev-okta commented 5 years ago

encountered the same issue, it is sad to see that new shiny product from AWS does not support new Ubuntu LTS

rohkat-aws commented 5 years ago

@gregkonushev-okta hey we have already rolled out a fix for this , its already in us-east-1 and being rolled out in other regions too.

gregkonushev-okta commented 5 years ago

@rohkat-aws that's great, which version of codedeploy agent works with ruby 2.5? When will you have rollout on us-east-2?

marcosdiez commented 5 years ago

If you want to beta test the version from us-east-1 on ubuntu 18.04:

sudo apt-get install ruby
wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/latest/install
sudo ruby install auto
commx commented 5 years ago

Looks like fixed versions are now available on most common regions:

eu-west-1: Setting up codedeploy-agent (1.0-1.1597) ...
us-east-1: Setting up codedeploy-agent (1.0-1.1597) ...
us-east-2: Setting up codedeploy-agent (1.0-1.1597) ...
rohkat-aws commented 5 years ago

resolved for a while,after the last agent release