This repository has been archived by the owner on Oct 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DockerfileForCartoBuilder
366 lines (325 loc) · 12.9 KB
/
DockerfileForCartoBuilder
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# vim:set filetype=dockerfile:
FROM ubuntu:16.04
# CartoDB installations assume UTF-8. Configure locales accordingly:
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update &&\
apt-get install -y \
locales \
apt-utils &&\
dpkg-reconfigure locales &&\
locale-gen en_US.UTF-8 &&\
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# 1. Create a 'cartodb' user.
# 2. Update apt-get and install various utils and build tools.
# See http://cartodb.readthedocs.io/en/latest/install.html
# NOTE that PostgreSQL is NOT installed into this container.
RUN useradd -m -d /home/cartodb -s /bin/bash cartodb &&\
apt-get install -y --no-install-recommends \
# This is needed for add-apt-repository.
# See http://unix.stackexchange.com/a/45905/18918
software-properties-common \
# Carto maintains packaged versions of almost every part of the stack,
# but there are some parts like gems and npm packages that need
# these dev tools to be system installed in order to compile.
autoconf \
binutils-doc \
bison \
build-essential \
checkinstall \
flex \
# These packages are needed for Ruby and the rvm installation.
gnupg \
libreadline6 \
libreadline6-dev \
openssl \
# Tools to grab sources...
wget \
git \
# Vim and ping for troubleshooting containers.
vim \
iputils-ping
# I don't know that these are needed. They are
# from https://github.com/sverhoeven/docker-cartodb/blob/master/Dockerfile
# which does not document why they are included, but I don't have
# time right now to look into each one.
RUN apt-get install -y --no-install-recommends \
make \
ca-certificates \
curl \
libc6-dev \
libcurl4-gnutls-dev \
libffi-dev \
libgdbm-dev \
libgmp-dev \
libjpeg8-dev \
libmapnik-dev \
libsqlite3-dev \
libssl-dev \
libtool \
libxml2-dev \
libxslt-dev \
libyaml-dev \
mapnik-utils \
ncurses-dev \
net-tools \
nginx-light \
pkg-config \
zlib1g \
zlib1g-dev
# These configs improve bash and Vim.
# COPY ["db/dotfiles/*","/root/"]
# COPY ["db/dotfiles/*","/home/carto/"]
# Varnish 3, Ubuntu:16.04 comes with Varnish 4.1 which can't be run with anonymous admin telnet
RUN cd /opt &&\
wget http://varnish-cache.org/_downloads/varnish-3.0.7.tgz &&\
tar -zxf varnish-3.0.7.tgz &&\
cd varnish-3.0.7 &&\
./configure --prefix=/opt/varnish &&\
make &&\
make install &&\
cd /opt &&\
rm -rf varnish-3.0.7 varnish-3.0.7.tgz
# # ogr2ogr2 static build, see https://github.com/CartoDB/cartodb/wiki/How-to-build-gdal-and-ogr2ogr2
# # Using cartodb instruction got error https://trac.osgeo.org/gdal/ticket/6073
# # https://github.com/OSGeo/gdal/compare/trunk...CartoDB:ogr2ogr2 has no code
# # changes, so just use latest gdal tarball.
# RUN cd /opt &&\
# curl http://download.osgeo.org/gdal/2.1.1/gdal-2.1.1.tar.gz -o gdal-2.1.1.tar.gz && \
# tar -zxf gdal-2.1.1.tar.gz &&\
# cd gdal-2.1.1 &&\
# ./configure --disable-shared &&\
# make -j 4 &&\
# cp apps/ogr2ogr /usr/bin/ogr2ogr2 &&\
# cd /opt &&\
# rm -rf /opt/ogr2ogr2 /opt/gdal-2.1.1.tar.gz /root/.gitconfig /opt/gdal-2.1.1
# Add Postgres 10 for Ubuntu 16.04
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' >> /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - &&\
apt-get update
RUN add-apt-repository ppa:cartodb/gis &&\
apt-get update
RUN apt-get install -y \
gdal-bin \
libgdal-dev \
# These dev libraries will be necessary to build some Node modules...
libpixman-1-0 \
libpixman-1-dev \
libcairo2-dev \
libjpeg-dev \
libgif-dev \
libpango1.0-dev \
# Install docs describe these as "Ruby dependencies"...
# https://cartodb.readthedocs.io/en/latest/install.html
imagemagick \
libicu-dev \
# Install Proj4 for reprojection support.
proj-bin \
proj-data \
libproj-dev \
# Install this stuff for JSON/GeoJSON support.
libjson0 \
libjson0-dev \
python-simplejson \
# Install GEOS for geometry function support.
libgeos-c1v5 \
libgeos-dev \
# Install the Postgres *client* software.
# This does not install the full database server.
libpq-dev \
libpq5 \
postgresql-client-10 \
# These are used by the CartoDB editor...
# unp is required for archive file upload support
unp \
# zip is required for table exports
zip \
unzip \
# tcpflow for troubleshooting, https://askubuntu.com/a/654993/17122
tcpflow \
# gnupg2 is needed to verify the RVM PGP signature
# https://github.com/rvm/rvm/blob/master/scripts/functions/cli#L207
gnupg2 \
# Other stuff in https://github.com/sverhoeven/docker-cartodb/blob/master/Dockerfile
liblwgeom-2.2-5
# Carto needs NodeJS 6.9.2 and npm 3.10.9
# http://cartodb.readthedocs.io/en/latest/install.html#nodejs
RUN curl https://nodejs.org/download/release/v6.9.2/node-v6.9.2-linux-x64.tar.gz| tar -zxf - --strip-components=1 -C /usr
# Grunt is used to run a task which precompiles assets.
# Needed if you don’t want to use CARTO’s CDN for assets.
RUN npm install --global grunt-cli
# Grab the source code
# Change the version message if you change the changeset ID!
RUN git clone --recursive https://github.com/CartoDB/cartodb.git &&\
cd /cartodb &&\
echo "Checking out CartoDB 4.20.2 (4cff80aa1)..." &&\
git checkout 4cff80aa1310777e46a64d087a4afe4cc4bbdffa &&\
git submodule update --init
# This installs all the CartoDB Node packages.
# Keep it as a separate cachable layer for now.
RUN cd /cartodb &&\
npm install &&\
rm -rf /tmp/npm-* /root/.npm
# Compile static assets
RUN cd /cartodb &&\
npm run carto-node &&\
npm run build:static
# CartoDB Builder/Editor is a Ruby on Rails app.
# RAILS_ENV changes how this image is built.
# Notes on production...
# - https://github.com/danseely/cartodb-install/blob/master/PRODUCTION-DEPLOY.md
# Also note that the app will not fully use HTTPS unless "staging" or "production"
# - https://groups.google.com/forum/#!topic/cartodb/XBqDVXgzZOc
# - https://github.com/CartoDB/cartodb/blob/37221b7521/config/initializers/carto_db.rb#L236
# When RAILS_ENV="development" for Carto Builder,
# user databases are found via 'cartodb_user_<%= user_id %>'
ENV RAILS_ENV="production"
# Install Python requirements
RUN apt-get install -y \
python-pip \
python-all-dev \
python-gdal &&\
# Clear the cache.
echo "Clearing the apt-get cache..." &&\
rm -rf /var/lib/apt/lists/*
# See https://github.com/CartoDB/cartodb/blob/master/python_requirements.txt
# chardet==2.3.0
# argparse==1.2.1
# brewery==0.6
# redis==2.4.9
# python-varnish==0.1.2
# gdal==2.2.2
# csvkit==0.9.0
# openpyxl==2.1.3
RUN cd /cartodb &&\
export CPLUS_INCLUDE_PATH=/usr/include/gdal &&\
export C_INCLUDE_PATH=/usr/include/gdal &&\
export PATH=$PATH:/usr/include/gdal &&\
pip install -r python_requirements.txt &&\
rm -rf /root/.cache/pip
# 1. Use a local copy of the RVM PGP key because:
# * Keyservers don't have 100% uptime and
# * HKP default port 11371 is firewall blocked in some environments
# Docker does this too, see https://github.com/docker/docker/pull/29967
# 2. Run `gpg --dry-run --import mpapis.asc` if you want to compare and verify
# its fingerprint against https://rvm.io/rvm/install#install-gpg-keys
# 3. The key expires 2019-03-09
# COPY ./mpapis.asc /tmp/mpapis.asc
## Install Ruby via RVM.
#RUN gpg --import /tmp/mpapis.asc &&\
# ################################################################
# # TEMP WORK-AROUND: See https://github.com/rvm/rvm/issues/4136 #
# # Use https://get.rvm.io when possible. #
# ################################################################
# curl -sSL https://raw.githubusercontent.com/wayneeseguin/rvm/stable/binscripts/rvm-installer \
# | bash -s stable --ruby
# # curl -sSL https://get.rvm.io | bash -s stable --ruby
#RUN echo 'source /usr/local/rvm/scripts/rvm' >> /etc/bash.bashrc &&\
# /bin/bash -l -c rvm requirements
#RUN echo rvm_max_time_flag=15 >> ~/.rvmrc
## Use version 2.2.10, https://github.com/sverhoeven/docker-cartodb/issues/49
#RUN /bin/bash -l -c 'rvm install 2.2.10' &&\
# /bin/bash -l -c 'rvm use 2.2.10 --default' &&\
# /bin/bash -l -c 'gem install bundle archive-tar-minitar' &&\
# ln -s /usr/local/rvm/rubies/ruby-2.2.10/bin/ruby /usr/bin && \
# rm -rf /usr/local/rvm/src
RUN apt-add-repository ppa:brightbox/ruby-ng &&\
apt-get update &&\
apt-get install -y \
ruby2.2 \
ruby2.2-dev \
ruby-bundler
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Add time zone data because of a Ubuntu 16.04 bug
# https://stackoverflow.com/questions/40234847/docker-timezone-in-ubuntu-16-04-image
# Rake will otherwise fail with TZInfo::DataSourceNotFound
ENV TZ 'America/Chicago'
RUN echo $TZ > /etc/timezone &&\
apt-get install -y tzdata &&\
rm /etc/localtime &&\
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime &&\
dpkg-reconfigure -f noninteractive tzdata &&\
apt-get clean
# Bundler is an app used to manage ruby dependencies.
# It is needed by CartoDB’s editor.
# RUN /bin/bash -l -c 'gem install bundler'
# Compass is also used by CartoDB's editor.
RUN /bin/bash -l -c 'gem install compass'
# Rake commands are aborted without tzinfo-data
RUN /bin/bash -l -c 'gem install tzinfo-data'
# Install the Carto Builder/Editor
RUN cd /cartodb &&\
# /bin/bash -l -c 'bundle update thin' &&\
/bin/bash -l -c 'bundle install'
# For now, the dev settings are fine for our staging and production builds.
# For example, the staging and prod configs (which we overwrite) tell
# the Rails server to not serve static assets, but we don't have a CDN
# or webserver to take it's place, so we want to use Rails for that!
# https://github.com/CartoDB/cartodb/blob/master/config/environments/staging.rb#L39
#
# TODO: Revisit this when we actually go live in production.
RUN cp /cartodb/config/grunt_development.json \
/cartodb/config/grunt_staging.json &&\
cp /cartodb/config/grunt_development.json \
/cartodb/config/grunt_production.json &&\
cp /cartodb/config/environments/development.rb \
/cartodb/config/environments/staging.rb &&\
cp /cartodb/config/environments/development.rb \
/cartodb/config/environments/production.rb
# Grunt reads the Node environment
ENV NODE_ENV="development"
# Running grunt will build all static assets into public/assets/:version
# We do this so assets can be sourced locally and not from Carto's CDN.
RUN export PATH=$PATH:/cartodb/node_modules/grunt-cli/bin
RUN cd /cartodb &&\
/bin/bash -l -c grunt
ENV GDAL_DATA /usr/share/gdal/2.2
# This is a bit of a hack...
# We don't install the observatory-extension in this container, but we do have
# a script (geocoder.sh) that reads src/pg/test/fixtures/load_fixtures.sql
# It runs from this container, therefore we clone to get that single file.
RUN cd / &&\
git clone --recursive https://github.com/CartoDB/observatory-extension.git &&\
cd /observatory-extension &&\
# Change the message if you change the changeset ID!
# Keep this in sync with the changeset ID in DockerfileForCartoPostgres
echo "Checking out 8acd5d3 (release 1.9.0+) ..." &&\
git checkout 8acd5d39b6bffc97949b2431957f6450c870a32e
# TODO: Remove users_modifications?
RUN mkdir -p /cartodb/log &&\
touch /cartodb/log/users_modifications
COPY ./carto/config/app_config.yml \
/cartodb/config/app_config.yml
COPY ./carto/config/app_config.aws.yml \
/cartodb/config/app_config.aws.yml
COPY ./carto/config/database.yml \
/cartodb/config/database.yml
COPY ./carto/create_dev_user \
/cartodb/script/create_dev_user
COPY ./carto/setup_organization.sh \
/cartodb/script/setup_organization.sh
COPY ./carto/geocoder.sh \
/cartodb/script/geocoder.sh
COPY ./carto/geocoder_server.sql \
/cartodb/script/geocoder_server.sql
COPY ./carto/fill_geocoder.sh \
/cartodb/script/fill_geocoder.sh
COPY ./carto/config/varnish.vcl \
/etc/varnish.vcl
# Number of seconds between sync tables tasks.
# Default is 1hr, use `docker run -e SYNC_TABLES_INTERVAL=60 ...` to change it.
ENV SYNC_TABLES_INTERVAL 3600
COPY ./carto/sync_tables_trigger.sh \
/cartodb/script/sync_tables_trigger.sh
RUN chmod +x /cartodb/script/create_dev_user && \
chmod +x /cartodb/script/setup_organization.sh && \
chmod +x /cartodb/script/fill_geocoder.sh && \
chmod +x /cartodb/script/sync_tables_trigger.sh
# The Rails app will run on 3000.
# Varnish will be accessible on 6081 and 6082 (Windshaft Maps API uses it).
EXPOSE 3000 6081 6082
COPY ./carto/startup.sh \
/opt/startup.sh
CMD ["/bin/bash", "/opt/startup.sh"]