-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
78 lines (53 loc) · 1.84 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
# ****************************
# ******Build base stage******
# ****************************
FROM node:10.16.3-slim as nodejs
FROM ruby:2.5.6-slim as builder
# Install common libs
RUN apt-get update -qq && apt-get install -y \
build-essential vim git
# Install Postgresql
RUN apt-get install -y postgresql-client libpq-dev
# Install Nodejs
ENV NODE_VERSION=10.16.3
COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
WORKDIR /app
# Production config
ARG BUNDLE_DEPLOYMENT=true
ARG BUNDLE_WITHOUT="development test staging"
ARG NODE_ENV=production
ENV BUNDLE_DEPLOYMENT=$BUNDLE_DEPLOYMENT BUNDLE_WITHOUT=$BUNDLE_WITHOUT
ENV NODE_ENV=$NODE_ENV
# Gems cache layer
COPY Gemfile Gemfile.lock /app/
RUN bundle install -j 4
# Node modules cache layer
COPY package.json package-lock.json /app/
RUN npm ci
COPY . .
CMD "./entrypoint.sh"
# ****************************
# ******Production stage******
# ****************************
FROM builder as production-builder
ENV NODE_ENV=production RAILS_ENV=production
# Build production assets
RUN bundle exec rails assets:precompile
RUN rm -r node_modules
# **********************************
# ******Final production Stage******
# **********************************
FROM ruby:2.5.6-slim
ENV NODE_ENV=production RAILS_ENV=production RAILS_LOG_TO_STDOUT=true
# Install system dependencies
COPY --from=nodejs /usr/local/ /usr/local/
RUN apt-get update -qq && apt-get install -y \
libpq-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN groupadd -r deploy && useradd -r -g deploy deploy
USER deploy
COPY --from=production-builder --chown=deploy:deploy /usr/local/bundle /usr/local/bundle
COPY --from=production-builder --chown=deploy:deploy /app /app
CMD [ "sh", "-c", "bundle exec rake db:create db:migrate && bundle exec rails server -b 0.0.0.0" ]