Start running Rails from the main branch #16
3 changed files with 35 additions and 18 deletions
40
Dockerfile
40
Dockerfile
|
@ -1,25 +1,36 @@
|
||||||
# syntax = docker/dockerfile:1
|
# syntax = docker/dockerfile:1
|
||||||
|
|
||||||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
|
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
|
||||||
ARG RUBY_VERSION=3.2.2
|
# docker build -t my-app .
|
||||||
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
|
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
|
||||||
|
|
||||||
|
# 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.3.1
|
||||||
|
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
|
||||||
|
|
||||||
# Rails app lives here
|
# Rails app lives here
|
||||||
WORKDIR /rails
|
WORKDIR /rails
|
||||||
|
|
||||||
|
# Install base packages
|
||||||
|
RUN apt-get update -qq && \
|
||||||
|
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 libvips && \
|
||||||
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
||||||
|
|
||||||
# Set production environment
|
# Set production environment
|
||||||
ENV RAILS_ENV="production" \
|
ENV RAILS_ENV="production" \
|
||||||
BUNDLE_DEPLOYMENT="1" \
|
BUNDLE_DEPLOYMENT="1" \
|
||||||
BUNDLE_PATH="/usr/local/bundle" \
|
BUNDLE_PATH="/usr/local/bundle" \
|
||||||
BUNDLE_WITHOUT="development"
|
BUNDLE_WITHOUT="development"
|
||||||
|
|
||||||
|
|
||||||
# Throw-away build stage to reduce size of final image
|
# Throw-away build stage to reduce size of final image
|
||||||
FROM base as build
|
FROM base AS build
|
||||||
|
|
||||||
# Install packages needed to build gems
|
# Install packages needed to build gems
|
||||||
RUN apt-get update -qq && \
|
RUN apt-get update -qq && \
|
||||||
apt-get install --no-install-recommends -y build-essential git libvips pkg-config
|
apt-get install --no-install-recommends -y build-essential git pkg-config && \
|
||||||
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
||||||
|
|
||||||
# Install application gems
|
# Install application gems
|
||||||
COPY Gemfile Gemfile.lock ./
|
COPY Gemfile Gemfile.lock ./
|
||||||
|
@ -27,7 +38,6 @@ RUN bundle install && \
|
||||||
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
|
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
|
||||||
bundle exec bootsnap precompile --gemfile
|
bundle exec bootsnap precompile --gemfile
|
||||||
|
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
@ -38,24 +48,20 @@ RUN bundle exec bootsnap precompile app/ lib/
|
||||||
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
|
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Final stage for app image
|
# Final stage for app image
|
||||||
FROM base
|
FROM base
|
||||||
|
|
||||||
# Install packages needed for deployment
|
|
||||||
RUN apt-get update -qq && \
|
|
||||||
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips libjemalloc2 && \
|
|
||||||
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
|
||||||
|
|
||||||
# Copy built artifacts: gems, application
|
# Copy built artifacts: gems, application
|
||||||
COPY --from=build /usr/local/bundle /usr/local/bundle
|
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
|
||||||
COPY --from=build /rails /rails
|
COPY --from=build /rails /rails
|
||||||
|
|
||||||
# Run and own only the runtime files as a non-root user for security
|
# Run and own only the runtime files as a non-root user for security
|
||||||
RUN useradd rails --create-home --shell /bin/bash && \
|
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
|
chown -R rails:rails db log storage tmp
|
||||||
USER rails:rails
|
USER 1000:1000
|
||||||
|
|
||||||
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
|
|
||||||
|
|
||||||
# Entrypoint prepares the database.
|
# Entrypoint prepares the database.
|
||||||
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
||||||
|
|
|
@ -166,6 +166,8 @@ GEM
|
||||||
net-smtp (0.5.0)
|
net-smtp (0.5.0)
|
||||||
net-protocol
|
net-protocol
|
||||||
nio4r (2.7.3)
|
nio4r (2.7.3)
|
||||||
|
nokogiri (1.16.6-aarch64-linux)
|
||||||
|
racc (~> 1.4)
|
||||||
nokogiri (1.16.6-arm64-darwin)
|
nokogiri (1.16.6-arm64-darwin)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.16.6-x86_64-linux)
|
nokogiri (1.16.6-x86_64-linux)
|
||||||
|
@ -246,12 +248,15 @@ GEM
|
||||||
actionpack (>= 6.1)
|
actionpack (>= 6.1)
|
||||||
activesupport (>= 6.1)
|
activesupport (>= 6.1)
|
||||||
sprockets (>= 3.0.0)
|
sprockets (>= 3.0.0)
|
||||||
|
sqlite3 (2.0.2-aarch64-linux-gnu)
|
||||||
sqlite3 (2.0.2-arm64-darwin)
|
sqlite3 (2.0.2-arm64-darwin)
|
||||||
sqlite3 (2.0.2-x86_64-linux-gnu)
|
sqlite3 (2.0.2-x86_64-linux-gnu)
|
||||||
stimulus-rails (1.3.3)
|
stimulus-rails (1.3.3)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
stringio (3.1.1)
|
stringio (3.1.1)
|
||||||
strscan (3.1.0)
|
strscan (3.1.0)
|
||||||
|
tailwindcss-rails (2.6.1-aarch64-linux)
|
||||||
|
railties (>= 7.0.0)
|
||||||
tailwindcss-rails (2.6.1-arm64-darwin)
|
tailwindcss-rails (2.6.1-arm64-darwin)
|
||||||
railties (>= 7.0.0)
|
railties (>= 7.0.0)
|
||||||
tailwindcss-rails (2.6.1-x86_64-linux)
|
tailwindcss-rails (2.6.1-x86_64-linux)
|
||||||
|
@ -285,6 +290,7 @@ GEM
|
||||||
zeitwerk (2.6.16)
|
zeitwerk (2.6.16)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
aarch64-linux
|
||||||
arm64-darwin-23
|
arm64-darwin-23
|
||||||
x86_64-linux
|
x86_64-linux
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# Enable jemalloc for reduced memory usage and latency.
|
||||||
|
if [ -z "${LD_PRELOAD+x}" ] && [ -f /usr/lib/*/libjemalloc.so.2 ]; then
|
||||||
|
export LD_PRELOAD="$(echo /usr/lib/*/libjemalloc.so.2)"
|
||||||
|
fi
|
||||||
|
|
||||||
# If running the rails server then create or migrate existing database
|
# If running the rails server then create or migrate existing database
|
||||||
if [ "${*}" == "./bin/rails server" ]; then
|
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
|
||||||
./bin/rails db:prepare
|
./bin/rails db:prepare
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue