Last active
March 3, 2023 21:12
-
-
Save jonyardley/47f6bd8847c860f68ed7e0fa463d6d23 to your computer and use it in GitHub Desktop.
Precompile Ruby on Rails assets with Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker build --build-arg="ASSET_HOST=http://mycdn/path-to-assets" . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG ASSET_HOST | |
RUN bundle exec rake ASSET_HOST=${ASSET_HOST} RAILS_ENV=production assets:precompile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable serving of images, stylesheets, and JavaScripts from an asset server. | |
config.action_controller.asset_host = ENV['ASSET_HOST'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p rails_assets | |
id=$(docker create <my_image_with_assets>) | |
docker cp $id:/app/public/assets rails_assets | |
aws s3 cp --recursive rails_assets/ s3://<my_s3_bucket_name> --cache-control max-age=604800 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment