-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.prod
83 lines (71 loc) · 2.15 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
73
74
75
76
77
78
79
80
81
82
83
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.6
FROM library/ruby:$RUBY_VERSION-slim AS base
# Rails app lives here
WORKDIR /rails
# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
build-essential \
git \
libpq-dev \
libssl-dev \
libvips \
openssl \
pkg-config \
postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
FROM base AS builder
# Install application gems
COPY Gemfile Gemfile.lock ./
RUN rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle install && \
bundle exec bootsnap precompile --gemfile
# Copy application code
COPY app ./app
COPY bin ./bin
COPY config ./config
COPY db ./db
COPY lib ./lib
COPY public ./public
COPY storage ./storage
COPY vendor ./vendor
COPY Rakefile ./Rakefile
COPY config.ru ./config.ru
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# Run and own only the runtime files AS a non-root user for security
# Run and own only the runtime files AS a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
chown -R rails:rails /rails /usr/local/bundle
USER rails:rails
# Start the server by default, this can be overwritten at runtime
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# FROM thatguyinabeanie/battle-stadium:latest AS production
FROM builder AS pre-production
USER rails:rails
WORKDIR /rails
COPY app ./app
COPY bin ./bin
COPY config ./config
COPY db ./db
COPY lib ./lib
COPY public ./public
COPY storage ./storage
COPY vendor ./vendor
COPY Rakefile ./Rakefile
COPY config.ru ./config.ru
COPY Gemfile Gemfile.lock ./
RUN bundle check || bundle install
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
FROM thatguyinabeanie/battle-stadium:latest AS production
EXPOSE 10000
ENV RAILS_ENV=production
USER rails:rails
ENTRYPOINT ["/rails/bin/docker-entrypoint"]