forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.template
130 lines (116 loc) · 4.27 KB
/
Dockerfile.template
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
<%= generation_message %>
# See doc/docker/README.md or https://github.com/instructure/canvas-lms/tree/master/doc/docker
FROM instructure/ruby-passenger:2.4-xenial
ENV APP_HOME /usr/src/app/
ENV RAILS_ENV "production"
ENV NGINX_MAX_UPLOAD_SIZE 10g
ENV YARN_VERSION 1.12.3-1
# Work around github.com/zertosh/v8-compile-cache/issues/2
# This can be removed once yarn pushes a release including the fixed version
# of v8-compile-cache.
ENV DISABLE_V8_COMPILE_CACHE 1
USER root
WORKDIR /root
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& printf 'path-exclude /usr/share/doc/*\npath-exclude /usr/share/man/*' > /etc/dpkg/dpkg.cfg.d/01_nodoc \
<% unless production? -%>
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
<% end -%>
&& apt-get update -qq \
&& apt-get install -qqy --no-install-recommends \
nodejs \
yarn="$YARN_VERSION" \
libxmlsec1-dev \
python-lxml \
libicu-dev \
<% unless production? -%>
postgresql-client-9.5 \
unzip \
fontforge \
<% end -%>
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /home/docker/.gem/ruby/$RUBY_MAJOR.0
RUN if [ -e /var/lib/gems/$RUBY_MAJOR.0/gems/bundler-* ]; then BUNDLER_INSTALL="-i /var/lib/gems/$RUBY_MAJOR.0"; fi \
&& gem uninstall --all --ignore-dependencies --force $BUNDLER_INSTALL bundler \
&& gem install bundler --no-document -v 1.16.1 \
&& find $GEM_HOME ! -user docker | xargs chown docker:docker
<% if development? -%>
# We will need sfnt2woff in order to build fonts
COPY build/vendor/woff-code-latest.zip ./
RUN unzip woff-code-latest.zip -d woff \
&& cd woff \
&& make \
&& cp sfnt2woff /usr/local/bin \
&& cd - \
&& rm -rf woff*
<% end -%>
WORKDIR $APP_HOME
<% if production? -%>
COPY . $APP_HOME
# optimizing for size here ... get all the dev dependencies so we can
# compile assets, then throw away everything we don't need
#
# the privilege dropping could be slightly less verbose if we ever add
# gosu (here or upstream)
#
# TODO: once we have docker 17.05+ everywhere, do this via multi-stage
# build
RUN bash -c ' \
# bash cuz better globbing and comments \
set -e; \
\
sudo -u docker -E env HOME=/home/docker PATH=$PATH bundle install --jobs 8; \
yarn install --pure-lockfile; \
COMPILE_ASSETS_NPM_INSTALL=0 bundle exec rake canvas:compile_assets; \
\
# downgrade to prod dependencies \
sudo -u docker -E env HOME=/home/docker PATH=$PATH bundle install --without test development; \
sudo -u docker -E env HOME=/home/docker PATH=$PATH bundle clean --force; \
yarn install --prod; \
\
# now some cleanup... \
rm -rf \
/home/docker/.bundle/cache \
$GEM_HOME/cache \
$GEM_HOME/bundler/gems/*/{.git,spec,test,features} \
$GEM_HOME/gems/*/{spec,test,features} \
`yarn cache dir` \
/root/.node-gyp \
/tmp/phantomjs \
.yardoc \
client_apps/canvas_quizzes/{tmp,node_modules} \
config/locales/generated \
gems/*/node_modules \
gems/plugins/*/node_modules \
log \
public/dist/maps \
public/doc/api/*.json \
public/javascripts/translations \
tmp-*.tmp'
USER docker
<% else -%>
COPY Gemfile ${APP_HOME}
COPY Gemfile.d ${APP_HOME}Gemfile.d
COPY config ${APP_HOME}config
COPY gems ${APP_HOME}gems
COPY packages ${APP_HOME}packages
COPY script ${APP_HOME}script
COPY package.json ${APP_HOME}
COPY yarn.lock ${APP_HOME}
RUN find gems packages -type d ! -user docker -print0 | xargs -0 chown -h docker:docker
# Install deps as docker to avoid sadness w/ npm lifecycle hooks
USER docker
RUN bundle install --jobs 8 \
&& yarn install --pure-lockfile
USER root
COPY . $APP_HOME
RUN mkdir -p <%= docker_compose_volume_paths.join(" \\\n ") %> \
&& find ${APP_HOME} /home/docker ! -user docker -print0 | xargs -0 chown -h docker:docker
USER docker
# TODO: switch to canvas:compile_assets_dev once we stop using this Dockerfile in production/e2e
RUN COMPILE_ASSETS_NPM_INSTALL=0 bundle exec rake canvas:compile_assets
<% end -%>