Upgrade to Ruby 2.4.2.
[discourse_docker.git] / image / base / Dockerfile
1 # NAME: discourse/base
2 # VERSION: release
3 FROM ubuntu:16.04
4
5 ENV PG_MAJOR 9.5
6 ENV RUBY_ALLOCATOR /usr/lib/libjemalloc.so.1
7 ENV COMPRESS_BROTLI 1
8
9 MAINTAINER Sam Saffron "https://twitter.com/samsaffron"
10
11 RUN echo 2.0.`date +%Y%m%d` > /VERSION
12
13 RUN apt-get update && apt-get install -y lsb-release sudo curl
14 RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections
15 RUN echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main restricted universe" > /etc/apt/sources.list
16 RUN echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-updates main restricted universe" >> /etc/apt/sources.list
17 RUN echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-security main restricted universe" >> /etc/apt/sources.list
18 RUN apt-get update && apt-get -y install fping
19 RUN sh -c "fping proxy && echo 'Acquire { Retries \"0\"; HTTP { Proxy \"http://proxy:3128\";}; };' > /etc/apt/apt.conf.d/40proxy && apt-get update || true"
20 RUN apt-get -y install software-properties-common
21 RUN apt-mark hold initscripts
22 RUN apt-get -y upgrade
23 RUN curl http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
24 RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main" | \
25 tee /etc/apt/sources.list.d/postgres.list
26 RUN curl --silent --location https://deb.nodesource.com/setup_8.x | sudo bash -
27 RUN apt-get -y update
28 RUN apt-get -y install build-essential git wget \
29 libxslt-dev libcurl4-openssl-dev \
30 libssl-dev libyaml-dev libtool \
31 libxml2-dev gawk parallel \
32 postgresql-${PG_MAJOR} postgresql-client-${PG_MAJOR} \
33 postgresql-contrib-${PG_MAJOR} libpq-dev libreadline-dev \
34 language-pack-en cron anacron \
35 psmisc rsyslog vim whois brotli libunwind-dev
36 RUN sed -i -e 's/start -q anacron/anacron -s/' /etc/cron.d/anacron
37 RUN sed -i.bak 's/$ModLoad imklog/#$ModLoad imklog/' /etc/rsyslog.conf
38 RUN dpkg-divert --local --rename --add /sbin/initctl
39 RUN sh -c "test -f /sbin/initctl || ln -s /bin/true /sbin/initctl"
40 RUN apt-get -y install redis-server haproxy openssh-server
41 RUN cd / &&\
42 apt-get -y install runit monit socat &&\
43 mkdir -p /etc/runit/1.d &&\
44 apt-get clean &&\
45 rm -f /etc/apt/apt.conf.d/40proxy &&\
46 locale-gen en_US &&\
47 apt-get install -y nodejs &&\
48 npm install -g uglify-js@"<3" &&\
49 npm install svgo -g
50
51 ADD install-nginx /tmp/install-nginx
52 RUN /tmp/install-nginx
53
54 RUN apt-get -y install advancecomp jhead jpegoptim libjpeg-turbo-progs optipng
55
56
57 RUN mkdir /jemalloc-stable && cd /jemalloc-stable &&\
58 wget https://github.com/jemalloc/jemalloc/releases/download/3.6.0/jemalloc-3.6.0.tar.bz2 &&\
59 tar -xjf jemalloc-3.6.0.tar.bz2 && cd jemalloc-3.6.0 && ./configure --prefix=/usr && make && make install &&\
60 cd / && rm -rf /jemalloc-stable
61
62 RUN mkdir /jemalloc-new && cd /jemalloc-new &&\
63 wget https://github.com/jemalloc/jemalloc/releases/download/5.0.1/jemalloc-5.0.1.tar.bz2 &&\
64 tar -xjf jemalloc-5.0.1.tar.bz2 && cd jemalloc-5.0.1 && ./configure --prefix=/usr --with-install-suffix=5.0.1 && make build_lib && make install_lib &&\
65 cd / && rm -rf /jemalloc-new
66
67 RUN mkdir /gperftools && git clone https://github.com/gperftools/gperftools.git /gperftools &&\
68 cd /gperftools && git checkout gperftools-2.5 && ./autogen.sh && ./configure --prefix=$PWD/lib &&\
69 make install && mv lib/lib/libtcmalloc_minimal.so.4.3.0 /usr/lib && cd / && rm -rf /gperftools
70
71 RUN mkdir /lockless && cd /lockless && curl -O https://locklessinc.com/downloads/lockless_allocator_linux.tgz &&\
72 tar zxf lockless_allocator_linux.tgz && mv lockless_allocator_linux/64bit/libllalloc.so.1.4 /usr/lib &&\
73 cd / && rm -rf /lockless
74
75 ADD rb_thread_fd_close.patch /tmp/rb_thread_fd_close.patch
76 RUN echo 'gem: --no-document' >> /usr/local/etc/gemrc &&\
77 mkdir /src && cd /src && git clone https://github.com/sstephenson/ruby-build.git &&\
78 cd /src/ruby-build && ./install.sh &&\
79 cd / && rm -rf /src/ruby-build && (ruby-build 2.4.2 /usr/local --patch << /tmp/rb_thread_fd_close.patch)
80
81 RUN gem update --system
82
83 RUN gem install bundler &&\
84 rm -rf /usr/local/share/ri/2.4.2/system &&\
85 cd / && git clone https://github.com/SamSaffron/pups.git
86
87 ADD install-imagemagick /tmp/install-imagemagick
88 RUN /tmp/install-imagemagick
89
90 # Validate install
91 RUN ruby -Eutf-8 -e "v = \`convert -version\`; %w{png tiff jpeg freetype}.each { |f| unless v.include?(f); STDERR.puts('no ' + f + ' support in imagemagick'); exit(-1); end }"
92
93 ADD install-pngcrush /tmp/install-pngcrush
94 RUN /tmp/install-pngcrush
95
96 ADD install-gifsicle /tmp/install-gifsicle
97 RUN /tmp/install-gifsicle
98
99 ADD install-pngquant /tmp/install-pngquant
100 RUN /tmp/install-pngquant
101
102 ADD phantomjs /usr/local/bin/phantomjs
103
104 # Not using the official repo until they compile against a recent openssl
105 # RUN cd tmp && wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
106 # RUN cd tmp && tar jxf phantomjs-2.1.1-linux-x86_64.tar.bz2 && mv /tmp/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin
107
108 # clean up for docker squash
109 RUN rm -fr /usr/share/man &&\
110 rm -fr /usr/share/doc &&\
111 rm -fr /usr/share/vim/vim74/tutor &&\
112 rm -fr /usr/share/vim/vim74/doc &&\
113 rm -fr /usr/share/vim/vim74/lang &&\
114 rm -fr /usr/local/share/doc &&\
115 rm -fr /usr/local/share/ruby-build &&\
116 rm -fr /root/.gem &&\
117 rm -fr /root/.npm &&\
118 rm -fr /tmp/* &&\
119 rm -fr /usr/share/vim/vim74/spell/en*
120
121
122 # this can probably be done, but I worry that people changing PG locales will have issues
123 # cd /usr/share/locale && rm -fr `ls -d */ | grep -v en`
124
125 RUN mkdir -p /etc/runit/3.d
126
127 ADD runit-1 /etc/runit/1
128 ADD runit-1.d-cleanup-pids /etc/runit/1.d/cleanup-pids
129 ADD runit-1.d-anacron /etc/runit/1.d/anacron
130 ADD runit-1.d-00-fix-var-logs /etc/runit/1.d/00-fix-var-logs
131 ADD runit-2 /etc/runit/2
132 ADD runit-3 /etc/runit/3
133 ADD boot /sbin/boot
134
135 ADD cron /etc/service/cron/run
136 ADD rsyslog /etc/service/rsyslog/run
137 ADD cron.d_anacron /etc/cron.d/anacron
138
139
140 # Discourse specific bits
141 RUN useradd discourse -s /bin/bash -m -U &&\
142 mkdir -p /var/www &&\
143 cd /var/www &&\
144 git clone https://github.com/discourse/discourse.git &&\
145 cd discourse &&\
146 git remote set-branches --add origin tests-passed &&\
147 chown -R discourse:discourse /var/www/discourse &&\
148 cd /var/www/discourse &&\
149 sudo -u discourse bundle install --deployment \
150 --without test --without development &&\
151 find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} +