-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dockerfile
94 lines (73 loc) · 2.58 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
# ---------------------------------------------------------
# Base Image
# ---------------------------------------------------------
FROM artsy/ruby:3.0.2-node-14-yarn as base
RUN apk update && apk --no-cache --quiet add --update \
git \
postgresql-dev \
tzdata \
&& adduser -D -g '' deploy
# support hokusai registry commands
# horizon needs to compare production/staging envs of projects
RUN apk update && apk --no-cache --quiet add --update \
build-base \
openssl-dev \
python3-dev \
py3-pip
RUN pip3 install --upgrade --no-cache-dir pip \
&& pip3 install --upgrade --no-cache-dir hokusai --ignore-installed
# ---------------------------------------------------------
# Build Image
# ---------------------------------------------------------
FROM base AS builder
ENV LANG C.UTF-8
ENV PORT 3000
EXPOSE 3000
RUN apk update && apk --no-cache --quiet add --update \
build-base \
postgresql-client
RUN gem install bundler -v '<2' && \
bundle config --global frozen 1
WORKDIR /app
RUN chown deploy:deploy $(pwd)
RUN chown -R deploy:deploy /usr/local
USER deploy
# Set up gems
# TODO: look into buildkit to prevent re-installing node modules after changing gems
COPY --chown=deploy:deploy Gemfile Gemfile.lock ./
# RUN bundle install -j4 --path /usr/local/bundle-prod --without development test && \
RUN bundle install -j4 --path /usr/local/bundle
# bundle clean
# Set up packages, empty cache to save space
COPY --chown=deploy:deploy package.json yarn.lock ./
RUN yarn install --frozen-lockfile --quiet && \
yarn cache clean --force
# Copy application code
COPY --chown=deploy:deploy . ./
# Precompile Rails assets
RUN bundle exec rake assets:precompile
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
# ---------------------------------------------------------
# Production Image
# ---------------------------------------------------------
FROM base AS production
ENV PORT 3000
EXPOSE 3000
WORKDIR /app
RUN apk update && apk --no-cache --quiet add --update \
dumb-init
# copy app files
COPY --chown=deploy:deploy --from=builder /app .
# copy gems
COPY --chown=deploy:deploy --from=builder /usr/local/bundle /usr/local/bundle
# Create directories for Puma/Nginx & give deploy user access
RUN mkdir -p /shared/pids /shared/sockets && \
chown -R deploy:deploy /shared
# Create directories for cron.
RUN mkdir /home/deploy/data && \
chown -R deploy:deploy /home/deploy/data
# TODO: dump dev bundle
RUN rm -rf node_modules
USER deploy
ENTRYPOINT ["/usr/bin/dumb-init", "./scripts/load_secrets_and_run.sh"]
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]