-
Notifications
You must be signed in to change notification settings - Fork 31
/
Dockerfile
68 lines (53 loc) · 1.5 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
######################
# Stage: Builder
FROM ruby:2.5.1-alpine as Builder
RUN apk add --update --no-cache \
build-base \
postgresql-dev \
git \
imagemagick \
tzdata
WORKDIR /app
# Install gems
ARG BUNDLE_WITHOUT
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
COPY Gemfile* /app/
RUN 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
# Add the Rails app
COPY . /app/
# Remove folders not needed in resulting image
ARG FOLDERS_TO_REMOVE
RUN rm -rf $FOLDERS_TO_REMOVE
###############################
# Stage Final
FROM ruby:2.5.1-alpine
LABEL maintainer="[email protected]"
# Add Alpine packages
ARG ADDITIONAL_PACKAGES
RUN apk add --update --no-cache \
postgresql-client \
imagemagick \
tzdata \
file \
$ADDITIONAL_PACKAGES
# 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 --chown=app:app /usr/local/bundle/ /usr/local/bundle/
COPY --from=Builder --chown=app:app /app/ /app/
WORKDIR /app
# Add a script to be executed every time the container starts.
COPY --chown=app:app bin/docker-entrypoint /usr/bin/
RUN chmod +x /usr/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]
# Expose Server port
EXPOSE 3000
# Set Rails env
ENV RAILS_LOG_TO_STDOUT true
# Start up
CMD ["bundle", "exec", "rails", "server"]