-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile.tt
111 lines (88 loc) · 3.26 KB
/
Dockerfile.tt
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
99
100
101
102
103
104
105
106
107
108
109
110
111
ARG APP_ROOT=<%= config.root %>
ARG RUBY_VERSION=<%= RUBY_VERSION %>
<%- if config.assets_precompile -%>ARG NODE_VERSION=<%= node_version %><%- end -%>
FROM ruby:${RUBY_VERSION}-alpine AS base
ARG APP_ROOT
RUN apk add --no-cache <%= packages.select(&:build?).join(' ') %>
RUN mkdir -p ${APP_ROOT}
COPY Gemfile Gemfile.lock ${APP_ROOT}/
WORKDIR ${APP_ROOT}
RUN gem install bundler:<%= Bundler::VERSION %> \
&& bundle config --local deployment 'true' \
&& bundle config --local frozen 'true' \
&& bundle config --local no-cache 'true' \
&& bundle config --local without '<%= exclude_groups.join(' ') %>' \
&& bundle install -j "$(getconf _NPROCESSORS_ONLN)" \
&& find ${APP_ROOT}/vendor/bundle -type f -name '*.c' -delete \
&& find ${APP_ROOT}/vendor/bundle -type f -name '*.h' -delete \
&& find ${APP_ROOT}/vendor/bundle -type f -name '*.o' -delete \
&& find ${APP_ROOT}/vendor/bundle -type f -name '*.gem' -delete
<%- if has?('bootsnap') -%>
RUN bundle exec bootsnap precompile --gemfile app/ lib/
<%- end -%>
<%- if config.assets_precompile -%>
FROM node:${NODE_VERSION}-alpine as node
FROM ruby:${RUBY_VERSION}-alpine as assets
ARG APP_ROOT
ARG RAILS_MASTER_KEY
ENV RAILS_MASTER_KEY=$RAILS_MASTER_KEY
<%- if packages.select(&:runtime?).any? -%>
RUN apk add --no-cache <%= packages.select(&:runtime?).join(' ') %> yarn
<%- end -%>
COPY --from=node /usr/local/bin/node /usr/local/bin/node
COPY --from=base /usr/local/bundle/config /usr/local/bundle/config
COPY --from=base /usr/local/bundle /usr/local/bundle
COPY --from=base ${APP_ROOT}/vendor/bundle ${APP_ROOT}/vendor/bundle
RUN mkdir -p ${APP_ROOT}
COPY . ${APP_ROOT}
ENV RAILS_ENV=production
WORKDIR ${APP_ROOT}
RUN bundle exec rake assets:precompile
<%- end -%>
FROM ruby:${RUBY_VERSION}-alpine
ARG APP_ROOT
<%- if packages.select(&:runtime?).any? -%>
RUN apk add --no-cache <%= packages.select(&:runtime?).join(' ') %>
<%- end -%>
COPY --from=base /usr/local/bundle/config /usr/local/bundle/config
COPY --from=base /usr/local/bundle /usr/local/bundle
COPY --from=base ${APP_ROOT}/vendor/bundle ${APP_ROOT}/vendor/bundle
<%- if has?('bootsnap') -%>
COPY --from=base ${APP_ROOT}/tmp/cache ${APP_ROOT}/tmp/cache
<%- end -%>
RUN mkdir -p ${APP_ROOT}
<%- if has?('rails') -%>
ENV RAILS_ENV=production
ENV RAILS_LOG_TO_STDOUT=true
ENV RAILS_SERVE_STATIC_FILES=yes
<%- end -%>
ENV APP_ROOT=$APP_ROOT
COPY . ${APP_ROOT}
<%- if config.assets_precompile -%>COPY --from=assets /${APP_ROOT}/public /${APP_ROOT}/public
<%- end -%>
<%- if config.revision -%>
ARG REVISION
ENV REVISION=$REVISION
ENV COMMIT_SHORT_SHA=$REVISION
RUN echo "${REVISION}" > ${APP_ROOT}/REVISION
<%- end -%>
<%- if config.sentry_release -%>
ARG SENTRY_RELEASE
ENV SENTRY_RELEASE=$SENTRY_RELEASE
<%- end -%>
# Apply Execute Permission
RUN adduser -h ${APP_ROOT} -D -s /bin/nologin ruby ruby && \
chown ruby:ruby ${APP_ROOT} && \
<%- if has?('rails') -%>
chown -R ruby:ruby ${APP_ROOT}/log && \
chown -R ruby:ruby ${APP_ROOT}/tmp && \
<%- end -%>
chmod -R +r ${APP_ROOT}
USER ruby
WORKDIR ${APP_ROOT}
EXPOSE <%= config.port %>
<%- if has?('liveness') || config.health_check -%>
HEALTHCHECK CMD curl -f http://localhost:<%= config.port %><%= config.health_check_path %> || exit 1
<%- end -%>
ENTRYPOINT <%= entrypoint %>
CMD <%= command %>