Skip to content

Commit

Permalink
Upgrade to rails 8
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Nov 12, 2024
1 parent 165144f commit eb75159
Show file tree
Hide file tree
Showing 85 changed files with 2,979 additions and 5,733 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
# Ignore bundler config.
/.bundle

# Ignore all environment files (except templates).
# Ignore all environment files.
/.env*
!/.env*.erb

# Ignore all default key files.
/config/master.key
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ jobs:
- name: Scan for common Rails security vulnerabilities using static analysis
run: bin/brakeman --no-pager

scan_js:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Scan for security vulnerabilities in JavaScript dependencies
run: bin/importmap audit

lint:
runs-on: ubuntu-latest
steps:
Expand Down
25 changes: 15 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
# Ignore bundler config.
/.bundle

# Ignore all environment files (except templates).
# Ignore all environment files.
/.env*
!/.env*.erb

# Ignore all logfiles and tempfiles.
/log/*
Expand All @@ -34,20 +33,26 @@
# Ignore master key for decrypting credentials and more.
/config/master.key

/app/assets/builds/*
!/app/assets/builds/.keep

/node_modules

##################
# Our Stuff
##################

/vendor/bundle

# solr
/solr/data
/solr/test/data
/solr/development/data
/solr/default/data
/solr/production/data
/solr/staging/data
/solr/pids
# Yarn v4
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
**/.yarn/install-state.gz

#sorbet
# They recommend you commit these but I'm not convinced
Expand Down
1 change: 1 addition & 0 deletions .node_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.11.1
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
61 changes: 43 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# syntax = docker/dockerfile:1.7-labs
# syntax=docker/dockerfile:1.7-labs
## NOTE: Above so we can use exclude
# check=error=true

# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
# docker build -t my-app .
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
# docker build -t nabu .
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name nabu nabu

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG RUBY_VERSION=3.2.2
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base

Expand All @@ -17,29 +20,47 @@ WORKDIR /rails

# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl default-mysql-client libjemalloc2 libvips && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
apt-get install --no-install-recommends -y curl default-mysql-client libjemalloc2 libvips && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development:test"
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development:test"
# Unlike dhh we don;t think this image wil be used for CI

# Throw-away build stage to reduce size of final image
FROM base AS build

# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential default-libmysqlclient-dev git pkg-config && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
apt-get install --no-install-recommends -y build-essential default-libmysqlclient-dev git pkg-config && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

ENV NODE_VERSION=22.11.0
ENV NVM_DIR /usr/local/nvm
RUN mkdir -p $NVM_DIR
# Setup node
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash && \
. $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default && \
corepack enable

ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile

# Install node modules
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Copy application code
COPY . .
Expand All @@ -51,7 +72,11 @@ RUN echo $GIT_SHA > REVISION
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN ASSET_PRECOMPILE=1 SECRET_KEY_BASE_DUMMY=1 NABU_CATALOG_BUCKET=dummy ./bin/rails assets:precompile
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

RUN rm -rf node_modules



# Final stage for app image
FROM base
Expand All @@ -62,13 +87,13 @@ COPY --from=build --exclude=tmp/cache/* --exclude=vendor/bundle /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
USER 1000:1000

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
# Start server via Thruster by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server", "--log-to-stdout"]
CMD ["./bin/rails", "server", "--log-to-stdout", "-b", "0.0.0.0"]
44 changes: 25 additions & 19 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
source 'https://rubygems.org'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'rails', '~> 7.2.0'
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem 'sprockets-rails'
gem 'rails', '~> 8.0.0'
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
gem 'propshaft'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.5'
# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '>= 5.0'
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem 'importmap-rails'
# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
gem 'jsbundling-rails'
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem 'turbo-rails'
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem 'stimulus-rails'
# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
gem "cssbundling-rails"

Check failure on line 18 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"
# Use Redis adapter to run Action Cable in production
# gem "redis", ">= 4.0.1"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[ windows jruby ]

# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
gem 'solid_cache'
gem 'solid_queue'
gem 'solid_cable'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false

# Deploy this application anywhere as a Docker container [https://kamal-deploy.org]
gem 'kamal', require: false

# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
gem 'thruster', require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-ge
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'debug', platforms: %i[ mri windows ], require: 'debug/prelude'

# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
Expand All @@ -60,15 +68,10 @@ end
# Our stuff
###################

gem 'solid_queue' # New queue system coming to Rails 8
# TODO: Remove the version when we upgrade to Rails 8
gem 'mission_control-jobs', '0.3.1' # Admin backend for jobs

# Needs to be as early as possible to do it's job
gem 'dotenv-rails', require: 'dotenv/load' # , groups: [:development, :test] # Load env variables in dev

# Views
gem 'sassc-rails' # Need this till we ditch blueprint?
gem 'haml-rails', '~> 2.0' # We use HAML for templates instead of erb
gem 'jb' # for json templates, simpler and faster than jbuilder
gem 'kaminari' # Pagination
Expand All @@ -93,10 +96,13 @@ gem 'paper_trail' # Keep an audit trail of all the changes
gem 'aws-sdk-rails' # Send emails via SES
gem 'aws-sdk-s3' # Talk to the catalog

# Frameworks
# Admin Dashboard
gem 'activeadmin'
gem 'country_select', '~> 8.0' # 9.0 breaks active admin
gem 'graphiql-rails', '1.8.0' # https://github.com/rmosolgo/graphiql-rails/issues/106
gem 'mission_control-jobs' # Jobs dashboard
gem 'country_select' # , '~> 8.0' # 9.0 breaks active admin

# Graphql
gem 'graphiql-rails' # , '1.8.0' # https://github.com/rmosolgo/graphiql-rails/issues/106
gem 'graphql'

# Search
Expand Down
Loading

0 comments on commit eb75159

Please sign in to comment.