forked from ledermann/docker-rails-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
64 lines (55 loc) · 2.37 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
# syntax = docker/dockerfile:1.0-experimental
FROM ruby:3.0.0-alpine
LABEL maintainer="georg@ledermann.dev"
# Add basic packages
RUN apk add --no-cache \
build-base \
postgresql-dev \
git \
nodejs \
yarn \
tzdata \
file
RUN apk add --update gcc musl-dev make curl-dev openssl-dev
WORKDIR /app
# Install standard Node modules
COPY package.json yarn.lock /app/
RUN yarn install --frozen-lockfile
# Install standard gems
COPY Gemfile* /app/
RUN bundle config --local frozen 1 && \
bundle install -j4 --retry 3
#### ONBUILD: Add triggers to the image, executed later while building a child image
# Install Ruby gems (for production only)
ONBUILD COPY Gemfile* /app/
ONBUILD RUN bundle config --local without 'development test' && \
bundle install -j4 --retry 3 && \
# Remove unneeded gems
bundle clean --force && \
# Remove unneeded files from installed gems (cached *.gem, *.o, *.c)
rm -rf /usr/local/bundle/cache/*.gem && \
find /usr/local/bundle/gems/ -name "*.c" -delete && \
find /usr/local/bundle/gems/ -name "*.o" -delete
# Copy the whole application folder into the image
ONBUILD COPY . /app
# Compile assets with Webpacker or Sprockets
#
# Notes:
# 1. Executing "assets:precompile" runs "yarn:install" prior
# 2. Executing "assets:precompile" runs "webpacker:compile", too
# 3. For an app using encrypted credentials, Rails raises a `MissingKeyError`
# if the master key is missing. Because on CI there is no master key,
# we hide the credentials while compiling assets (by renaming them before and after)
#
ONBUILD RUN mv config/credentials.yml.enc config/credentials.yml.enc.bak 2>/dev/null || true
ONBUILD RUN mv config/credentials config/credentials.bak 2>/dev/null || true
ONBUILD RUN --mount=type=secret,id=npmrc,dst=/root/.npmrc \
--mount=type=secret,id=yarnrc,dst=/root/.yarnrc.yml \
RAILS_ENV=production \
SECRET_KEY_BASE=dummy \
RAILS_MASTER_KEY=dummy \
bundle exec rails assets:precompile
ONBUILD RUN mv config/credentials.yml.enc.bak config/credentials.yml.enc 2>/dev/null || true
ONBUILD RUN mv config/credentials.bak config/credentials 2>/dev/null || true
# Remove folders not needed in resulting image
ONBUILD RUN rm -rf node_modules tmp/cache vendor/bundle test spec app/javascript app/packs