Skip to content

Commit

Permalink
fix: Package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarMWarraich committed Jul 25, 2024
1 parent 0d24b17 commit 2afbb91
Show file tree
Hide file tree
Showing 23 changed files with 20,942 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
/config/master.key

/config/credentials/development.key
node_modules
28 changes: 15 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,32 @@ ENV RAILS_ENV="production" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"


# 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
apt-get install --no-install-recommends -y build-essential curl git libvips node-gyp pkg-config python-is-python3

# Install JavaScript dependencies
ARG NODE_VERSION=20.11.1
ARG YARN_VERSION=1.22.22
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 if package.json is present
# Install node modules
COPY package.json yarn.lock ./
RUN if [ -f package.json ]; then \
curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "21.5.0" /usr/local/node && \
npm install -g [email protected] && \
yarn install --frozen-lockfile && \
rm -rf /tmp/node-build-master; \
fi
RUN yarn install --frozen-lockfile

# Copy application code
COPY . .
Expand All @@ -45,21 +49,19 @@ 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


# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libvips postgresql-client && \
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
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

# Ensure mini_racer is installed for ExecJS
RUN gem install mini_racer

# 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 storage tmp
Expand Down
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ 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"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

Expand Down Expand Up @@ -82,5 +85,3 @@ gem "sidekiq"
gem "ruby-vips", "~> 2.2"

gem "stripe", "~> 12.3"

gem "mini_racer"
7 changes: 3 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ GEM
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crass (1.0.6)
cssbundling-rails (1.4.0)
railties (>= 6.0.0)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
Expand Down Expand Up @@ -158,7 +160,6 @@ GEM
childprocess (~> 5.0)
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
libv8-node (21.7.2.0-x86_64-linux)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
Expand All @@ -172,8 +173,6 @@ GEM
matrix (0.4.2)
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_racer (0.12.0)
libv8-node (~> 21.7.2.0)
minitest (5.24.0)
msgpack (1.7.2)
mutex_m (0.2.0)
Expand Down Expand Up @@ -330,14 +329,14 @@ DEPENDENCIES
bootsnap
bootstrap (~> 5.3)
capybara
cssbundling-rails
debug
dotenv-rails (~> 2.8)
font-awesome-sass (~> 5.15.1)
image_processing (~> 1.2)
importmap-rails
jbuilder
letter_opener
mini_racer
pg (~> 1.1)
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.4)
Expand Down
3 changes: 3 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
css: yarn watch:css
sidekiq: bundle exec sidekiq -c 3
Empty file added app/assets/builds/.keep
Empty file.
Loading

0 comments on commit 2afbb91

Please sign in to comment.