-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
54 lines (45 loc) · 1.67 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
FROM ruby:3.2.2-slim@sha256:70370316b02901d7db3f6e453d6259ed4d0d52326d6ac57e3a579f7e3b616e41
# Add build-essential tools.
RUN apt-get update -qq && \
apt-get install -y \
build-essential \
git \
libpq-dev \
curl \
netcat \
wkhtmltopdf
# Add Node, required for asset pipeline.
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y nodejs && \
npm install -q -g yarn
RUN mkdir /app
WORKDIR /app
# Define args that can be supplied with
# `docker build --build-args RAILS_ENV=<env>`, defaults to production.
ARG BUILD_HASH='unknown'
ENV BUILD_HASH=$BUILD_HASH
ARG RAILS_ENV='production'
ARG NODE_ENV='production'
ARG RAILS_MASTER_KEY
# Pre-install gems, so that they can be cached.
COPY Gemfile* /app/
RUN if [ "$RAILS_ENV" = 'production' ] || [ "$RAILS_ENV" = 'staging' ] || [ "$RAILS_ENV" = 'luxproduction' ]; then \
bundle config set --local without 'development test'; \
else \
bundle config set --local without 'development'; \
fi
RUN bundle install
# Pre-install npm packages, so that they can be cached.
COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn .yarn
RUN yarn install --immutable
COPY . /app/
# Precompile assets after copying app because whole Rails pipeline is needed.
RUN --mount=type=secret,id=rails_master_key \
if [ "$RAILS_ENV" = 'production' ] || [ "$RAILS_ENV" = 'staging' ] || [ "$RAILS_ENV" = 'luxproduction' ]; then \
# Use secret if RAILS_MASTER_KEY build arg is not set.
RAILS_MASTER_KEY="${RAILS_MASTER_KEY:-$(cat /run/secrets/rails_master_key)}" bundle exec rails assets:precompile; \
else \
echo "Skipping assets:precompile"; \
fi
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]