forked from magma-labs/magma-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.old
74 lines (56 loc) · 2.08 KB
/
Dockerfile.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
FROM ruby:3.2.1 as base
WORKDIR /rails
ENV RAILS_ENV=production \
LANG=C.UTF-8 \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3 \
BUNDLE_PATH="/usr/local/bundle"
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build gems
# This example intentionally does not require or install node.js
RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
build-essential \
gnupg2 \
libpq-dev \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN gem update --system && gem install bundler
# Install application gems
COPY Gemfile Gemfile.lock ./
# TODO: consolidate bundle config better, currently split between ENV and `bundle config`
RUN bundle config frozen true \
&& bundle config jobs 4 \
&& bundle config deployment true \
&& bundle config without 'development test' \
&& bundle install \
&& bundle exec bootsnap precompile --gemfile
# Copy application code
COPY . .
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# 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:precompile
# TODO: This will work in Rails 7.1
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
# RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
# Final stage for app image
FROM base
# Install packages needed for deployment
RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
libpq-dev \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
# Run and own only the runtime files as a non-root user for security
RUN useradd rails --home /rails --shell /bin/bash && \
chown -R rails:rails db log storage tmp
USER rails:rails
# Start Server
EXPOSE 3000
RUN mkdir -p tmp/pids
# CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]