Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting directory owner and permission with appspec.yml through Amazon Web Service CodeDeploy

I'm deploying a Node.js application through Codeship using the CodeDeploy AWS deployment system.

I am making use of the appspec.yml file to set the owner and permissions of one of the deployed directory.

I want to allow read/write for any files that will be created in a specified folder of the deployment. Files will be created by the web application once it starts running.

Currently my appspec.yml contains the following:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/APPLICATION_NAME
permissions:
  - object: /var/www/APPLICATION_NAME/tmpfiles
    mode: 644
    owner: ec2-user
    type:
      - directory
like image 950
Peter Bridger Avatar asked Feb 04 '15 11:02

Peter Bridger


People also ask

Where should the AppSpec Yml file be stored for AWS CodeDeploy to function properly?

If your application uses the EC2/On-Premises compute platform, the AppSpec file must be a YAML-formatted file named appspec. yml and it must be placed in the root of the directory structure of an application's source code.

What is destination in AppSpec Yml?

The destination instruction identifies the location on the instance where the files should be copied. This must be a fully qualified path such as /root/destination/directory (on Linux, RHEL, and Ubuntu) or c:\destination\folder (on Windows). source and destination are each specified with a string.

What are hooks used for in CodeDeploy AppSpec file?

Use the 'hooks' section to specify a Lambda function that CodeDeploy can call to validate a Lambda deployment. You can use the same function or a different one for the BeforeAllowTraffic and AfterAllowTraffic deployment lifecyle events.


1 Answers

I found appspec.yml file really hard to deal with.

I have very big and complex folder structure and it's headache to try to set permissions with appspec.yml file. Because of this reason, I make use of "hooks" to call small bash script to set my permissions

Here is an example appspec.yml file that I have:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www
hooks:
  AfterInstall:
    - location: scripts/set-permissions.sh

Here is an example of set-permissions.sh file:

#!/bin/bash
# Set ownership for all folders
chown -R www-data:www-data /var/www/
chown -R root:root /var/www/protected

# set files to 644 [except *.pl *.cgi *.sh]
find /var/www/ -type f -not -name ".pl" -not -name ".cgi" -not -name "*.sh" -print0 | xargs -0 chmod 0644

# set folders to 755
find /var/www/ -type d -print0 | xargs -0 chmod 0755
like image 63
Neutralizer Avatar answered Oct 06 '22 23:10

Neutralizer