-
Notifications
You must be signed in to change notification settings - Fork 13
/
Dockerfile.prod
72 lines (56 loc) · 1.81 KB
/
Dockerfile.prod
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
###############################################################################
# Stage 1: Build
FROM ruby:3.0.0 as builder
# Install base packages
RUN apt-get update -qq && \
apt-get install -y \
build-essential \
vim \
nano \
postgresql-client && \
rm -rf /var/lib/apt/lists
# Set env variables
ENV BUNDLER_VERSION 2.2.3
ENV BUNDLE_JOBS 8
ENV BUNDLE_RETRY 5
ENV BUNDLE_WITHOUT development:test
ENV BUNDLE_CACHE_ALL true
ENV RAILS_ROOT /app
ENV RAILS_ENV production
ENV RACK_ENV production
# Set working directory
WORKDIR $RAILS_ROOT
# Install gems
COPY Gemfile Gemfile.lock ./
RUN gem install bundler -v $BUNDLER_VERSION --no-document
RUN bundle config --global frozen 1 && \
bundle install && \
rm -rf /usr/local/bundle/cache/*.gem && \
find /usr/local/bundle/gems/ -name "*.c" -delete && \
find /usr/local/bundle/gems/ -name "*.o" -delete
# Copy app files
COPY . .
# Precompile assets
# SECRET_KEY_BASE=`bin/rake secret` is added here as a workaround for
# https://github.com/rails/rails/issues/32947
RUN SECRET_KEY_BASE=`bin/rake secret` rails assets:precompile --trace && \
rm -rf tmp/cache vendor/assets test
###############################################################################
# Stage 2: Run
FROM ruby:3.0.0
ENV RAILS_ENV production
ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_ROOT /app
EXPOSE 3000
RUN mkdir -p $RAILS_ROOT
WORKDIR $RAILS_ROOT
# Copy necessary data at runtime
COPY --from=builder /usr/lib /usr/lib
# Copy gems
COPY --from=builder /usr/local/bundle /usr/local/bundle
# Copy app files
COPY --from=builder $RAILS_ROOT $RAILS_ROOT
# Default entrypoint (overriden if used with this project's docker-compose)
ENTRYPOINT ["sh", "/app/docker-entrypoint.sh"]
# Default command (overriden if used with this project's docker-compose)
CMD ["rails", "server", "-b", "0.0.0.0"]