forked from ledermann/docker-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
98 lines (77 loc) · 2.11 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
######################
# Stage: Builder
FROM ruby:2.4.4-alpine3.7 as Builder
ARG FOLDERS_TO_REMOVE
ARG BUNDLE_WITHOUT
ARG RAILS_ENV
ARG NODE_ENV
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
ENV RAILS_ENV ${RAILS_ENV}
ENV NODE_ENV ${NODE_ENV}
ENV SECRET_KEY_BASE=foo
ENV RAILS_SERVE_STATIC_FILES=true
RUN apk add --update --no-cache \
build-base \
postgresql-dev \
git \
imagemagick \
nodejs-current \
yarn \
tzdata
WORKDIR /app
# Install gems
ADD Gemfile* /app/
RUN bundle config --global frozen 1 \
&& bundle install -j4 --retry 3 \
# Remove unneeded files (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
# Install yarn packages
COPY package.json yarn.lock .yarnclean /app/
RUN yarn install
# Add the Rails app
ADD . /app
# Precompile assets
RUN bundle exec rake assets:precompile
# Remove folders not needed in resulting image
RUN rm -rf $FOLDERS_TO_REMOVE
###############################
# Stage wkhtmltopdf
FROM madnight/docker-alpine-wkhtmltopdf as wkhtmltopdf
###############################
# Stage Final
FROM ruby:2.4.4-alpine3.7
LABEL maintainer="[email protected]"
ARG ADDITIONAL_PACKAGES
ARG EXECJS_RUNTIME
# Add Alpine packages
RUN apk add --update --no-cache \
postgresql-client \
imagemagick \
$ADDITIONAL_PACKAGES \
tzdata \
file \
# needed for wkhtmltopdf
libcrypto1.0 libssl1.0 \
ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family
# Copy wkhtmltopdf from former build stage
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/
# Add user
RUN addgroup -g 1000 -S app \
&& adduser -u 1000 -S app -G app
USER app
# Copy app with gems from former build stage
COPY --from=Builder /usr/local/bundle/ /usr/local/bundle/
COPY --from=Builder --chown=app:app /app /app
# Set Rails env
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_SERVE_STATIC_FILES true
ENV EXECJS_RUNTIME $EXECJS_RUNTIME
WORKDIR /app
# Expose Puma port
EXPOSE 3000
# Save timestamp of image building
RUN date -u > BUILD_TIME
# Start up
CMD ["docker/startup.sh"]