Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Improve Dockerfile and reduce image size

Cyril Rohr8c68f470440e
diff --git a/.dockerignore b/.dockerignore
index d1dd66a33ab..6780e8d0c2c 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,6 +1,22 @@
.git
.bundle
.env*
+.buildpacks
+.*.yml
+.*ignore
+*.md
+*.log
+Vagrantfile
+Guardfile
+docker-compose.*
+browserslist
+docs
+extra
+features
+help
+log/*.log
+spec
+spec_legacy
tmp
frontend/node_modules
# travis
diff --git a/Dockerfile b/Dockerfile
index 0d7ef1f1e30..bb3c231bd57 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,8 +1,14 @@
+FROM ruby:2.6-stretch AS pgloader
+RUN apt-get update -qq && apt-get install -y libsqlite3-dev make curl gawk freetds-dev libzip-dev
+COPY docker/mysql-to-postgres/bin/build /tmp/build-pgloader
+RUN /tmp/build-pgloader && rm /tmp/build-pgloader
+
FROM ruby:2.6-stretch
MAINTAINER [email protected]
ENV NODE_VERSION "10.15.0"
ENV BUNDLER_VERSION "2.0.2"
+ENV BUNDLE_PATH__SYSTEM=false
ENV APP_USER app
ENV APP_PATH /app
ENV APP_DATA_PATH /var/openproject/assets
@@ -17,20 +23,17 @@ ENV RAILS_CACHE_STORE memcache
ENV OPENPROJECT_INSTALLATION__TYPE docker
ENV NEW_RELIC_AGENT_ENABLED false
ENV ATTACHMENTS_STORAGE_PATH $APP_DATA_PATH/files
-ENV BUNDLE_PATH__SYSTEM=false
-
-ENV PGLOADER_DEPENDENCIES "libsqlite3-dev make curl gawk freetds-dev libzip-dev"
-
# Set a default key base, ensure to provide a secure value in production environments!
ENV SECRET_KEY_BASE OVERWRITE_ME
+COPY --from=pgloader /usr/local/bin/pgloader-ccl /usr/local/bin/
+
# install node + npm
RUN curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz | tar xzf - -C /usr/local --strip-components=1
RUN apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
postgresql-client \
- mysql-client \
poppler-utils \
unrtf \
tesseract-ocr \
@@ -38,18 +41,10 @@ RUN apt-get update -qq && \
memcached \
postfix \
postgresql \
- $PGLOADER_DEPENDENCIES \
apache2 \
supervisor && \
apt-get clean && rm -rf /var/lib/apt/lists/*
-# pgloader
-ENV CCL_DEFAULT_DIRECTORY /opt/ccl
-COPY docker/mysql-to-postgres/bin/build /tmp/build-pgloader
-RUN /tmp/build-pgloader && rm /tmp/build-pgloader
-# Add MySQL-to-Postgres migration script to path (used in entrypoint.sh)
-COPY docker/mysql-to-postgres/bin/migrate-mysql-to-postgres /usr/local/bin/
-
# Set up pg defaults
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.6/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.6/main/postgresql.conf
@@ -70,27 +65,33 @@ COPY modules ./modules
# OpenProject::Version is required by module versions in gemspecs
RUN mkdir -p lib/open_project
COPY lib/open_project/version.rb ./lib/open_project/
-RUN bundle install --deployment --path vendor/bundle --with="docker opf_plugins" --without="test development" --jobs=8 --retry=3
+RUN bundle install --deployment --path vendor/bundle --no-cache \
+ --with="docker opf_plugins" --without="test development" --jobs=8 --retry=3 && \
+ rm -rf vendor/bundle/ruby/*/cache && rm -rf vendor/bundle/ruby/*/gems/*/spec && rm -rf vendor/bundle/ruby/*/gems/*/test
# Finally, copy over the whole thing
-COPY . $APP_PATH
+COPY . .
+# Re-use packager database.yml
+RUN cp ./packaging/conf/database.yml ./config/database.yml
+# Add MySQL-to-Postgres migration script to path (used in entrypoint.sh)
+RUN cp ./docker/mysql-to-postgres/bin/migrate-mysql-to-postgres /usr/local/bin/
+# Ensure OpenProject starts with the docker group of gems
RUN sed -i "s|Rails.groups(:opf_plugins)|Rails.groups(:opf_plugins, :docker)|" config/application.rb
-
# Ensure we can write in /tmp/op_uploaded_files (cf. #29112)
RUN mkdir -p /tmp/op_uploaded_files/ && chown -R $APP_USER:$APP_USER /tmp/op_uploaded_files/
-# Re-use packager database.yml
-COPY packaging/conf/database.yml ./config/database.yml
-
-# Run the npm postinstall manually after it was copied
-# Then, npm install node modules
+# Handle the assets precompilation
RUN bash docker/precompile-assets.sh
-# ports
+# Expose ports for apache and postgres
EXPOSE 80 5432
-# volumes to export
+# Expose the postgres data directory and OpenProject data directory as volumes
VOLUME ["$PGDATA", "$APP_DATA_PATH"]
+
+# Set a custom entrypoint to allow for privilege dropping and one-off commands
ENTRYPOINT ["./docker/entrypoint.sh"]
+
+# Set default command to launch the all-in-one configuration supervised by supervisord
CMD ["./docker/supervisord"]
diff --git a/docker/mysql-to-postgres/bin/build b/docker/mysql-to-postgres/bin/build
index e2cb14c0211..1a73ee776ec 100755
--- a/docker/mysql-to-postgres/bin/build
+++ b/docker/mysql-to-postgres/bin/build
@@ -1,21 +1,19 @@
#!/bin/bash
-
set -e
+set -o pipefail
cd /opt
# install Clozure CL to avoid memory issues with the standard SBCL
-wget -q https://github.com/Clozure/ccl/releases/download/v1.11.5/ccl-1.11.5-linuxx86.tar.gz
-tar -xzf ccl-1.11.5-linuxx86.tar.gz
-rm ccl-1.11.5-linuxx86.tar.gz
+curl -sL https://github.com/Clozure/ccl/releases/download/v1.11.5/ccl-1.11.5-linuxx86.tar.gz -o - | tar xzf - -C /opt/
ln -s /opt/ccl/scripts/ccl64 /usr/local/bin/ccl
export CCL_DEFAULT_DIRECTORY=/opt/ccl
# build pgloader from source using CCL as the lisp runtime
-git clone https://github.com/dimitri/pgloader.git
+git clone -q https://github.com/dimitri/pgloader.git --branch v3.6.1 --depth 1
cd pgloader
-git checkout v3.6.1
make CL=ccl pgloader >& /tmp/pgloader-compile.log || (cat /tmp/pgloader-compile.log && exit 1)
mv /opt/pgloader/build/bin/pgloader /usr/local/bin/pgloader-ccl
-rm -rf /opt/pgloader
+
+rm -rf /opt/pgloader /tmp/pgloader-compile.log /usr/local/bin/ccl /opt/ccl
diff --git a/docker/precompile-assets.sh b/docker/precompile-assets.sh
index 4f12938ad4f..07d9aa72bfd 100644
--- a/docker/precompile-assets.sh
+++ b/docker/precompile-assets.sh
@@ -13,6 +13,9 @@ popd
# Bundle assets
DATABASE_URL='nulldb://nohost' RAILS_ENV=production bundle exec rake assets:precompile
+# Remove sprockets cache
+rm -rf "$APP_PATH/tmp/cache/assets"
+
# Remove node_modules and entire frontend
rm -rf "$APP_PATH/node_modules/" "$APP_PATH/frontend/node_modules/"