Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeDeploy running outdated appspec file?

I'm new to AWS CodeDeploy, in fact, I'm just experimenting.

I'm trying to handle continuous integration using CircleCI 2.0 and AWS CodeDeploy so that when I push changes to my django project to development in github, it builds in CircleCI and then pushes the deploy to an S3 and after that the changes are deployed to the EC2.

I did all the configurations in CodeDeploy, and I copied the appspec from a guy in github that used CodeDeploy with a Django/DRF project (such as mine). The only difference is that he was using another kernel in his EC2 instance (I think AWS linux) and I'm using ubuntu. So I had to change the username in the runas section of every hooks part. The first time I ran the create-deployment command in the aws cli the deployment failed with this message:

LifecycleEvent - ApplicationStop
Script - scripts/stop_application.sh
[stderr]No passwd entry for user 'ec2-user'

As it turned out, I forgot to change the runas useer in the ApplicationStop hook. Then I changed it, did the push and the create-deployment again, but the error remains to be the same. Do I need to do something else for the changes in the appspec to be considered or why is this happening?

Here is the appspec.yml file:

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/taptop_web
permissions:
  - object: /home/ubuntu
    pattern: "**"
    owner: ubuntu
    group: ubuntu
hooks:
  BeforeInstall:
    - location: scripts/clean_instance.sh
      timeout: 6000
      runas: root
  AfterInstall:
    - location: scripts/install_os_dependencies.sh
      timeout: 6000
      runas: root
    - location: scripts/install_python_dependencies.sh
      timeout: 6000
      runas: ubuntu
    - location: scripts/migrate.sh
      timeout: 6000
      runas: ubuntu
  ApplicationStart:
    - location: scripts/start_application.sh
      timeout: 6000
      runas: ubuntu
  ApplicationStop:
    - location: scripts/stop_application.sh
      timeout: 6000
      runas: ubuntu

And the stop_application.sh

#!/usr/bin/env bash
cd /home/ubuntu/taptop_web
ps auxw | grep runserver | awk '{print $2}' | xargs kill
like image 390
Adolfo Esparza Avatar asked May 03 '18 00:05

Adolfo Esparza


People also ask

What is AppSpec file in CodeDeploy?

The application specification file (AppSpec file) is a YAML -formatted or JSON-formatted file used by CodeDeploy to manage a deployment. The AppSpec file for an EC2/On-Premises deployment must be named appspec. yml or appspec. yaml , unless you are performing a local deployment.

How do I update AppSpec Yml?

To update your AppSpec fileCopy and paste the Hooks section into your AppSpec file file. Update the ARN after AfterAllowTestTraffic with the ARN of the Lambda function that you noted in Step 3: Create a lifecycle hook Lambda function. Save your AppSpec file and upload to its S3 bucket.

Where should the AppSpec Yml file be stored for CodeDeploy?

Save the file as appspec. yml in the root directory of the revision.

Can we rollback CodeDeploy deployment?

CodeDeploy rolls back deployments by redeploying a previously deployed revision of an application as a new deployment. These rolled-back deployments are technically new deployments, with new deployment IDs, rather than restored versions of a previous deployment. Deployments can be rolled back automatically or manually.


1 Answers

The only thing you need to do to fix your issue is have a successful deployment. It only appears as though it didn't update because when you do the deployment, it will run ApplicationStop from the previous revision. This is often confusing, but it works that way because only a revision should know how to stop its own application - if the stop commands changed between revisions, the new stop command wouldn't work.

That being said, it's not an uncommon issue where customers have a ApplicationStop script that fails due to an issue in the script, so a deployment will keep failing without intervention. If there's your issue, follow this guide to get out of the situation.

like image 156
EmptyArsenal Avatar answered Sep 30 '22 07:09

EmptyArsenal