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
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With