-
Notifications
You must be signed in to change notification settings - Fork 71
/
Dockerfile
74 lines (53 loc) · 2.13 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
ARG RUBY_VERSION=3.1.2
ARG IMAGE_FLAVOUR=slim-buster
FROM ruby:$RUBY_VERSION-$IMAGE_FLAVOUR AS assets
WORKDIR /app
ARG NODE_MAJOR=18
RUN bash -c "set -o pipefail && apt-get update \
&& apt-get install -y --no-install-recommends build-essential curl git libpq-dev \
&& curl -sSL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash - \
&& curl -sSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo 'deb https://dl.yarnpkg.com/debian/ stable main' | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y --no-install-recommends nodejs yarn \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& apt-get clean \
&& useradd --create-home ruby \
&& mkdir /node_modules && chown ruby:ruby -R /node_modules /app"
USER ruby
COPY --chown=ruby:ruby Gemfile* .ruby-version ./
RUN bundle install --jobs "$(nproc)"
COPY --chown=ruby:ruby package.json *yarn* ./
RUN yarn install
ARG RAILS_ENV="production"
ARG NODE_ENV="production"
ARG DEVISE_JWT_SECRET_KEY
ENV RAILS_ENV="${RAILS_ENV}" \
NODE_ENV="${NODE_ENV}" \
PATH="${PATH}:/home/ruby/.local/bin:/node_modules/.bin" \
USER="ruby"
COPY --chown=ruby:ruby . .
RUN if [ "${RAILS_ENV}" != "development" ]; then \
SECRET_KEY_BASE=irrelevant DEVISE_JWT_SECRET_KEY=irrelevant bundle exec rails assets:precompile; fi
CMD ["bash"]
###############################################################################
FROM ruby:$RUBY_VERSION-$IMAGE_FLAVOUR AS app
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential curl git libpq-dev \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& apt-get clean \
&& useradd --create-home ruby \
&& chown ruby:ruby -R /app
USER ruby
COPY --chown=ruby:ruby bin/ ./bin
RUN chmod 0755 bin/*
ARG RAILS_ENV="production"
ENV RAILS_ENV="${RAILS_ENV}" \
PATH="${PATH}:/home/ruby/.local/bin" \
USER="ruby"
COPY --chown=ruby:ruby --from=assets /usr/local/bundle /usr/local/bundle
COPY --chown=ruby:ruby --from=assets /app/public /public
COPY --chown=ruby:ruby . .
ENTRYPOINT ["/app/bin/docker-entrypoint-web"]
EXPOSE 3000
CMD ["rails", "s"]