Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk run post deploy script

My node.js app consists of two things, an express backend and a react frontend.

I have two package.json files in this structure

package.json 
/app/package.json

What I want to do is run a script in my frontend folder, app, that builds my code.

the script I want to run is npm install and npm run build How do I run this script after a deploy have happened?

commands:
    01_app_npm_install:
        command: npm install
        cwd: app/
    02_app_npm_build:
        command: npm run build
        cwd: app/

But it returns an error saying that "No such file or direc tory: 'app/'."

Is this possible to do on aws elastic beanstalk?

like image 876
auo Avatar asked Nov 23 '16 12:11

auo


1 Answers

Update: This is now much more developed and defined.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html

Original:

I haven't done nodejs myself with Elastic Beanstalk, but I have done a lot of Django.

The commands: section runs before the project files are put in place. This is where you can install server packages for example.

The container_commands: section runs in a staging directory before the files are put in its final destination (which is /var/app/current it seems for nodejs). Here you can modify your files if you need to.

Reference for above: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

You can also run a post deploy scripts. This is not very well documented (at least it wasn't). You can do something like this:

files:
    "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh":
        mode: "000755"
        owner: root
        group: root
        content: |
            #!/usr/bin/env bash
            service httpd restart
like image 149
Gustaf Avatar answered Sep 25 '22 20:09

Gustaf