eoinoc
eoinoc

Reputation: 3265

Strategy to deploy versioned assets (for PHP app's assets to Amazon S3)

I currently deploy a PHP app's static assets using s3cmd.

If an asset for Amazon S3 has changed (like a JavaScript script), I'll rename it manually, so that the new version is synced and served by Amazon Cloudfront.

Are there documented practices for deploying a PHP app's static assets to Amazon S3? I've seen that sites use a hash to refer to a certain deployment version of their assets. I'm wondering the approach to get that hash (like the git commit SHA?) to be referenced by the web application.

The approach I could see working is writing to a stand-alone config file that holds the current SHA, and read from it for deployment.

Update 1 with current process

I'm looking to make the deployment of assets more automated:

Upvotes: 0

Views: 688

Answers (1)

Noman Ur Rehman
Noman Ur Rehman

Reputation: 6957

I would like to think there is no specific answer to this question but here are a few things.

  1. If you only want to automate the manual work you are doing then it might be worthwhile to look into a few deployment tools. Capistrano and Magallanes are two names that come to my mind but you can google for this and I am sure you will find a lot of options.

  2. The Rails framework was built on the philosophy that there is a best way to do things. It also uses hashes to version static assets and does its thing out of the box on the fly. You can look into implementing hashing in your case.

  3. Grunt is another automation tool that you can look into. I found this module that might come in handy https://github.com/theasta/grunt-assets-versioning

I would say for me, the 2,3,4 are the problem areas in your workflow. Renaming manually and updating code every time does not sound too nice. As you have pointed out, GIT hashes are unique so perhaps append the GIT hash to your assets during deployment and sync them to S3/Cloudfront ?

Upvotes: 1

Related Questions