Daniel Rosewarne Daniel Rosewarne - 4 months ago 12
Ruby Question

Elastic Beanstalk: what's the best way to create folders & set permissions after deploy?

I'm running a Rails 4.2 app on Elastic Beanstalk, and need to set log permissions and create the /tmp/uploads folder (plus permissions) after deploy.

I was running two ebextensions scripts to do this, but on some occasions they would fail because the folder /var/app/current/ didn't yet exist.

I'm presuming this is because the permissions and/or folders should be created on /app/ondeck/ first so that EB can copy the contents over to /var/app/current/, but I'm interested to see if there's a recommended and more foolproof approach to doing this?

For reference, my two ebextension scripts were:

commands:
01_set_log_permissions:
command: "chmod 755 /var/app/current/log/*"


and

commands:
01_create_uploads_folder:
command: "mkdir -p /var/app/current/tmp/uploads/"
02_set_folder_permission:
command: "chmod 755 /var/app/current/tmp/uploads/"


Thanks,
Dan

Answer

you should probably use files tag and not command:

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
    "/opt/elasticbeanstalk/hooks/appdeploy/post/99_make_changes.sh":
    mode: "000777"
    content: |
      #!/bin/bash
      mkdir -p /var/app/current/tmp/uploads/
      chmod 755 /var/app/current/tmp/uploads/

it will be triggered after app deploy finished