Deploying Gastropoda to Amazon Web Services - Never Forget

After my last blog post I decided that it was time to deploy Gastropoda to Amazon Web Services - namely Elastic Beanstalk, which utilizes an EC2 instance (reserved) and an RDS DB instance.

I started last Saturday. I’ve just now gotten something running that seems on par with what I have on my vagrant box. I have decided to put together a post of random tips for myself so that I never have to go through this nightmare again the next time I have to set up a new Elastic Beanstalk app or environment.

I started off mostly following these very helpful Laravel deployment instructions. These set me off on the right track, but there were so many obstacles that I ran into that just following this wasn’t really enough.

So…notes.

Differences from instructions above

$env = $app->detectEnvironment(array(

	'local' => array('homestead'),
	'development' => array('hostnamehere'),

));

{:lang=“php”}

container_commands:
   01migrateSeed:
      command: "php artisan migrate --env=development --force"
   02seed:
      command: "php artisan db:seed --force"

Migrating and Seeding Database

class RaceTerrainTableSeeder extends Seeder {

    public function run()
    {
        DB::table('race_terrains')->delete();

        $statement = "
                        ALTER TABLE race_terrains AUTO_INCREMENT = 1;
                    ";
        DB::unprepared($statement);

        DB::table('race_terrains')->insert(array(
        		array(
        			'name' => 'Plastic Tabletop',
        			'description' => 'A smooth, plastic tabletop - lightly misted with water'  			
        		)
        	)     		    
        );
    }
}

{:lang=“php”}

The $statement above is very important. Before I added this, the auto-incremeneted primary key would keep counting up from the previous batch each time I deployed a new version of the app. This broke everything, since I had code and other tables referring specifically to various IDs. This makes sure the IDs increment back from 1 each time the table is seeded.

Cron job

container_commands:
   01optimize:
      command: "/usr/bin/composer.phar dump-autoload --optimize"
   02dispatcher:
      command: "cat .ebextensions/dispatcherJob.txt > /etc/cron.d/dispatcherJob && chmod 644 /etc/cron.d/dispatcherJob"
      leader_only: true
* * * * * root /usr/bin/php /var/www/html/artisan scheduled:run > /dev/null

Logs and Storage

   03chmodStorage:
      command: sudo chmod -R 777 /var/www/html/app/storage

More most likely to come…

comments powered by Disqus