Skip to content

Commit 74ef4d9

Browse files
committed
Moved CSS pipeline to postcss
The production setup included all CSS files directly and this resulted in broken links and lots of 404 requests to our server. This new approach compacts everything into a single css file and everything should work better.
1 parent 44c7166 commit 74ef4d9

File tree

16 files changed

+1196
-10
lines changed

16 files changed

+1196
-10
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ jobs:
3939
- name: Install dependencies
4040
run: |
4141
sudo apt-get update -qq
42-
sudo apt-get install -y build-essential libpq-dev pkg-config
42+
sudo apt-get install -y build-essential libpq-dev pkg-config nodejs npm
43+
NPM_CONFIG_PRODUCTION=false npm ci --production=false
44+
npm run build:css
4345
4446
- name: Prepare database
4547
run: bin/rails db:prepare

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@
3636

3737
.claude
3838
CLAUDE.md
39+
40+
/app/assets/builds/*
41+
!/app/assets/builds/.keep
42+
43+
/node_modules

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ FROM ruby:${RUBY_VERSION} AS base
55

66
ENV BUNDLE_WITHOUT="development:test" \
77
RAILS_ENV=production \
8-
NODE_ENV=production
8+
NODE_ENV=production \
9+
NPM_CONFIG_PRODUCTION=false
910

1011
RUN apt-get update -qq && \
11-
apt-get install -y --no-install-recommends build-essential libpq-dev git curl && \
12+
apt-get install -y --no-install-recommends build-essential libpq-dev git curl nodejs npm && \
1213
rm -rf /var/lib/apt/lists/*
1314

1415
WORKDIR /app
@@ -18,6 +19,9 @@ RUN bundle install --jobs=4 --retry=3
1819

1920
COPY . .
2021

22+
# Install JS deps including devDependencies for the PostCSS build, then build CSS.
23+
RUN npm ci --production=false && \
24+
npm run build:css
2125
RUN SECRET_KEY_BASE=dummy bundle exec rails assets:precompile
2226

2327
FROM ruby:${RUBY_VERSION}-slim AS final

Dockerfile.dev

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV RAILS_ENV=development \
66
BUNDLE_WITHOUT=""
77

88
RUN apt-get update -qq && \
9-
apt-get install -y --no-install-recommends build-essential libpq-dev git curl && \
9+
apt-get install -y --no-install-recommends build-essential libpq-dev git curl nodejs npm && \
1010
rm -rf /var/lib/apt/lists/*
1111

1212
WORKDIR /app
@@ -16,6 +16,9 @@ RUN bundle install --jobs=4 --retry=3
1616

1717
COPY . .
1818

19+
# Install JS dependencies so dev server can run the CSS watcher; actual CSS is rebuilt by bin/dev/foreman.
20+
RUN npm install
21+
1922
EXPOSE 3000
2023

2124
ENTRYPOINT ["./bin/docker-entrypoint"]

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ source "https://rubygems.org"
44
gem "rails", "~> 8.0.2"
55
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
66
gem "propshaft"
7+
gem "cssbundling-rails"
78
# Use postgresql as the database for Active Record
89
gem "pg", "~> 1.1"
910
# PostgreSQL-specific ActiveRecord extensions (UNION, CTE, etc.)

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ GEM
106106
concurrent-ruby (1.3.5)
107107
connection_pool (3.0.2)
108108
crass (1.0.6)
109+
cssbundling-rails (1.4.3)
110+
railties (>= 6.0.0)
109111
date (3.5.0)
110112
debug (1.11.0)
111113
irb (~> 1.10)
@@ -481,6 +483,7 @@ DEPENDENCIES
481483
brakeman
482484
bullet
483485
capybara
486+
cssbundling-rails
484487
debug
485488
factory_bot_rails
486489
faker

Procfile.dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: env RUBY_DEBUG_OPEN=true bin/rails server -b ${HOST:-127.0.0.1} -p ${PORT:-3000}
2+
css: yarn build:css --watch

app/assets/stylesheets/application.css renamed to app/assets/stylesheets/application.postcss.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
@import "components/form.css";
1111
@import "components/navigation.css";
1212
@import "components/sidebar.css";
13-
@import "components/search.css";
1413
@import "components/topics.css";
1514
@import "components/avatars.css";
1615
@import "components/participants.css";

app/views/layouts/application.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ html data-theme="light"
2121
var theme = stored || (prefersDark ? 'dark' : 'light');
2222
document.documentElement.dataset.theme = theme;
2323
})();
24-
= stylesheet_link_tag :app, "data-turbo-track": "reload"
24+
= stylesheet_link_tag "application", "data-turbo-track": "reload"
2525
= javascript_importmap_tags
2626
script[src="https://kit.fontawesome.com/92fb6aa8ba.js"]
2727
body

bin/dev

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
#!/usr/bin/env ruby
2-
exec "./bin/rails", "server", *ARGV
1+
#!/usr/bin/env sh
2+
3+
if gem list --no-installed --exact --silent foreman; then
4+
echo "Installing foreman..."
5+
gem install foreman
6+
fi
7+
8+
# Default to port 3000 if not specified
9+
export PORT="${PORT:-3000}"
10+
11+
exec foreman start -f Procfile.dev --env /dev/null "$@"

0 commit comments

Comments
 (0)