Skip to content

Commit

Permalink
No build is faster than any build
Browse files Browse the repository at this point in the history
* Dockerize application
* Replace SASS with pure CSS
* Remove JS via node with importmap
* Fix UI issues on admin modal
* Upgrade simple-form to boostrap 5
  • Loading branch information
gmmcal committed Oct 14, 2023
1 parent 3595e10 commit 49ac17d
Show file tree
Hide file tree
Showing 124 changed files with 20,334 additions and 1,184 deletions.
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.

# Ignore git directory.
/.git/

# Ignore bundler config.
/.bundle

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

# Ignore all default key files.
/config/master.key
/config/credentials/*.key

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/.keep

# Ignore assets.
/node_modules/
/app/assets/builds/*
!/app/assets/builds/.keep
/public/assets
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.rbc
capybara-*.html
/log
/tmp
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
/db/*.sqlite3
/public/system
/public/assets
Expand Down
98 changes: 98 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV BUNDLE_PATH="/usr/local/bundle"

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

# Install packages needed to build gems and node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3

# Install JavaScript dependencies
ARG NODE_VERSION=18.12.1
ARG YARN_VERSION=1.22.19
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
npm install -g yarn@$YARN_VERSION && \
rm -rf /tmp/node-build-master

# 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

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

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

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

# Development image
FROM base as development

ENV RAILS_ENV="development"

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libvips postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

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

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

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server", "-b", "0.0.0.0"]

# Backend Test image
FROM base as test

ENV RAILS_ENV="test"

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libvips postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

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

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

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["bundle", "exec", "rspec"]
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ gem 'rails', '~> 7.1.1'
# Frontend gems
gem 'draper'
# Use SCSS for stylesheets
gem 'cssbundling-rails'
gem 'jsbundling-rails'
gem 'importmap-rails'
gem 'sprockets-rails'
gem 'uglifier'
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

Expand Down
14 changes: 4 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ GEM
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
cssbundling-rails (1.3.3)
railties (>= 6.0.0)
cypress-on-rails (1.16.0)
rack
database_cleaner (2.0.2)
Expand Down Expand Up @@ -118,7 +116,6 @@ GEM
drb (2.1.1)
ruby2_keywords
erubi (1.12.0)
execjs (2.8.1)
factory_bot (6.2.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.2.0)
Expand All @@ -131,12 +128,13 @@ GEM
activesupport (>= 6.1)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
importmap-rails (1.2.1)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.6.0)
irb (1.8.1)
rdoc
reline (>= 0.3.8)
jsbundling-rails (1.2.1)
railties (>= 6.0.0)
json (2.6.3)
kramdown (2.4.0)
rexml
Expand Down Expand Up @@ -327,8 +325,6 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.5.0)
warden (1.2.9)
rack (>= 2.0.9)
Expand All @@ -347,14 +343,13 @@ PLATFORMS
DEPENDENCIES
bootsnap
brakeman
cssbundling-rails
cypress-on-rails
database_cleaner
devise
draper
factory_bot_rails
faker
jsbundling-rails
importmap-rails
kramdown
listen
pg
Expand All @@ -374,7 +369,6 @@ DEPENDENCIES
simplecov
sprockets-rails
turbo-rails
uglifier
wicked_pdf
wkhtmltopdf-binary

Expand Down
9 changes: 4 additions & 5 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//= link application.css
//= link admin/application.css
//= link cv/application.css
//= link favicon.ico
//= link_tree ../images
//= link_tree ../builds
//= link_directory ../stylesheets .css
//= link_directory ../stylesheets/admin .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ $h4-font-size: $font-size-base * 1.5 !default;
$h5-font-size: $font-size-base * 1.25 !default;
$h6-font-size: $font-size-base !default;

$headings-margin-bottom: ($spacer / 2) !default;
$headings-margin-bottom: calc($spacer / 2) !default;
$headings-font-family: inherit !default;
$headings-font-weight: 500 !default;
$headings-line-height: 1.2 !default;
Expand Down Expand Up @@ -637,11 +637,11 @@ $nav-pills-link-active-color: $component-active-color !default;
$nav-pills-link-active-bg: $component-active-bg !default;

$nav-divider-color: $gray-200 !default;
$nav-divider-margin-y: ($spacer / 2) !default;
$nav-divider-margin-y: calc($spacer / 2) !default;

// Navbar

$navbar-padding-y: ($spacer / 2) !default;
$navbar-padding-y: calc($spacer / 2) !default;
$navbar-padding-x: $spacer !default;

$navbar-nav-link-padding-x: .5rem !default;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions app/assets/scss/frontend/tailwind.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
Loading

0 comments on commit 49ac17d

Please sign in to comment.