|
1 | | -FROM ruby:3.1.2 |
| 1 | +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile |
| 2 | +ARG RUBY_VERSION=3.1.2 |
| 3 | +FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base |
2 | 4 |
|
3 | | -RUN apt-get update |
| 5 | +# Install packages needed to build gems and node modules |
| 6 | +RUN apt-get update -qq && \ |
| 7 | + apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3 |
4 | 8 |
|
5 | | -# install node and yarn |
6 | | -RUN curl -sL https://deb.nodesource.com/setup_18.x | bash |
7 | | -RUN apt-get install -y nodejs |
8 | | -RUN npm install -g yarn |
| 9 | +# Install JavaScript dependencies |
| 10 | +# Make sure NODE_VERSION matches the node version in .nvmrc and package.json |
| 11 | +ARG NODE_VERSION=18.13.0 |
| 12 | +ARG YARN_VERSION=1.22.19 |
| 13 | +ENV PATH=/usr/local/node/bin:$PATH |
| 14 | +RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \ |
| 15 | + /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \ |
| 16 | + npm install -g yarn@$YARN_VERSION && \ |
| 17 | + rm -rf /tmp/node-build-master |
9 | 18 |
|
| 19 | +# Rails app lives here |
10 | 20 | WORKDIR /app |
11 | 21 |
|
12 | | -# install ruby gems |
13 | | -COPY Gemfile* ./ |
| 22 | +# Set production environment |
| 23 | +ENV RAILS_ENV="production" \ |
| 24 | + BUNDLE_DEPLOYMENT="1" \ |
| 25 | + BUNDLE_PATH="/usr/local/bundle" \ |
| 26 | + BUNDLE_WITHOUT="development test" |
14 | 27 |
|
15 | | -RUN bundle config set without 'development test' && \ |
16 | | - bundle config set with 'staging production' && \ |
17 | | - bundle install --jobs=3 --retry=3 |
18 | 28 |
|
19 | | -# install node packages |
| 29 | +# Throw-away build stage to reduce size of final image |
| 30 | +FROM base as build |
| 31 | + |
| 32 | +# Install application gems |
| 33 | +COPY Gemfile Gemfile.lock ./ |
| 34 | +RUN bundle install && \ |
| 35 | + rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git |
| 36 | + |
| 37 | +# Install node modules |
20 | 38 | COPY package.json yarn.lock ./ |
21 | | -RUN yarn install |
| 39 | +RUN yarn install --frozen-lockfile |
| 40 | + |
| 41 | +# Copy application code |
| 42 | +COPY . . |
| 43 | + |
| 44 | +# Final stage for app image |
| 45 | +FROM base |
22 | 46 |
|
23 | | -COPY . ./ |
| 47 | +# Install packages needed for deployment |
| 48 | +RUN apt-get update -qq && \ |
| 49 | + apt-get install --no-install-recommends -y curl libvips postgresql-client && \ |
| 50 | + rm -rf /var/lib/apt/lists /var/cache/apt/archives |
24 | 51 |
|
25 | | -ENV RAILS_ENV=production |
26 | | -ENV NODE_ENV=production |
| 52 | +# Copy built artifacts: gems, application |
| 53 | +COPY --from=build /usr/local/bundle /usr/local/bundle |
| 54 | +COPY --from=build /app /app |
27 | 55 |
|
| 56 | +ENV RAILS_ENV=production \ |
| 57 | + NODE_ENV=production \ |
| 58 | + SECRET_KEY_BASE=NOT_USED_NON_BLANK |
28 | 59 | # compiling assets requires any value for ENV of SECRET_KEY_BASE |
29 | | -ENV SECRET_KEY_BASE=NOT_USED_NON_BLANK |
30 | 60 |
|
31 | 61 | RUN yarn res:build |
32 | | -RUN rails react_on_rails:locale |
33 | | -RUN rails assets:precompile |
| 62 | +RUN bin/rails react_on_rails:locale |
| 63 | +RUN bin/rails assets:precompile |
34 | 64 |
|
35 | 65 | # add entrypoint |
36 | 66 | COPY .controlplane/entrypoint.sh ./ |
37 | 67 | ENTRYPOINT ["/app/entrypoint.sh"] |
38 | 68 |
|
39 | | -CMD ["rails", "s"] |
| 69 | +CMD ["rails", "server"] |
0 commit comments