1
0
Fork 0
forked from OpenNeo/impress

Precompile assets when deploying new version

I did some refactoring while here too, of pulling the deploy scripts out of `package.json` and into `bin`, to be a bit more canonically Rails-y. (idk how canonical the colon thing is but, probably fine??)
This commit is contained in:
Emi Matchu 2023-08-19 18:51:46 -07:00
parent 4ddcb005ea
commit 9b68e982e7
12 changed files with 31 additions and 8 deletions

View file

@ -17,7 +17,7 @@ gem 'dotenv-rails', '~> 2.8', '>= 2.8.1'
gem 'haml', '~> 6.1', '>= 6.1.1' gem 'haml', '~> 6.1', '>= 6.1.1'
gem 'sass-rails', '~> 5.0', '>= 5.0.7' gem 'sass-rails', '~> 5.0', '>= 5.0.7'
gem 'compass-rails', '~> 3.1' gem 'compass-rails', '~> 3.1'
gem 'uglifier', '~> 4.2' gem 'terser', '~> 1.1', '>= 1.1.17'
gem 'react-rails', '~> 2.7', '>= 2.7.1' gem 'react-rails', '~> 2.7', '>= 2.7.1'
gem 'jsbundling-rails', '~> 1.1' gem 'jsbundling-rails', '~> 1.1'

View file

@ -293,13 +293,13 @@ GEM
activesupport (>= 5.2) activesupport (>= 5.2)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
temple (0.8.2) temple (0.8.2)
terser (1.1.17)
execjs (>= 0.3.0, < 3)
thor (1.2.2) thor (1.2.2)
tilt (2.2.0) tilt (2.2.0)
timeout (0.4.0) timeout (0.4.0)
tzinfo (2.0.6) tzinfo (2.0.6)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.8.2) unf_ext (0.0.8.2)
@ -348,7 +348,7 @@ DEPENDENCIES
rvm-capistrano (~> 1.5.6) rvm-capistrano (~> 1.5.6)
sanitize (~> 6.0, >= 6.0.2) sanitize (~> 6.0, >= 6.0.2)
sass-rails (~> 5.0, >= 5.0.7) sass-rails (~> 5.0, >= 5.0.7)
uglifier (~> 4.2) terser (~> 1.1, >= 1.1.17)
web-console (~> 4.2) web-console (~> 4.2)
will_paginate (~> 4.0) will_paginate (~> 4.0)

4
bin/deploy Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Deploy a new version to production, using the Ansible playbook in `deploy/deploy.yml`.
$(dirname $0)/deploy:precompile && \
$(dirname $0)/deploy:push

3
bin/deploy:precompile Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
# Precompile the assets for production.
RAILS_ENV=production $(dirname $0)/rails assets:precompile

4
bin/deploy:push Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Deploy a new version to production, using the Ansible playbook in `deploy/deploy.yml`.
# This skips the build step that normally runs when you just call `bin/deploy`.
ansible-playbook -i deploy/inventory.cfg deploy/deploy.yml

4
bin/deploy:setup Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Set up the deployment environment, using the Ansible playbook in `deploy/setup.yml`.
echo $'Setup requires you to become the root user. You\'ll need to enter the password for your account on the remote web server below, and you must be part of the `sudo` user group.'
ansible-playbook -K -i deploy/inventory.cfg deploy/setup.yml

View file

@ -58,6 +58,13 @@ Rails.application.configure do
config.react.variant = :development config.react.variant = :development
# Don't use the assets precompiled for production; recompile live instead.
# HACK: We do this by just telling it that dev assets belong in a special
# folder, so if you run precompile in development it'll look there instead,
# as recommended by the Rails guide. But I don't actually use that irl!
# https://guides.rubyonrails.org/v7.0.7/asset_pipeline.html#local-precompilation
config.assets.prefix = "/dev-assets"
# Fix file reloading in a Vagrant environment. # Fix file reloading in a Vagrant environment.
# The `ActiveSupport::EventedFileUpdateChecker` is faster, but doesn't work # The `ActiveSupport::EventedFileUpdateChecker` is faster, but doesn't work
# correctly for Vagrant's networked folders! # correctly for Vagrant's networked folders!

View file

@ -52,7 +52,7 @@ Rails.application.configure do
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS. # Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier config.assets.js_compressor = :terser
# Don't fallback to assets pipeline if a precompiled asset is missed # Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false config.assets.compile = false

View file

@ -27,11 +27,14 @@
path: "{{ remote_app_root }}" path: "{{ remote_app_root }}"
state: directory state: directory
# NOTE: We skip most gitignored files, except for public/assets/*, which
# contains the assets we precompiled for production.
- name: Copy local app's source files to new remote folder - name: Copy local app's source files to new remote folder
ansible.posix.synchronize: ansible.posix.synchronize:
src: "{{ local_app_root }}/" src: "{{ local_app_root }}/"
dest: "{{ remote_app_root }}" dest: "{{ remote_app_root }}"
rsync_opts: rsync_opts:
- "--include=/public/assets/*"
- "--exclude=.git" - "--exclude=.git"
- "--filter=':- .gitignore'" - "--filter=':- .gitignore'"

View file

@ -28,8 +28,6 @@
}, },
"scripts": { "scripts": {
"build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=/assets --loader:.js=jsx --loader:.png=file --loader:.svg=file --loader:.min.js=text", "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=/assets --loader:.js=jsx --loader:.png=file --loader:.svg=file --loader:.min.js=text",
"build:production": "yarn build --minify", "build:production": "yarn build --minify"
"deploy:setup": "echo $'Setup requires you to become the root user. You\\'ll need to enter the password for your account on the remote web server below, and you must be part of the `sudo` user group.' && ansible-playbook -K -i deploy/inventory.cfg deploy/setup.yml",
"deploy": "ansible-playbook -i deploy/inventory.cfg deploy/deploy.yml"
} }
} }

BIN
vendor/cache/terser-1.1.17.gem vendored Normal file

Binary file not shown.

Binary file not shown.