-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
91 lines (70 loc) · 2.13 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
######################
# Stage: Builder
FROM ruby:2.7.4-alpine as builder
ARG GID
ARG UID
ARG RAILS_ENV
RUN apk add --update --no-cache \
build-base \
postgresql-dev \
git \
nodejs \
bash \
yarn \
imagemagick \
tzdata
ENV BUNDLER_VERSION 2.2.18
RUN echo 'gem: --no-rdoc --no-ri' >> "/etc/gemrc"
RUN gem install bundler --version $BUNDLER_VERSION
RUN addgroup --gid $GID decidem && adduser -D -g '' -u $UID -G decidem decidem
ENV app /home/decidem/app
WORKDIR $app
COPY . $app
# Install gems
RUN bundle config --global frozen 1 \
&& bundle config set --local without 'development test' \
&& bundle config set --local path vendor/bundle \
&& bundle install --jobs 20 --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
RUN yarn install --ignore-engines
RUN RAILS_ENV=$RAILS_ENV SECRET_KEY_BASE=foo bundle exec rails webpacker:compile
# Remove folders not needed in resulting image
RUN rm -rf node_modules tmp/cache
###############################
# Stage wkhtmltopdf
FROM madnight/docker-alpine-wkhtmltopdf as wkhtmltopdf
###############################
# Stage Final
FROM ruby:2.7.4-alpine
ARG GID
ARG UID
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV app /home/decidem/app
# Add Alpine packages
RUN apk add --update --no-cache \
postgresql-client \
imagemagick \
tzdata \
file \
bash \
# needed for whenever cron jobs
busybox-initscripts \
busybox-suid \
# needed for wkhtmltopdf
libressl3.3-libcrypto \
ttf-dejavu ttf-droid ttf-freefont ttf-liberation
# Copy wkhtmltopdf from former build stage
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/
RUN addgroup --gid $GID decidem && adduser -D -g '' -u $UID -G decidem decidem
USER decidem
# Copy app with gems from former build stage
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
COPY --from=builder --chown=decidem:decidem /home/decidem/app $app
WORKDIR $app
EXPOSE 3000
ENTRYPOINT []
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]