By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Have problem with appspec.yml for deploy ruby on rails to ec2 instance with AWS CodeDeploy and AWS CodePipeline.

0

Hi I new on AWS here. I want to try to deploy some ruby on rails project to ec2 instance and my use case I want is when I deploy code to GitHub to my specific branch (like branch master etc.) I want it to deploy to my ec2 instance right after push to that branch. and I run into this guide (link) they use AWS CodeDeploy and AWS CodePipeline in this guide. I try to following they step and I got struck at appspec.yml. I try to following appspec.yml in this guide and make some modify to following code.

appspec.yml

version: 0.0
os: linux
files:
- source: /
destination: /var/www/eb-rails/deployment
file_exists_behavior: OVERWRITE
permissions:
- object: /var/www/eb-rails/deployment
pattern: "**"
owner: ubuntu
group: ubuntu
mode: 775
hooks:
AfterInstall:
- location: scripts/dependencies_install.sh
runas: ubuntu

and my scripts/dependencies_install.sh

#!/bin/bash
export PATH=/home/ubuntu/.rvm/gems/ruby-2.7.8/bin:/home/ubuntu/.rvm/gems/ruby-2.7.8@global/bin:/home/ubuntu/.rvm/rubies/ruby-2.7.8/bin:/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/.rvm/bin:/home/ubuntu/.rvm/bin
sudo kill -9 $(cat /var/www/my-app/tmp/pids/server.pid)
cd /var/www/my-app/
#sudo apt-get install ruby2.3-dev libffi-dev -y
gem install nokogiri — — use-system-libraries
bundle config build.nokogiri — use-system-libraries
gem install bundler — user-install
bundle install

note my ruby-version in this test project is 2.7.8

so I following guide and when I push code to my github it trigger my both AWS CodeDeploy and AWS CodePipeline but the deploy failed and when I try to see in log in my ec2 instance with less /var/log/aws/codedeploy-agent/codedeploy-agent.log I found this

2023-07-25T03:07:12 INFO  [codedeploy-agent(713)]: [Aws::CodeDeployCommand::Client 200 0.020335 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":5,\"script_name\":\"\",\"message\":\"The deployment failed because the application specification file specifies only a source file (/). Add the name of the destination file to the files section of the AppSpec file, and then try again.\",\"log\":\"\"}"},host_command_identifier:"some base64 word here.......")

so I want to know where I gone wrong in my appspec.yml? I try to look into another guide they can set source: / normally but I get this in log.

asked a year ago782 views
1 Answer
4
Accepted Answer

Hello.
Since the structure of the file is yaml, I thought it would be an error if I did not set the indentation as follows.
The error message says that "destination" is not listed under "files".
So, we set the indentation as follows so that "destination" is set inside "files".
Can you confirm that this works?
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure.html

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/eb-rails/deployment
    file_exists_behavior: OVERWRITE
permissions:
  - object: /var/www/eb-rails/deployment
    pattern: "**"
    owner: ubuntu
    group: ubuntu
    mode: 775
hooks:
  AfterInstall:
    - location: scripts/dependencies_install.sh
      runas: ubuntu
profile picture
EXPERT
answered a year ago
profile picture
EXPERT
reviewed 7 months ago
profile pictureAWS
EXPERT
reviewed a year ago
profile picture
EXPERT
reviewed a year ago
  • I see. My code not give a space correctly so it can't find my destination in next line. Thank You

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions