Helps you optimize images stored on S3 and invalidate cloudfront cache. Do read the tips section might just be helpful
-
ruby 2.2.x
-
App is hardcoded to only work with JPEG & JPG. It can be easily modified to work with other formats. You will need to refer to image-optim[github.com/toy/image_optim] gem to understand how.
-
The expires header has been hardcoded to 10 years.
-
It adds a header to the image to mark as optimized. Header name can be changed by setting environment variable AWS_IMAGE_METATAG
Initalize following environment variables
-
AWS_REGION
-
AWS_BUCKET
-
AWS_CLOUDFRONT_DISTRIBUTION_ID
-
AWS_SECRET_ACCESS_KEY
-
AWS_ACCESS_KEY_ID
-
AWS_IMAGE_ACL # default - public-read reference S3 Canned ACL
-
AWS_IMAGE_METATAG # default - img_optim reference S3 User-Defined Metadata
-
AWS_IMAGE_CACHE_CONTROL # default - max-age=315576000 reference Cache Control
-
IMAGE_OPT_DATABASE
-
IMAGE_OPT_DATABASE_USERNAME
-
IMAGE_OPT_DATABASE_PASSWORD
-
IMAGE_OPT_DATABASE_HOST
-
bundle install
-
add your Active Job queue adapter (options Sidekiq, Resque, Delayed Job etc)
-
Start rails c
-
Add paths within your s3 bucket that you want to optimize
-
Start your active job queue worker
DirPath.create(:path => 'myfolder/', :invalidate_cloudfront => true) # '/' Character is mandatory after folder name
Current instance is built around postgres but can easily work with any other relational database (mysql, sqlite etc)
mysql - mysql2 gem requires lmysqlclient-dev package
postgres - pg gem requires libpq-dev package
-
Feel free to fork the repo
-
Want something changed, submit a pull request
-
Problem with the app post an issue
-
Run it in a EC2 instance in the same region as your s3 instance - Will save cost and give quick responses.
-
Prefer keeping the number of jobs equivalent to the number of processors in an EC2 instance. # Can’t explain low level OS Stuff.
-
Prefer using postgres. Optimizing in postgres is far simpler than mysql at least for me. FYI I am a noob when it comes to databases.