Skip to content

Commit 0d7edfc

Browse files
committed
Align Dockerfile to new Koalagator Dockerfile
1 parent 55aff6a commit 0d7edfc

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

Dockerfile

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,57 @@
22

33
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
44
ARG RUBY_VERSION=3.3.7
5-
FROM ruby:$RUBY_VERSION-slim as base
6-
7-
LABEL fly_launch_runtime="rails"
5+
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
86

97
# Rails app lives here
108
WORKDIR /rails
119

1210
# Set production environment
1311
ENV RAILS_ENV="production" \
14-
BUNDLE_WITHOUT="development:test" \
15-
BUNDLE_DEPLOYMENT="1"
16-
17-
# Update gems and bundler
18-
RUN gem update --system --no-document && \
19-
gem install -N bundler
12+
BUNDLE_DEPLOYMENT="1" \
13+
BUNDLE_PATH="/usr/local/bundle" \
14+
BUNDLE_WITHOUT="development"
2015

2116

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

2520
# Install packages needed to build gems
2621
RUN apt-get update -qq && \
27-
apt-get install --no-install-recommends -y build-essential libpq-dev libyaml pkg-config git
22+
apt-get install --no-install-recommends -y build-essential git libvips pkg-config
2823

2924
# Install application gems
30-
COPY --link Gemfile Gemfile.lock ./
25+
COPY Gemfile Gemfile.lock ./
3126
RUN bundle install && \
32-
bundle exec bootsnap precompile --gemfile && \
33-
rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git
27+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
28+
bundle exec bootsnap precompile --gemfile
3429

3530
# Copy application code
36-
COPY --link . .
31+
COPY . .
3732

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

4136
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
42-
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
37+
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
4338

4439

4540
# Final stage for app image
4641
FROM base
4742

4843
# Install packages needed for deployment
4944
RUN apt-get update -qq && \
50-
apt-get install --no-install-recommends -y libsqlite3-0 postgresql-client && \
45+
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
5146
rm -rf /var/lib/apt/lists /var/cache/apt/archives
5247

53-
# Run and own the application files as a non-root user for security
54-
RUN useradd rails --home /rails --shell /bin/bash
55-
USER rails:rails
56-
5748
# Copy built artifacts: gems, application
5849
COPY --from=build /usr/local/bundle /usr/local/bundle
59-
COPY --from=build --chown=rails:rails /rails /rails
50+
COPY --from=build /rails /rails
6051

61-
# Deployment options
62-
ENV RAILS_LOG_TO_STDOUT="1" \
63-
RAILS_SERVE_STATIC_FILES="true"
52+
# Run and own only the runtime files as a non-root user for security
53+
RUN useradd rails --create-home --shell /bin/bash && \
54+
chown -R rails:rails db log storage tmp
55+
USER rails:rails
6456

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

0 commit comments

Comments
 (0)