diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f97ef7f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,77 @@ +# syntax = docker/dockerfile:1 + +# Note: This Dockerfile is optimized for production deployment and isn't a good base +# for development enviroments. + +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version +ARG RUBY_VERSION=3.3.1 +FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base + +# Rails app lives here +WORKDIR /rails + +# Install base packages +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client + +# Set production environment +ENV RAILS_ENV="production" \ + BUNDLE_DEPLOYMENT="1" \ + 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 +RUN apt-get install --no-install-recommends -y build-essential git libpq-dev pkg-config unzip + +ENV BUN_INSTALL=/usr/local/bun +ENV PATH=/usr/local/bun/bin:$PATH +ARG BUN_VERSION=1.1.8 +RUN curl -fsSL https://bun.sh/install | bash -s -- "bun-v${BUN_VERSION}" + +# 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 bun.lockb ./ +RUN bun 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 + + + + +# Final stage for app image +FROM base + +# Clean up installation packages to reduce image size +RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Copy built artifacts: gems, application +COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" +COPY --from=build /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 +USER 1000:1000 + +# 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"] diff --git a/Gemfile.lock b/Gemfile.lock index d50212d..9749af6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -86,7 +86,7 @@ GEM erubi (~> 1.4) parser (>= 2.4) smart_properties - bigdecimal (3.1.7) + bigdecimal (3.1.8) bindex (0.8.1) bootsnap (1.18.3) msgpack (~> 1.2) @@ -104,7 +104,7 @@ GEM debug (1.9.2) irb (~> 1.10) reline (>= 0.3.8) - dotenv (3.1.1) + dotenv (3.1.2) drb (2.2.1) dry-cli (1.0.0) erb_lint (0.5.0) @@ -128,7 +128,7 @@ GEM raabro (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.4) + i18n (1.14.5) concurrent-ruby (~> 1.0) io-console (0.7.2) irb (1.13.1) @@ -157,7 +157,7 @@ GEM minitest (5.22.3) msgpack (1.7.2) mutex_m (0.2.0) - net-imap (0.4.10) + net-imap (0.4.11) date net-protocol net-pop (0.1.2) @@ -166,7 +166,7 @@ GEM timeout net-smtp (0.5.0) net-protocol - nio4r (2.7.1) + nio4r (2.7.3) nokogiri (1.16.4-aarch64-linux) racc (~> 1.4) nokogiri (1.16.4-arm-linux) @@ -191,7 +191,7 @@ GEM nio4r (~> 2.0) raabro (1.4.0) racc (1.7.3) - rack (3.0.10) + rack (3.0.11) rack-proxy (0.7.7) rack rack-session (2.0.0) @@ -235,10 +235,10 @@ GEM rdoc (6.6.3.1) psych (>= 4.0.0) regexp_parser (2.9.0) - reline (0.5.5) + reline (0.5.6) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.63.4) + rubocop (1.63.5) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -311,7 +311,6 @@ PLATFORMS aarch64-linux arm-linux arm64-darwin - arm64-linux x86-linux x86_64-darwin x86_64-linux diff --git a/bin/shims/vite b/bin/shims/vite new file mode 100755 index 0000000..4d5e216 --- /dev/null +++ b/bin/shims/vite @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eo pipefail + +bunx vite "$@" \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 9729356..68fce3d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 4644c92..f5aee21 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,9 @@ "postcss": "^8.4.38", "rollup": "^4.2.0", "stimulus-vite-helpers": "^3.1.0", - "vite": "^5.0.0", - "vite-plugin-rails": "^0.5.0" + "vite": "^5.2.11", + "vite-plugin-rails": "^0.5.0", + "vite-plugin-ruby": "^5.0.0" }, "devDependencies": { "tailwindcss": "^3.4.3"