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

Make slim image for docker

Cyril Rohr2c123e647e4f
diff --git a/.dockerignore b/.dockerignore
index 38a45ad430b..bca449c8d7c 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,6 +1,7 @@
.github/
.git
.dockerignore
+.gitignore
.bundle
.env*
.buildpacks
@@ -9,24 +10,24 @@
.*ignore
*.md
*.log
-Vagrantfile
-Dockerfile
+docker/prod/Dockerfile
+docker/ci/Dockerfile
Guardfile
docker-compose.*
browserslist
-docs
-!docs/api/apiv3/openapi-spec.yml
-!docs/api/apiv3/paths
-!docs/api/apiv3/tags
-!docs/api/apiv3/components
+/docs
+!/docs/api/apiv3/openapi-spec.yml
+!/docs/api/apiv3/paths
+!/docs/api/apiv3/tags
+!/docs/api/apiv3/components
extra
features
help
log/*.log
spec
-tmp
+/tmp
frontend/.angular/cache
frontend/node_modules
node_modules
diff --git a/docker/prod/Dockerfile.slim b/docker/prod/Dockerfile.slim
new file mode 100644
index 00000000000..5b4282fb34a
--- /dev/null
+++ b/docker/prod/Dockerfile.slim
@@ -0,0 +1,112 @@
+ARG RUBY_VERSION=3.2.2
+ARG NODE_VERSION=16.17.0
+ARG DEBIAN_FRONTEND=noninteractive
+
+FROM ruby:${RUBY_VERSION}-bullseye as rubygems
+ENV BUNDLE_JOBS=8
+ENV BUNDLE_RETRY=3
+ENV BUNDLE_WITHOUT="development:test"
+
+WORKDIR /app
+
+RUN gem install bundler --version "$BUNDLER_VERSION" --no-document
+
+COPY Gemfile Gemfile.modules Gemfile.lock ./
+COPY modules ./modules
+RUN bundle install
+
+# Using docker image for node so that multi-arch is automatically taken care of
+FROM node:${NODE_VERSION} as nodejs
+
+WORKDIR /app
+
+COPY package.json ./
+COPY frontend/package.json frontend/package-lock.json frontend/.npmrc ./frontend/
+RUN JOBS=8 npm install
+
+FROM rubygems as assets
+
+COPY --from=nodejs /usr/local/bin/node /usr/local/bin/node
+COPY --from=nodejs /usr/local/lib/node_modules /usr/local/lib/node_modules
+COPY --from=nodejs /usr/local/include/node /usr/local/include/node
+RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
+
+WORKDIR /app
+
+COPY --from=nodejs /app/node_modules ./node_modules
+COPY --from=nodejs /app/frontend/node_modules ./frontend/node_modules
+COPY bin ./bin
+COPY app ./app
+COPY config ./config
+COPY lib ./lib
+COPY lib_static ./lib_static
+COPY Rakefile .
+COPY frontend ./frontend
+COPY modules ./modules
+COPY vendor ./vendor
+
+RUN --mount=type=cache,target=/app/frontend/.angular/cache,uid=1000,gid=1000 \
+ SECRET_KEY_BASE=1 RAILS_ENV=production DATABASE_URL=nulldb://db \
+ bin/rails openproject:plugins:register_frontend assets:precompile && \
+ # only keep most current angular cache since webpack is unable to cleanup after itself
+ find frontend/.angular/cache -type d -exec sh -c 'ls -dt "$1"/*/ | tail -n +2 | xargs rm -r' sh {} \;
+
+FROM ruby:${RUBY_VERSION}-slim-bullseye
+LABEL maintainer="[email protected]"
+
+# SYSTEM
+ENV APP_USER=app
+ENV APP_PATH=/app
+ENV APP_DATA_PATH=/var/openproject/assets
+ENV PGVERSION="13"
+ENV PGBIN="/usr/lib/postgresql/$PGVERSION/bin"
+ENV BUNDLE_WITHOUT="development:test"
+
+# RAILS
+# Set a default key base, ensure to provide a secure value in production environments!
+ENV SECRET_KEY_BASE=OVERWRITE_ME
+ENV RAILS_ENV=production
+ENV RAILS_LOG_TO_STDOUT=1
+ENV RAILS_SERVE_STATIC_FILES=1
+
+# OPENPROJECT
+# Valid values are: standard,bim
+ENV OPENPROJECT_EDITION=standard
+ENV OPENPROJECT_INSTALLATION__TYPE=docker
+ENV OPENPROJECT_ATTACHMENTS__STORAGE__PATH=$APP_DATA_PATH/files
+ENV OPENPROJECT_RAILS__CACHE__STORE=file_store
+
+RUN useradd -d /home/$APP_USER -m $APP_USER
+RUN mkdir -p $APP_PATH && chown $APP_USER:$APP_USER $APP_PATH
+RUN mkdir -p $APP_DATA_PATH && chown $APP_USER:$APP_USER $APP_DATA_PATH
+
+WORKDIR $APP_PATH
+
+RUN --mount=type=cache,target=/var/cache/apt \
+ apt-get update -qq \
+ && apt-get install -yq --no-install-recommends \
+ curl \
+ gnupg2 \
+ && curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
+ && echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main' $PGVERSION > /etc/apt/sources.list.d/pgdg.list \
+ && apt-get update -qq \
+ && apt-get install -yq --no-install-recommends \
+ libpq5 \
+ postgresql-client-$PGVERSION \
+ libffi7 \
+ unrtf tesseract-ocr poppler-utils catdoc imagemagick \
+ && apt-get purge -y curl gnupg2 \
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
+ && truncate -s 0 /var/log/*log
+
+COPY --chown=$APP_USER:$APP_USER --from=rubygems /usr/local/bundle /usr/local/bundle
+COPY --chown=$APP_USER:$APP_USER --from=assets /app/public/assets /app/public/assets
+COPY --chown=$APP_USER:$APP_USER --from=assets /app/config/frontend_assets.manifest.json /app/config/frontend_assets.manifest.json
+COPY --chown=$APP_USER:$APP_USER . .
+
+USER $APP_USER
+RUN ln -s $APP_PATH/docker/prod/setup/.irbrc /home/$APP_USER/
+
+EXPOSE 8080
+CMD ["./docker/prod/web"]
+VOLUME ["$APP_DATA_PATH"]
\ No newline at end of file