forked from ledermann/docker-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
84 lines (65 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
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
######################
# Stage: Builder
FROM ruby:2.6.4-alpine as Builder
ARG FOLDERS_TO_REMOVE
ARG BUNDLE_WITHOUT
ARG RAILS_ENV
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
ENV RAILS_ENV ${RAILS_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 \
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 Final
FROM ruby:2.6.4-alpine
LABEL maintainer="mail@georg-ledermann.de"
ARG ADDITIONAL_PACKAGES
# Add Alpine packages
RUN apk add --update --no-cache \
postgresql-client \
imagemagick \
$ADDITIONAL_PACKAGES \
tzdata \
file
# 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
WORKDIR /app
# Expose Puma port
EXPOSE 3000
# Save timestamp of image building
RUN date -u > BUILD_TIME
# Start up
CMD ["docker/startup.sh"]