Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from alpine to ruby slim image #173

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 28 additions & 47 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
FROM ruby:3.3.5-alpine3.20
FROM ruby:3.3.5-slim

# for postgres: postgresql-dev
RUN apk add --no-cache \
sqlite-dev \
tzdata \
yarn
RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
build-essential \
git \
sqlite3 \
yarn \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR /app
ENV LANG=C.UTF-8 \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3 \
RAILS_ENV=production

ARG RACK_ENV=production
ENV RACK_ENV=$RACK_ENV
RUN gem update --system && gem install bundler

ADD Gemfile* /app/
RUN set -x \
&& apk add --no-cache --virtual .build-deps \
build-base \
libxml2-dev \
libxslt-dev \
git \
&& gem install bundler \
&& bundle config set --local without 'development:test' \
&& bundle install --jobs 20 -j"$(nproc)" --retry 3 \
# Remove unneeded files (cached *.gem, *.o, *.c)
&& rm -rf \
/usr/local/bundle/cache/*.gem \
/usr/local/bundle/gems/**/*.c \
/usr/local/bundle/gems/**/*.o \
&& apk del .build-deps
WORKDIR /app

COPY Gemfile* .ruby-version /app/
RUN bundle config frozen true \
&& bundle config jobs 4 \
&& bundle config deployment true \
&& bundle config without 'development test' \
&& bundle install

COPY package.json yarn.lock /app/
RUN set -x \
Expand All @@ -35,33 +30,19 @@ RUN set -x \

COPY . ./

# The command '/bin/sh -c rake assets:precompile' needs the RAILS_MASTER_KEY to be set!?
# https://github.com/rails/rails/issues/32947
#
# Added xz-libs because nokogiri needs liblzma.so.5
# during rake tasks (eg. assets-precompile)
#
# Added gcompat
# https://nokogiri.org/tutorials/installing_nokogiri.html#linux-musl-error-loading-shared-library
RUN set -x \
&& apk add --no-cache xz-libs gcompat \
&& SECRET_KEY_BASE=foo bundle exec rake assets:precompile \
# Remove folders not needed in resulting image
&& rm -rf \
/tmp/* \
app/assets \
lib/assets \
node_modules \
spec \
tmp/cache \
vendor/assets
# Precompile assets
# SECRET_KEY_BASE or RAILS_MASTER_KEY is required in production, but we don't
# want real secrets in the image or image history. The real secret is passed in
# at run time
ARG SECRET_KEY_BASE=fakekeyforassets
RUN bin/rails assets:clobber && bundle exec rails assets:precompile

EXPOSE 3000

ENV RAILS_LOG_TO_STDOUT=true
ENV RAILS_SERVE_STATIC_FILES=true
ENV EXECJS_RUNTIME=Disabled

EXPOSE 3000

VOLUME /app/db/sqlite

CMD ["./start.sh"]
Loading