-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
48 lines (43 loc) · 1.42 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
# *******************
# Stage base
FROM ruby:3.1.2-alpine as base_stage
ENV RAILS_LOG_TO_STDOUT=1
ENV LANG C.UTF-8
# Install only production dependencies by default. Provide empty value as build arg to allow non-prod dependencies
# Leave this in the base stage so that Rails also reads this value to do its magic with dependencies
ARG BUNDLE_WITHOUT=development:test
ENV BUNDLE_WITHOUT $BUNDLE_WITHOUT
RUN set -eux; \
apk add --update --no-cache \
tzdata \
gcompat \
bash \
curl \
# Needed for postgres gem
libpq-dev
ARG USERNAME=rails
ENV USERNAME $USERNAME
RUN adduser -D -H ${USERNAME} ${USERNAME}
ENV HOMEDIR /home/${USERNAME}
ENV WORKDIR ${HOMEDIR}/app
WORKDIR ${WORKDIR}
RUN chown $USERNAME:$USERNAME ${HOMEDIR}
COPY --chown=${USERNAME}:${USERNAME} Gemfile Gemfile.lock ./
# Stage bundle
# Install packages and avoid leaving auth tokens for private packages in history (i.e. docker history <IMAGE_NAME>)
FROM base_stage as bundle
RUN set -eux; \
apk add --update --no-cache \
build-base
RUN gem install bundler -v 2.3.12 && \
gem cleanup bundler
RUN bundle install
# --jobs "$(getconf _NPROCESSORS_ONLN)"
# Stage: Final
FROM base_stage
COPY --chown=${USERNAME}:${USERNAME} --from=bundle ${GEM_HOME} ${GEM_HOME}
COPY --chown=${USERNAME}:${USERNAME} . ${WORKDIR}
USER ${USERNAME}:${USERNAME}
RUN bundle exec rake RAILS_ENV=production assets:precompile
EXPOSE 3000
ENTRYPOINT ["./docker-entrypoint.sh"]