From 810e17c588d926d1154cffcc5396b79330fe121b Mon Sep 17 00:00:00 2001 From: pierreozoux Date: Tue, 11 Feb 2020 17:13:35 +0100 Subject: [PATCH] Improves the docker build. --- .gitlab-ci.yml | 57 +++++++++++ Dockerfile | 113 ++++++++++----------- install-gifsicle | 11 -- install-pngquant | 8 -- install/gifsicle | 9 ++ install-imagemagick => install/imagemagick | 18 ++-- install/plugin-list | 5 + install-pngcrush => install/pngcrush | 4 +- install/pngquant | 7 ++ 9 files changed, 142 insertions(+), 90 deletions(-) create mode 100644 .gitlab-ci.yml delete mode 100755 install-gifsicle delete mode 100755 install-pngquant create mode 100755 install/gifsicle rename install-imagemagick => install/imagemagick (77%) create mode 100644 install/plugin-list rename install-pngcrush => install/pngcrush (89%) create mode 100755 install/pngquant diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..956af63 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +variables: + GIT_SUBMODULE_STRATEGY: recursive + DOCKER_HUB_REPO: libresh/discourse + +test-beta: + tags: + - build + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + script: + - export DISCOURSE_VERSION=`wget -qO- https://api.github.com/repos/discourse/discourse/tags | grep name | cut -d'"' -f4 | grep beta | head -n1` + - /kaniko/executor --context . --no-push --build-arg DISCOURSE_VERSION=$DISCOURSE_VERSION + except: + - master + +test-stable: + tags: + - build + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + script: + - export DISCOURSE_VERSION=`wget -qO- https://api.github.com/repos/discourse/discourse/tags | grep name | cut -d'"' -f4 | grep -v beta | head -n1` + - /kaniko/executor --context . --no-push --build-arg DISCOURSE_VERSION=$DISCOURSE_VERSION + except: + - master + +build-beta: + tags: + - build + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + script: + - cp $DOCKER_SECRET_CONFIG /kaniko/.docker/config.json + - export DISCOURSE_VERSION=`wget -qO- https://api.github.com/repos/discourse/discourse/tags | grep name | cut -d'"' -f4 | grep beta | head -n1` + - export DISCOURSE_MAJOR=`echo $DISCOURSE_VERSION | cut -d"." -f1-3` + - export DESTINATION="--destination ${DOCKER_HUB_REPO}:${DISCOURSE_VERSION} --destination ${DOCKER_HUB_REPO}:${DISCOURSE_MAJOR} --destination ${DOCKER_HUB_REPO}:beta" + - /kaniko/executor --context . ${DESTINATION} --build-arg DISCOURSE_VERSION=$DISCOURSE_VERSION + only: + - master + +build-stable: + tags: + - build + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + script: + - cp $DOCKER_SECRET_CONFIG /kaniko/.docker/config.json + - export DISCOURSE_VERSION=`wget -qO- https://api.github.com/repos/discourse/discourse/tags | grep name | cut -d'"' -f4 | grep -v beta | head -n1` + - export DISCOURSE_MAJOR=`echo $DISCOURSE_VERSION | cut -d"." -f1-2` + - export DESTINATION="--destination ${DOCKER_HUB_REPO}:${DISCOURSE_VERSION} --destination ${DOCKER_HUB_REPO}:${DISCOURSE_MAJOR} --destination ${DOCKER_HUB_REPO}:stable" + - /kaniko/executor --context . ${DESTINATION} --build-arg DISCOURSE_VERSION=$DISCOURSE_VERSION + only: + - master diff --git a/Dockerfile b/Dockerfile index 4ee7605..b125006 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,25 @@ -FROM ruby:2.5.3 +FROM ruby:2.6.5 + +ARG DISCOURSE_VERSION ENV RAILS_ENV=production \ + DEBIAN_VERSION=buster \ DISCOURSE_DB_HOST=postgres \ DISCOURSE_REDIS_HOST=redis \ DISCOURSE_SERVE_STATIC_ASSETS=true \ - GIFSICLE_VERSION=1.91 \ - PNGQUANT_VERSION=2.12.1 \ + DISCOURSE_VERSION=${DISCOURSE_VERSION} \ + GIFSICLE_VERSION=1.92 \ + PNGQUANT_VERSION=2.12.5 \ PNGCRUSH_VERSION=1.8.13 \ - DISCOURSE_VERSION=2.2.0.beta4 \ + JEMALLOC_NEW=3.6.0 \ + JEMALLOC_STABLE=5.2.0 \ PG_MAJOR=10 \ + NODE_MAJOR=10 \ + RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 \ + RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 \ + RUBY_GC_HEAP_INIT_SLOTS=400000 \ + RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 \ + RUBY_GC_MALLOC_LIMIT=90000000 \ BUILD_DEPS="\ autoconf \ advancecomp \ @@ -19,87 +30,67 @@ ENV RAILS_ENV=production \ libtiff-dev \ pkg-config" -RUN curl http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add - -RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" | \ - tee /etc/apt/sources.list.d/postgres.list +COPY install /tmp/install + +RUN ls /tmp/ && ls /tmp/install -RUN curl --silent --location https://deb.nodesource.com/setup_8.x | bash - \ +RUN curl http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add - \ + && echo "deb http://apt.postgresql.org/pub/repos/apt/ ${DEBIAN_VERSION}-pgdg main" | \ + tee /etc/apt/sources.list.d/postgres.list \ + && curl --silent --location https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash - \ && apt-get update && apt-get install -y --no-install-recommends \ ${BUILD_DEPS} \ ghostscript \ gsfonts \ - imagemagick \ jpegoptim \ libxml2 \ nodejs \ optipng \ jhead \ postgresql-client-${PG_MAJOR} \ - postgresql-contrib-${PG_MAJOR} libpq-dev libreadline-dev - -RUN npm install svgo uglify-js@"<3" -g - -RUN mkdir /jemalloc-stable && cd /jemalloc-stable &&\ - wget https://github.com/jemalloc/jemalloc/releases/download/3.6.0/jemalloc-3.6.0.tar.bz2 &&\ - tar -xjf jemalloc-3.6.0.tar.bz2 && cd jemalloc-3.6.0 && ./configure --prefix=/usr && make && make install &&\ - cd / && rm -rf /jemalloc-stable - -RUN mkdir /jemalloc-new && cd /jemalloc-new &&\ - wget https://github.com/jemalloc/jemalloc/releases/download/5.1.0/jemalloc-5.1.0.tar.bz2 &&\ - tar -xjf jemalloc-5.1.0.tar.bz2 && cd jemalloc-5.1.0 && ./configure --prefix=/usr --with-install-suffix=5.1.0 && make build_lib && make install_lib &&\ - cd / && rm -rf /jemalloc-new - - -RUN gem update --system - -RUN gem install bundler --force \ - && rm -rf /usr/local/share/ri/2.5.2/system - -ADD install-imagemagick /tmp/install-imagemagick -RUN /tmp/install-imagemagick - -# Validate install -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 }" - -ADD install-pngcrush /tmp/install-pngcrush -RUN /tmp/install-pngcrush - -ADD install-gifsicle /tmp/install-gifsicle -RUN /tmp/install-gifsicle - -ADD install-pngquant /tmp/install-pngquant -RUN /tmp/install-pngquant - -RUN addgroup --gid 1000 discourse \ + postgresql-contrib-${PG_MAJOR} libpq-dev libreadline-dev \ + && npm install svgo uglify-js@"<3" -g \ + && mkdir /jemalloc-stable && cd /jemalloc-stable &&\ + wget https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_STABLE}/jemalloc-${JEMALLOC_STABLE}.tar.bz2 &&\ + tar -xjf jemalloc-${JEMALLOC_STABLE}.tar.bz2 && cd jemalloc-${JEMALLOC_STABLE} && ./configure --prefix=/usr && make && make install &&\ + cd / && rm -rf /jemalloc-stable \ + && mkdir /jemalloc-new && cd /jemalloc-new &&\ + wget https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_NEW}/jemalloc-${JEMALLOC_NEW}.tar.bz2 &&\ + tar -xjf jemalloc-${JEMALLOC_NEW}.tar.bz2 && cd jemalloc-${JEMALLOC_NEW} && ./configure --prefix=/usr --with-install-suffix=${JEMALLOC_NEW} && make build_lib && make install_lib &&\ + cd / && rm -rf /jemalloc-new \ + && gem update --system \ + && gem install bundler --force \ + && rm -rf /usr/local/share/ri/${RUBY_VERSION}/system \ + && /tmp/install/imagemagick \ + # Validate install + && 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 }" \ + && /tmp/install/pngcrush \ + && /tmp/install/gifsicle \ + && /tmp/install/pngquant \ + && addgroup --gid 1000 discourse \ && adduser --system --uid 1000 --ingroup discourse --shell /bin/bash discourse \ && cd /home/discourse \ && mkdir -p tmp/pids \ && mkdir -p ./tmp/sockets \ - && git clone --branch v${DISCOURSE_VERSION} https://github.com/discourse/discourse.git \ + && git clone --branch ${DISCOURSE_VERSION} https://github.com/discourse/discourse.git \ && chown -R discourse:discourse . \ && cd /home/discourse/discourse \ && git remote set-branches --add origin tests-passed \ && sed -i 's/daemonize true/daemonize false/g' ./config/puma.rb \ && bundle config build.nokogiri --use-system-libraries \ - && bundle install --deployment --verbose --without test --without development --retry 3 --jobs 4 - -RUN find /home/discourse/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + - -# RUN apt-get remove -y --purge ${BUILD_DEPS} \ -# && apt-get autoremove -y \ -# && rm -rf /var/lib/apt/lists/* + && bundle install --deployment --verbose --without test --without development --retry 3 --jobs 4 \ + && find /home/discourse/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + \ + && apt-get remove -y --purge ${BUILD_DEPS} \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* -RUN rm -rf /var/lib/apt/lists/* +RUN cd /home/discourse/discourse/plugins \ + && for plugin in $(cat /tmp/install/plugin-list); do \ + git clone $plugin; \ + done; WORKDIR /home/discourse/discourse -ENV RAILS_ENV=production \ - RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 \ - RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 \ - RUBY_GC_HEAP_INIT_SLOTS=400000 \ - RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 \ - RUBY_GC_MALLOC_LIMIT=90000000 - USER discourse CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] diff --git a/install-gifsicle b/install-gifsicle deleted file mode 100755 index e35be3c..0000000 --- a/install-gifsicle +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e -VERSION=1.91 -cd /tmp -curl -O http://www.lcdf.org/gifsicle/gifsicle-$VERSION.tar.gz -tar zxf gifsicle-$VERSION.tar.gz -cd gifsicle-$VERSION -./configure -make install -cd / -rm -fr /tmp/gifsicle* diff --git a/install-pngquant b/install-pngquant deleted file mode 100755 index 2a21c8a..0000000 --- a/install-pngquant +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -VERSION=2.12.1 -cd /tmp -git clone -b $VERSION --single-branch https://github.com/pornel/pngquant -cd pngquant -make && make install -cd / -rm -fr /tmp/pngq* diff --git a/install/gifsicle b/install/gifsicle new file mode 100755 index 0000000..4420465 --- /dev/null +++ b/install/gifsicle @@ -0,0 +1,9 @@ +#!/bin/bash -e +cd /tmp +curl -O http://www.lcdf.org/gifsicle/gifsicle-$GIFSICLE_VERSION.tar.gz +tar zxf gifsicle-$GIFSICLE_VERSION.tar.gz +cd gifsicle-$GIFSICLE_VERSION +./configure +make install +cd / +rm -fr /tmp/gifsicle* diff --git a/install-imagemagick b/install/imagemagick similarity index 77% rename from install-imagemagick rename to install/imagemagick index f0e99e3..83c6100 100755 --- a/install-imagemagick +++ b/install/imagemagick @@ -1,22 +1,26 @@ #!/bin/bash set -o errexit -# Install build deps -apt-get -y -q remove imagemagick +IMAGE_MAGICK_VERSION="7.0.8-66" +LIBPNG_VERSION="1.6.37" PREFIX=/usr/local WDIR=/tmp/imagemagick + mkdir -p $WDIR +cd $WDIR # Build and install libpng -git clone -b v1.6.34 https://github.com/glennrp/libpng.git $WDIR/libpng -cd $WDIR/libpng -./autogen.sh +wget -O $WDIR/libpng.tar.gz https://prdownloads.sourceforge.net/libpng/libpng-$LIBPNG_VERSION.tar.gz?download + +tar -xzvf $WDIR/libpng.tar.gz +cd $WDIR/libpng-$LIBPNG_VERSION + ./configure --prefix=$PREFIX make all && make install # Build and install ImageMagick -wget -O $WDIR/ImageMagick.tar.gz "https://github.com/ImageMagick/ImageMagick/archive/7.0.8-6.tar.gz" +wget -O $WDIR/ImageMagick.tar.gz "https://github.com/ImageMagick/ImageMagick/archive/$IMAGE_MAGICK_VERSION.tar.gz" IMDIR=$WDIR/$(tar tzf $WDIR/ImageMagick.tar.gz --wildcards "ImageMagick-*/configure" |cut -d/ -f1) tar zxf $WDIR/ImageMagick.tar.gz -C $WDIR cd $IMDIR @@ -43,4 +47,4 @@ make all && make install cd $HOME rm -rf $WDIR -ldconfig /usr/local/lib +ldconfig /usr/local/lib \ No newline at end of file diff --git a/install/plugin-list b/install/plugin-list new file mode 100644 index 0000000..016d36c --- /dev/null +++ b/install/plugin-list @@ -0,0 +1,5 @@ +https://github.com/discourse/discourse-checklist +https://github.com/discourse/discourse-math +https://github.com/discourse/discourse-openid-connect +https://github.com/discourse/discourse-solved +https://github.com/discourse/discourse-voting \ No newline at end of file diff --git a/install-pngcrush b/install/pngcrush similarity index 89% rename from install-pngcrush rename to install/pngcrush index a08b2b6..5d1b72b 100755 --- a/install-pngcrush +++ b/install/pngcrush @@ -1,6 +1,4 @@ -#!/bin/bash -set -e -PNGCRUSH_VERSION=1.8.13 +#!/bin/bash -e cd /tmp wget https://sourceforge.net/projects/pmt/files/pngcrush/$PNGCRUSH_VERSION/pngcrush-$PNGCRUSH_VERSION.tar.gz/download -O pngcrush-$PNGCRUSH_VERSION.tar.gz tar zxf pngcrush-$PNGCRUSH_VERSION.tar.gz diff --git a/install/pngquant b/install/pngquant new file mode 100755 index 0000000..7f8b808 --- /dev/null +++ b/install/pngquant @@ -0,0 +1,7 @@ +#!/bin/bash +cd /tmp +git clone -b PNGQUANT_VERSION --single-branch https://github.com/pornel/pngquant +cd pngquant +make && make install +cd / +rm -fr /tmp/pngq* -- GitLab