I'm in the process of moving my website to Amazon AWS, which has a raised an essential question regarding deployment.
I'm running a S3 and EC2 instance. The S3 instance is serving all static content like images, JavaScript, and CSS. On the EC2 instance, however, I have initiated a Git repository in /var/www/ so that I can do a "git pull" when I want to update my code base.
I can't seem to find a solution as to how I make sure I upload the static content and code at the same time so that it will be completely seamless. Let's say I want to update the logo and the layout of the front page. When I upload logo.png to S3 my current code base on EC2 will automatically point to the new logo even though the new layout haven't been deployed.
Should I upload logo.png under a new name (for instance logo-2.png) on S3, update all references to logo.png in my HTML to logo-2.png and then deploy it?
I hope you understand--thank you!
Use a third step to do your deploys, like a Jenkins or a Springloops or maybe a rake.
That way, both of your build steps can be triggered simultaneously from one commit.
Yes you should definitely names your S3 files somehow, for example my files have the current git commit hash in them: minified..css. Whatever tool you're using to do builds, do the S3 step first and then the application code after.
This is especially important because people will cache the old files in their browser cache and they'll get the old versions.
I do not namespace all my files like logo.gif. That file never changes and if it ever did, I would manually add logo.gif?v=1
To do the stuff above, I just setup a simple node script that uses Rsync and Knox.
I open sourced my dev tool here if you're interested. It's pretty specific to my use case but you can pick it apart.
I also recommend using cloudfront to pull from your S3. Cloudfront is hella fast and only take fifteen minutes to set up. Lastly don't forget to gzip and using Expired headers on these assets.
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