Skip to content

Instantly share code, notes, and snippets.

@jonyardley
Last active March 3, 2023 21:12
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jonyardley/47f6bd8847c860f68ed7e0fa463d6d23 to your computer and use it in GitHub Desktop.
Save jonyardley/47f6bd8847c860f68ed7e0fa463d6d23 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