-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
73 lines (52 loc) · 1.89 KB
/
Dockerfile
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
# Accept optional arguments.
ARG RUBY_VERSION="3.3.6-alpine3.20"
# Create a base image.
FROM ruby:$RUBY_VERSION AS base
# Set production environment variables.
ENV BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development test" \
RAILS_ENV="production" \
RUBY_YJIT_ENABLE="true"
# Change to an application working directory.
WORKDIR /rails
# Install dependency requirements.
RUN apk -U upgrade \
&& apk add --no-cache bash gcompat jemalloc libxml2-dev libxslt-dev sqlite tzdata
# Create a builder image for Ruby.
FROM base AS build
# Install build dependency requirements.
RUN apk add --no-cache build-base
# Copy in files for Bundler.
COPY Gemfile Gemfile.lock ./
# Install the Bundler version specified.
RUN gem install bundler -v $(tail -n1 Gemfile.lock)
# Install the Ruby dependencies.
RUN bundle install
# Clean up dependnecy caches.
RUN rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
# Precompile the Bootsnap cache for the dependencies.
RUN bundle exec bootsnap precompile --gemfile
# Copy the application into Docker.
COPY . .
# Precompile the Bootsnap cache for the application.
RUN bundle exec bootsnap precompile app/ lib/
# Compile the assets without requiring the secret RAILS_MASTER_KEY.
RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile
# Create an image for the application.
FROM base AS application
# Copy the application and dependencies into Docker.
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails
# Create an application-specific user.
RUN addgroup --system rails \
&& adduser -G rails --system rails \
&& chown -R rails:rails db log storage tmp
# Switch to the user.
USER rails:rails
# Set a custom entrypoint.
ENTRYPOINT ["bin/docker-entrypoint"]
# Expose the server.
EXPOSE 80
# Run the server via Thruster.
CMD ["bin/thrust", "bin/rails", "server"]