How do you call db:seed on AWS Elastic Beanstalk apps?

后端 未结 5 709
挽巷
挽巷 2021-02-07 14:18

I know that you can run tasks as part of each deploy, but I only want to bootstrap the database once.

5条回答
  •  暖寄归人
    2021-02-07 14:40

    to do commands on your elastic beanstalk instance, you can setup custom commands configurations that will get run when you do update your application. (In fact, there is a whole docs page dedicated to the different types of container commands you can do).

    1. if you don't already have an .ebextensions directory in the root of your application, create one.
    2. any file you put in here will be run. name it whatever you want as long as it ends with ".config" -- I arbitrarily named mine seed.config
    3. borrowing from what hfogel wrote, you can put something in there like this:

      container_commands:
        01seed:
          command: rake db:seed
      
    4. add this new code to your repo: git add . then git commit -m 'added seed config script' then git push

    5. then push this new code to your aws eb instance(s): git aws.push

    To verify that your command actually ran, go into your elastic beanstalk console and expand the details for your environment, and navigate to the logs tab, and refresh your logs and view them. Inside there, simply do a ctrl + f for "seed" until you see your seed command was run. If you don't see it in there somewhere, then it didn't run.

提交回复
热议问题