This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
114 lines (94 loc) · 3.12 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
FROM ruby:3.0.1-alpine AS builder
LABEL maintainer="Mike Rogers <me@mikerogers.io>"
RUN apk --no-cache add --virtual build-dependencies \
build-base \
# Nokogiri Libraries
zlib-dev \
libxml2-dev \
libxslt-dev \
# PG
postgresql-dev \
# JavaScript
nodejs \
yarn \
# FFI Bindings in ruby (Run C Commands)
libffi-dev \
# Fixes watch file issues with things like HMR
libnotify-dev
RUN apk --no-cache add \
# ActiveStorage file inspection
file \
# Time zone data
tzdata \
# HTML to PDF conversion
# ttf-ubuntu-font-family \
# wkhtmltopdf \
# Image Resizing
imagemagick \
vips \
# Nice to have
bash \
git \
# VIM is a handy editor for editing credentials
vim \
# Allows for mimemagic gem to be installed
shared-mime-info
# Install any extra dependencies via Aptfile - These are installed on Heroku
COPY Aptfile /usr/src/app/Aptfile
RUN apk add --update $(cat /usr/src/app/Aptfile | xargs)
FROM builder AS development
# Set common ENVs
ENV BOOTSNAP_CACHE_DIR /usr/src/bootsnap
ENV YARN_CACHE_FOLDER /usr/src/yarn
ENV EDITOR vim
ENV LANG en_US.UTF-8
ENV BUNDLE_PATH /usr/local/bundle
ENV RAILS_LOG_TO_STDOUT enabled
ENV HISTFILE /usr/src/app/log/.bash_history
# Set build args. These let linux users not run into file permission problems
ARG USER_ID=${USER_ID:-1000}
ARG GROUP_ID=${GROUP_ID:-1000}
# Add non-root user and group with alpine first available uid, 1000
RUN addgroup -g $USER_ID -S appgroup \
&& adduser -u $GROUP_ID -S appuser -G appgroup
# Install multiple gems at the same time
RUN bundle config set jobs $(nproc)
# Create app directory in the conventional /usr/src/app
RUN mkdir -p /usr/src/app \
&& mkdir -p /usr/src/app/node_modules \
&& mkdir -p /usr/src/app/public/packs \
&& mkdir -p /usr/src/app/tmp/cache \
&& mkdir -p $YARN_CACHE_FOLDER \
&& mkdir -p $BOOTSNAP_CACHE_DIR \
&& chown -R appuser:appgroup /usr/src/app \
&& chown -R appuser:appgroup $BUNDLE_PATH \
&& chown -R appuser:appgroup $BOOTSNAP_CACHE_DIR \
&& chown -R appuser:appgroup $YARN_CACHE_FOLDER
WORKDIR /usr/src/app
ENV PATH /usr/src/app/bin:$PATH
# Define the user running the container
USER appuser
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"]
FROM development AS production
ENV RAILS_ENV production
ENV RACK_ENV production
ENV NODE_ENV production
COPY Gemfile /usr/src/app
COPY .ruby-version /usr/src/app
COPY Gemfile.lock /usr/src/app
# Install Ruby Gems
RUN bundle config set deployment 'true' \
&& bundle config set without 'development:test' \
&& bundle check || bundle install --jobs=$(nproc)
COPY package.json /usr/src/app
COPY yarn.lock /usr/src/app
# Install Yarn Libraries
RUN yarn install --check-files
# Chown files so non are root.
COPY --chown=appuser:appgroup . /usr/src/app
# Precompile the assets & bootsnap
RUN RAILS_SERVE_STATIC_FILES=enabled \
SECRET_KEY_BASE=secret-key-base \
bundle exec rake assets:precompile \
&& bundle exec bootsnap precompile --gemfile app/ lib/