Skip to content

Instantly share code, notes, and snippets.

@manzhikov
Forked from jonyardley/Dockerfile
Created March 30, 2022 01:54
Show Gist options
  • Save manzhikov/f86e5a4157df944f3585b0f5a7bdf0f7 to your computer and use it in GitHub Desktop.
Save manzhikov/f86e5a4157df944f3585b0f5a7bdf0f7 to your computer and use it in GitHub Desktop.
Precompile Ruby on Rails assets with Docker
docker build --build-arg="ASSET_HOST=http://mycdn/path-to-assets" .
ARG ASSET_HOST
RUN bundle exec rake ASSET_HOST=${ASSET_HOST} RAILS_ENV=production assets:precompile
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
config.action_controller.asset_host = ENV['ASSET_HOST']
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