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

Dockerfile improvements for final image size #92

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 13 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ RUN bash -c "set -o pipefail && apt-get update \
&& mkdir /node_modules && chown ruby:ruby -R /node_modules /app"

USER ruby
ARG BUNDLE_WITHOUT='development test'
ENV BUNDLE_PATH=/usr/local/bundle

COPY --chown=ruby:ruby Gemfile* ./
RUN bundle install
RUN bundle config set without $BUNDLE_WITHOUT && \
bundle config set deployment true && \
bundle install

RUN mkdir .yarn public log tmp
COPY --chown=ruby:ruby package.json *yarn* ./
RUN yarn install
RUN yarn install --frozen-lockfile

ARG RAILS_ENV="production"
ARG NODE_ENV="production"
Expand All @@ -36,7 +41,7 @@ ENV RAILS_ENV="${RAILS_ENV}" \
COPY --chown=ruby:ruby . .

RUN if [ "${RAILS_ENV}" != "development" ]; then \
SECRET_KEY_BASE_DUMMY=1 rails assets:precompile; fi
SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile; fi

CMD ["bash"]

Expand All @@ -51,8 +56,8 @@ ARG UID=1000
ARG GID=1000

RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential curl libpq-dev \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& apt-get install -y --no-install-recommends curl postgresql-client tzdata \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& apt-get clean \
&& groupadd -g "${GID}" ruby \
&& useradd --create-home --no-log-init -u "${UID}" -g "${GID}" ruby \
Expand All @@ -66,7 +71,8 @@ RUN chmod 0755 bin/*
ARG RAILS_ENV="production"
ENV RAILS_ENV="${RAILS_ENV}" \
PATH="${PATH}:/home/ruby/.local/bin" \
USER="ruby"
USER="ruby" \
BUNDLE_PATH=/usr/local/bundle

COPY --chown=ruby:ruby --from=assets /usr/local/bundle /usr/local/bundle
COPY --chown=ruby:ruby --from=assets /app/public /public
Expand All @@ -76,4 +82,4 @@ ENTRYPOINT ["/app/bin/docker-entrypoint-web"]

EXPOSE 8000

CMD ["rails", "s"]
CMD ["rails", "s"]
Loading