generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
126 lines (90 loc) · 3.63 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# ------------------------------------------------------------------------------
# Base
# ------------------------------------------------------------------------------
FROM ruby:3.3.3-slim as base
RUN apt-get update && apt-get install -qq -y \
build-essential \
libpq-dev \
--fix-missing --no-install-recommends
RUN apt-get install -y wget curl gnupg2 git --no-install-recommends
ENV TZ="Europe/London"
# https://github.com/jgm/pandoc/releases/download/2.17.0.1/pandoc-2.17.0.1-1-arm64.deb
RUN wget -q https://github.com/jgm/pandoc/releases/download/2.14.2/pandoc-2.14.2-1-amd64.deb; \
apt-get install ./pandoc-2.14.2-1-amd64.deb; \
rm pandoc-2.14.2-1-amd64.deb
RUN apt-get install -qq -y \
texlive \
texlive-latex-recommended \
lmodern \
--fix-missing --no-install-recommends
# Yarn
RUN apt-get install -y nodejs npm --no-install-recommends
RUN npm install --global yarn
# ------------------------------------------------------------------------------
# Assets
# ------------------------------------------------------------------------------
FROM node:22.4.1-alpine as assets
ENV NODE_ENV ${NODE_ENV:-production}
RUN mkdir -p /deps/config/webpack
RUN mkdir -p /deps/script/assets
WORKDIR /deps
COPY yarn.lock /deps/yarn.lock
COPY package.json /deps/package.json
COPY script /deps/script
RUN yarn install
# ------------------------------------------------------------------------------
# Production Stage
# ------------------------------------------------------------------------------
FROM base AS app
ENV APP_HOME /srv/app
ENV RAILS_ENV ${RAILS_ENV:-production}
ENV PATH $PATH:/usr/local/bundle/bin:/usr/local/bin
RUN mkdir -p ${APP_HOME}/tmp/pids ${APP_HOME}/log
WORKDIR ${APP_HOME}
COPY Gemfile $APP_HOME/Gemfile
COPY Gemfile.lock $APP_HOME/Gemfile.lock
RUN bundle config set frozen true
RUN bundle config set no-cache true
RUN bundle config set without development test
RUN bundle install --no-binstubs --retry=10 --jobs=4
COPY config.ru ${APP_HOME}/config.ru
COPY Rakefile ${APP_HOME}/Rakefile
COPY public ${APP_HOME}/public
COPY bin ${APP_HOME}/bin
COPY script ${APP_HOME}/script
COPY lib ${APP_HOME}/lib
COPY config ${APP_HOME}/config
COPY db ${APP_HOME}/db
COPY app ${APP_HOME}/app
COPY yarn.lock ${APP_HOME}/yarn.lock
COPY package.json ${APP_HOME}/package.json
COPY babel.config.js ${APP_HOME}/babel.config.js
COPY .browserslistrc ${APP_HOME}/.browserslistrc
COPY --from=assets /deps/node_modules /srv/node_modules
COPY --from=assets /deps/node_modules $APP_HOME/node_modules
RUN yarn config set ignore-engines true
RUN RAILS_ENV=production SECRET_KEY_BASE=key bundle exec rake assets:precompile
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 3000
CMD ["bundle", "exec", "rails", "server"]
# ------------------------------------------------------------------------------
# Development Stage
# ------------------------------------------------------------------------------
FROM app as dev
RUN bundle config unset without
RUN bundle config set without test
RUN bundle install --no-binstubs --retry=10 --jobs=4
# ------------------------------------------------------------------------------
# Test Stage
# ------------------------------------------------------------------------------
FROM app as test
RUN bundle config unset without
RUN bundle config set without development
RUN bundle install --no-binstubs --retry=10 --jobs=4
RUN apt-get install -qq -y shellcheck wait-for-it iproute2
COPY .rubocop.yml ${APP_HOME}/.rubocop.yml
COPY .rubocop_todo.yml ${APP_HOME}/.rubocop_todo.yml
COPY knapsack_rspec_report.json ${APP_HOME}/knapsack_rspec_report.json
COPY .rspec ${APP_HOME}/.rspec
COPY spec ${APP_HOME}/spec