-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine RUN directives and optimize Dockerfile for smaller build (#2)
* Combine RUN directives and optimize Dockerfile for smaller build * Remove duplicate WORKDIR directives * Update commented package names for alpine
- Loading branch information
1 parent
a6217d2
commit 071b6b1
Showing
3 changed files
with
62 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,56 @@ | ||
FROM ruby:2.5.5 | ||
|
||
RUN apt-get update -qq && apt-get install -y build-essential apt-transport-https | ||
|
||
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - | ||
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list | ||
|
||
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash | ||
|
||
RUN apt-get update -qq && apt-get install -y libxml2-dev libxslt1-dev nodejs yarn | ||
|
||
# for postgres: libpq-dev | ||
# for capybara-webkit: libqt4-webkit libqt4-dev xvfb | ||
|
||
ENV APP_HOME=/app | ||
ENV RACK_ENV=production | ||
ENV RAILS_LOG_TO_STDOUT=true | ||
|
||
RUN mkdir $APP_HOME | ||
WORKDIR $APP_HOME | ||
|
||
RUN gem update --system && gem install bundler | ||
|
||
ADD Gemfile* package.json yarn.lock $APP_HOME/ | ||
# RUN bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | ||
RUN bundle install --without development:test --jobs 20 | ||
|
||
ADD . $APP_HOME | ||
FROM ruby:2.5.5-alpine | ||
|
||
# for postgres: postgresql-dev | ||
RUN apk add --no-cache \ | ||
sqlite-dev \ | ||
tzdata \ | ||
yarn | ||
|
||
WORKDIR /app | ||
|
||
ARG RACK_ENV=production | ||
ENV RACK_ENV=$RACK_ENV | ||
|
||
ADD Gemfile* /app/ | ||
RUN set -x \ | ||
&& apk add --no-cache --virtual .build-deps \ | ||
build-base \ | ||
libxml2-dev \ | ||
libxslt-dev \ | ||
&& gem install bundler \ | ||
&& bundle install --without development:test --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 | ||
|
||
COPY package.json yarn.lock /app/ | ||
RUN set -x \ | ||
&& yarn install \ | ||
&& rm -rf /tmp/* | ||
|
||
COPY . ./ | ||
|
||
# The command '/bin/sh -c rake assets:precompile' needs the RAILS_MASTER_KEY to be set!? | ||
# https://github.com/rails/rails/issues/32947 | ||
RUN SECRET_KEY_BASE=`bin/rake secret` rake assets:precompile | ||
RUN set -x \ | ||
&& 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 | ||
|
||
ENV RAILS_LOG_TO_STDOUT=true | ||
ENV RAILS_SERVE_STATIC_FILES=true | ||
ENV EXECJS_RUNTIME=Disabled | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["./start.sh"] | ||
CMD ["./start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#!/usr/bin/env bash | ||
#!/bin/sh | ||
|
||
set -e | ||
self=${0##*/} | ||
set -euo pipefail | ||
|
||
if [[ -z "$SECRET_KEY_BASE" ]]; then | ||
self="$(basename "$0")" | ||
|
||
if [ -z "${SECRET_KEY_BASE:-}" ]; then | ||
echo "== $self WARNING: SECRET_KEY_BASE not set" | ||
echo "== $self It will be set to a random value using \`rake secret\`" | ||
export SECRET_KEY_BASE=`rake secret` | ||
export SECRET_KEY_BASE="$(rake secret)" | ||
fi | ||
|
||
rake db:migrate | ||
|
||
exec rails server -b 0.0.0.0 -p 3000 | ||
exec rails server -b 0.0.0.0 -p 3000 |