-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
135 lines (104 loc) · 3.53 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
127
128
129
130
131
132
133
134
135
ARG RUBY_VERSION=2.7.8
ARG RUBY_SLIM="-slim"
FROM ruby:${RUBY_VERSION}${RUBY_SLIM} AS base
ARG UNAME=app
ARG UID=1000
ARG GID=1000
ARG ARCH=amd64
ARG BUNDLER_VERSION=2.4.22
ARG NODE_VERSION=20
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' \
> /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && apt-get --no-install-recommends install -yq \
apt-transport-https \
build-essential \
curl \
git \
unzip \
libpq-dev \
##### FIXME: remove these once useless gems are trimmed \
libmariadb-dev \
libsqlite3-dev \
##### What is netcat here for???
netcat
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \
--mount=type=cache,sharing=locked,target=/var/lib/apt \
curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh && \
chmod 500 nsolid_setup_deb.sh && \
./nsolid_setup_deb.sh ${NODE_VERSION} && \
apt-get install nodejs -yq
RUN gem install bundler:${BUNDLER_VERSION}
RUN groupadd -g $GID -o $UNAME
RUN useradd -m -d /opt/app -u $UID -g $GID -o -s /bin/bash $UNAME
ENV RAILS_LOG_TO_STDOUT true
WORKDIR /opt/app
COPY Gemfile* .
#############
FROM base AS base-dev
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \
--mount=type=cache,sharing=locked,target=/var/lib/apt \
apt-get --no-install-recommends install -yq \
fd-find \
less \
ripgrep \
vim-tiny
############
FROM base AS gems-prod
RUN --mount=type=cache,id=med-bundle-prod,sharing=locked,target=/vendor/bundle \
--mount=type=cache,sharing=locked,target=/vendor/cache \
bundle config set path /vendor/bundle && \
bundle config set cache_path /vendor/cache && \
bundle config set cache_all true && \
bundle config set without 'development test' && \
bundle config build.sassc --disable-march-tune-native && \
bundle cache --no-install && \
bundle install --local && \
bundle clean && \
bundle config unset cache_path && \
bundle config set path /gems && \
mkdir -p /gems && \
cp -ar /vendor/bundle/* /gems
#############
FROM base-dev AS gems-dev
RUN --mount=type=cache,id=med-bundle-dev,sharing=locked,target=/vendor/bundle \
--mount=type=cache,sharing=locked,target=/vendor/cache \
bundle config set path /vendor/bundle && \
bundle config set cache_path /vendor/cache && \
bundle config set cache_all true && \
bundle cache --no-install && \
bundle config build.sassc --disable-march-tune-native && \
bundle install --local && \
bundle clean && \
bundle config unset cache_path && \
bundle config set path /gems && \
mkdir -p /gems && \
cp -ar /vendor/bundle/* /gems
#############
FROM gems-prod AS production
ARG RAILS_RELATIVE_URL_ROOT
COPY . .
RUN chown -R ${UID}:${GID} /gems && chown -R ${UID}:${GID} /opt/app
EXPOSE 3000
USER $UNAME
### temporarily required to start up/precompile
ENV SOLR_ROOT=bogus
ENV SOLR_COLLECTION=bogus
###
ENV RAILS_ENV production
ENV RAILS_SERVE_STATIC_FILES true
ENV SECRET_KEY_BASE 121222bccca
ENV RAILS_RELATIVE_URL_ROOT=${RAILS_RELATIVE_URL_ROOT}
RUN bin/rails assets:precompile
CMD ["bin/rails", "s", "-b", "0.0.0.0"]
############
FROM gems-dev AS development
COPY . .
RUN chown -R ${UID}:${GID} /gems && chown -R ${UID}:${GID} /opt/app
RUN bundle config build.sassc --disable-march-tune-native
RUN bundle config set path /gems
EXPOSE 3000
USER $UNAME
CMD ["bin/rails", "s", "-b", "0.0.0.0"]