Skip to content

Commit 626f006

Browse files
committed
Upgrade to Rails 8.1
1 parent ff45a0e commit 626f006

32 files changed

+969
-1057
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ updates:
33
- package-ecosystem: bundler
44
directory: "/"
55
schedule:
6-
interval: daily
6+
interval: weekly
77
open-pull-requests-limit: 10
88
- package-ecosystem: github-actions
99
directory: "/"
1010
schedule:
11-
interval: daily
11+
interval: weekly
1212
open-pull-requests-limit: 10

.github/workflows/ci.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v5
1515

1616
- name: Set up Node.js
17-
uses: actions/setup-node@v5
17+
uses: actions/setup-node@v6
1818
with:
1919
node-version: 22
2020
cache: 'npm'
@@ -41,24 +41,37 @@ jobs:
4141
- name: Set up Ruby
4242
uses: ruby/setup-ruby@v1
4343
with:
44-
ruby-version: .ruby-version
4544
bundler-cache: true
4645

4746
- name: Scan for common Rails security vulnerabilities using static analysis
4847
run: bin/brakeman --no-pager
4948

49+
- name: Scan for known security vulnerabilities in gems used
50+
run: bin/bundler-audit
51+
5052
lint:
5153
runs-on: ubuntu-latest
54+
env:
55+
RUBOCOP_CACHE_ROOT: tmp/rubocop
5256
steps:
5357
- name: Checkout code
5458
uses: actions/checkout@v5
5559

5660
- name: Set up Ruby
5761
uses: ruby/setup-ruby@v1
5862
with:
59-
ruby-version: .ruby-version
6063
bundler-cache: true
6164

65+
- name: Prepare RuboCop cache
66+
uses: actions/cache@v4
67+
env:
68+
DEPENDENCIES_HASH: ${{ hashFiles('.ruby-version', '**/.rubocop.yml', '**/.rubocop_todo.yml', 'Gemfile.lock') }}
69+
with:
70+
path: ${{ env.RUBOCOP_CACHE_ROOT }}
71+
key: rubocop-${{ runner.os }}-${{ env.DEPENDENCIES_HASH }}-${{ github.ref_name == github.event.repository.default_branch && github.run_id || 'default' }}
72+
restore-keys: |
73+
rubocop-${{ runner.os }}-${{ env.DEPENDENCIES_HASH }}-
74+
6275
- name: Lint code for consistent style
6376
run: bin/rubocop -f github
6477

@@ -80,7 +93,7 @@ jobs:
8093
uses: actions/checkout@v5
8194

8295
- name: Set up Node.js
83-
uses: actions/setup-node@v5
96+
uses: actions/setup-node@v6
8497
with:
8598
node-version: 22
8699
cache: 'npm'
@@ -91,7 +104,6 @@ jobs:
91104
- name: Set up Ruby
92105
uses: ruby/setup-ruby@v1
93106
with:
94-
ruby-version: .ruby-version
95107
bundler-cache: true
96108

97109
- name: Run tests
@@ -103,7 +115,7 @@ jobs:
103115
run: bin/rails db:test:prepare spec
104116

105117
- name: Keep screenshots from failed system tests
106-
uses: actions/upload-artifact@v4
118+
uses: actions/upload-artifact@v5
107119
if: failure()
108120
with:
109121
name: screenshots

.github/workflows/deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
- name: Set up Ruby
3333
uses: ruby/setup-ruby@v1
3434
with:
35-
ruby-version: .ruby-version
3635
bundler-cache: true
3736

3837
- name: Deploy

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
/public/assets
3232

33-
# Ignore master key for decrypting credentials and more.
34-
/config/master.key
33+
# Ignore key files for decrypting credentials and more.
34+
/config/*.key
3535

3636
# Vite Ruby
3737
/public/vite*

.kamal/secrets

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
# KAMAL_REGISTRY_PASSWORD=$(kamal secrets extract KAMAL_REGISTRY_PASSWORD ${SECRETS})
88
# RAILS_MASTER_KEY=$(kamal secrets extract RAILS_MASTER_KEY ${SECRETS})
99

10+
# Example of extracting secrets from Rails credentials
11+
# KAMAL_REGISTRY_PASSWORD=$(rails credentials:fetch kamal.registry_password)
12+
1013
# Use a GITHUB_TOKEN if private repositories are needed for the image
1114
# GITHUB_TOKEN=$(gh config get -h github.com oauth_token)
1215

1316
# Grab the registry password from ENV
14-
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
17+
# KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
1518

16-
# Grab the master key from ENV
17-
RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
19+
# Improve security by using a password manager. Never check config/master.key into git!
20+
RAILS_MASTER_KEY=$(cat config/master.key)

Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ WORKDIR /rails
1717
# Install base packages
1818
RUN apt-get update -qq && \
1919
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
20+
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
2021
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2122

22-
# Set production environment
23+
# Set production environment variables and enable jemalloc for reduced memory usage and latency.
2324
ENV RAILS_ENV="production" \
2425
BUNDLE_DEPLOYMENT="1" \
2526
BUNDLE_PATH="/usr/local/bundle" \
26-
BUNDLE_WITHOUT="development:test"
27+
BUNDLE_WITHOUT="development:test" \
28+
LD_PRELOAD="/usr/local/lib/libjemalloc.so"
2729

2830
# Throw-away build stage to reduce size of final image
2931
FROM base AS build
@@ -45,7 +47,8 @@ COPY Gemfile Gemfile.lock vendor ./
4547

4648
RUN bundle install && \
4749
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
48-
bundle exec bootsnap precompile --gemfile
50+
# -j 1 disable parallel compilation to avoid a QEMU bug: https://github.com/rails/bootsnap/issues/495
51+
bundle exec bootsnap precompile -j 1 --gemfile
4952

5053
# Install node modules
5154
COPY package.json package-lock.json ./
@@ -55,8 +58,9 @@ RUN npm ci && \
5558
# Copy application code
5659
COPY . .
5760

58-
# Precompile bootsnap code for faster boot times
59-
RUN bundle exec bootsnap precompile app/ lib/
61+
# Precompile bootsnap code for faster boot times.
62+
# -j 1 disable parallel compilation to avoid a QEMU bug: https://github.com/rails/bootsnap/issues/495
63+
RUN bundle exec bootsnap precompile -j 1 app/ lib/
6064

6165
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
6266
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

Dockerfile-ssr

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ WORKDIR /rails
1717
# Install base packages
1818
RUN apt-get update -qq && \
1919
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
20+
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
2021
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2122

2223
# Install JavaScript dependencies
@@ -26,11 +27,12 @@ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz
2627
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
2728
rm -rf /tmp/node-build-master
2829

29-
# Set production environment
30+
# Set production environment variables and enable jemalloc for reduced memory usage and latency.
3031
ENV RAILS_ENV="production" \
3132
BUNDLE_DEPLOYMENT="1" \
3233
BUNDLE_PATH="/usr/local/bundle" \
33-
BUNDLE_WITHOUT="development:test"
34+
BUNDLE_WITHOUT="development:test" \
35+
LD_PRELOAD="/usr/local/lib/libjemalloc.so"
3436

3537
# Throw-away build stage to reduce size of final image
3638
FROM base AS build
@@ -45,7 +47,8 @@ COPY Gemfile Gemfile.lock vendor ./
4547

4648
RUN bundle install && \
4749
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
48-
bundle exec bootsnap precompile --gemfile
50+
# -j 1 disable parallel compilation to avoid a QEMU bug: https://github.com/rails/bootsnap/issues/495
51+
bundle exec bootsnap precompile -j 1 --gemfile
4952

5053
# Install node modules
5154
COPY package.json package-lock.json ./
@@ -55,8 +58,9 @@ RUN npm ci && \
5558
# Copy application code
5659
COPY . .
5760

58-
# Precompile bootsnap code for faster boot times
59-
RUN bundle exec bootsnap precompile app/ lib/
61+
# Precompile bootsnap code for faster boot times.
62+
# -j 1 disable parallel compilation to avoid a QEMU bug: https://github.com/rails/bootsnap/issues/495
63+
RUN bundle exec bootsnap precompile -j 1 app/ lib/
6064

6165
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
6266
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile && \
@@ -71,7 +75,6 @@ FROM base
7175
# Run and own only the runtime files as a non-root user for security
7276
RUN groupadd --system --gid 1000 rails && \
7377
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash
74-
7578
USER 1000:1000
7679

7780
# Copy built artifacts: gems, application

Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source "https://rubygems.org"
44

55
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
6-
gem "rails", "~> 8.0.2"
6+
gem "rails", "~> 8.1.1"
77
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
88
gem "propshaft"
99
# Use sqlite3 as the database for Active Record
@@ -53,6 +53,9 @@ group :development, :test do
5353
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
5454
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
5555

56+
# Audits gems for known security defects (use config/bundler-audit.yml to ignore issues)
57+
gem "bundler-audit", require: false
58+
5659
# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
5760
gem "brakeman", require: false
5861

0 commit comments

Comments
 (0)