From c779cc689f9bbbabc04058610dd9e173c0907739 Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Thu, 15 Sep 2022 12:14:14 +0900 Subject: [PATCH 1/9] Updates README Signed-off-by: Daniel Kastl --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 42c6d5f..1899215 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# docker-gtt +# Docker GTT Docker image for GTT Project @@ -6,16 +6,20 @@ Docker image for GTT Project After cloning this repository run: -``` +```sh git submodule update --init cp .env.example .env -docker-compose up --build +docker compose up --build ``` -Open the application on http://localhost:3000/ +Open the application on `http://localhost:3000/` Default user is `admin/admin`. ## How to use GTT: Find more information [how to get started with the GTT plugin](https://github.com/gtt-project/redmine_gtt#how-to-use). + +## LICENSE + +This program is free software. See [LICENSE](LICENSE) for more information. From 8350f87082ba5f4d7be5464330debb802f0cc900 Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Thu, 15 Sep 2022 12:36:30 +0900 Subject: [PATCH 2/9] Updates submodules to latest release Signed-off-by: Daniel Kastl --- .env.example | 25 +++++++++++++++---------- .markdownlint.json | 6 ++++++ plugins/redmine_gtt | 2 +- plugins/redmine_gtt_print | 2 +- plugins/redmine_gtt_smash | 2 +- plugins/redmine_text_blocks | 2 +- 6 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 .markdownlint.json diff --git a/.env.example b/.env.example index 6aa2827..77c2cc9 100644 --- a/.env.example +++ b/.env.example @@ -1,16 +1,21 @@ # Gemfile GEM_PG_VERSION=1.2.2 -# docker-compose.yml - postgres -POSTGRES_USER=gtt -POSTGRES_PASSWORD=gtt -POSTGRES_DB=gtt +# Database +DB_HOST=postgis +DB_NAME=gtt +DB_USER=gtt +DB_PASS=gtt +DB_PORT=5432 -# config/configuration.yml -SMTP_ENABLE_STARTTLS_AUTO=true # (or false) -SMTP_ADDRESS=smtp.gmail.com -SMTP_PORT=587 -SMTP_DOMAIN=smtp.gmail.com -SMTP_AUTHENTICATION=plain # (or login) +# Configuration.yml +SMTP_ADDRESS=smtp +SMTP_DOMAIN=smtp.example.com +SMTP_PORT=1025 SMTP_USER_NAME=YOUR_EMAIL_ADDRESS SMTP_PASSWORD=YOUR_PASSWORD +SMTP_AUTHENTICATION=plain # (or login) +SMTP_ENABLE_STARTTLS_AUTO=false + +# Setup +EMAIL_ADDRESS=gtt@example.com diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..0b6c84c --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,6 @@ +{ + "MD029": false, + "MD033": false, + "MD038": false, + "MD041": false +} diff --git a/plugins/redmine_gtt b/plugins/redmine_gtt index 68f3b40..414b5a9 160000 --- a/plugins/redmine_gtt +++ b/plugins/redmine_gtt @@ -1 +1 @@ -Subproject commit 68f3b402a96380be4192912e38e6b9d2b419b593 +Subproject commit 414b5a9085d02c0659c53867a32e8d42be9e1404 diff --git a/plugins/redmine_gtt_print b/plugins/redmine_gtt_print index 6d67a3c..2c6568e 160000 --- a/plugins/redmine_gtt_print +++ b/plugins/redmine_gtt_print @@ -1 +1 @@ -Subproject commit 6d67a3c7b6eee3c7645c26d41d66901824287e8d +Subproject commit 2c6568e352cf516677487715c8b457f857c18d9c diff --git a/plugins/redmine_gtt_smash b/plugins/redmine_gtt_smash index 3863ef9..871cf07 160000 --- a/plugins/redmine_gtt_smash +++ b/plugins/redmine_gtt_smash @@ -1 +1 @@ -Subproject commit 3863ef9f36c31d46c109c3491f885470ec83ab3b +Subproject commit 871cf072db927ddc7f2932319c1fb5a8591fbde7 diff --git a/plugins/redmine_text_blocks b/plugins/redmine_text_blocks index 88a6021..733c1df 160000 --- a/plugins/redmine_text_blocks +++ b/plugins/redmine_text_blocks @@ -1 +1 @@ -Subproject commit 88a602179327e7c2042304c86f2af1298ae614db +Subproject commit 733c1dffc47ea739c04515030948101b5416345f From 367178f307ace830650b9ad533c36ad8884d54fc Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Thu, 15 Sep 2022 15:05:19 +0900 Subject: [PATCH 3/9] New Docker setup Signed-off-by: Daniel Kastl --- .env.example | 8 +- Dockerfile | 139 ++++++++++-------------- Gemfile.local | 8 +- README.md | 2 +- config/configuration.yml | 15 +-- config/database.yml | 17 +++ config/environments/production.rb | 34 ++++++ config/initializers/lograge.rb | 14 +++ config/puma.rb | 15 +++ docker-compose.yml | 87 ++++++++------- docker-entrypoint.sh | 169 ++++-------------------------- 11 files changed, 204 insertions(+), 304 deletions(-) create mode 100644 config/database.yml create mode 100644 config/environments/production.rb create mode 100644 config/initializers/lograge.rb create mode 100644 config/puma.rb diff --git a/.env.example b/.env.example index 77c2cc9..c7fb6cb 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,3 @@ -# Gemfile -GEM_PG_VERSION=1.2.2 - # Database DB_HOST=postgis DB_NAME=gtt @@ -8,7 +5,7 @@ DB_USER=gtt DB_PASS=gtt DB_PORT=5432 -# Configuration.yml +# Email SMTP_ADDRESS=smtp SMTP_DOMAIN=smtp.example.com SMTP_PORT=1025 @@ -18,4 +15,5 @@ SMTP_AUTHENTICATION=plain # (or login) SMTP_ENABLE_STARTTLS_AUTO=false # Setup -EMAIL_ADDRESS=gtt@example.com +REDMINE_LANG=en +REDMINE_EMAIL=gtt@example.com diff --git a/Dockerfile b/Dockerfile index 4a0a719..8f2c5b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,22 @@ -FROM ruby:2.7-slim-buster +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# GTT Builder +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +FROM node:16-bullseye-slim as gtt-builder + +WORKDIR /app + +COPY plugins/redmine_gtt/ ./redmine_gtt/ + +RUN apt update; \ + apt install -y git; \ + cd redmine_gtt; \ + yarn; \ + yarn webpack + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# GTT Base +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +FROM ruby:3.1-slim-bullseye as base # explicitly set uid/gid to guarantee that it won't change in the future # the values 999:999 are identical to the current user/group id assigned @@ -10,25 +28,17 @@ RUN set -eux; \ ca-certificates \ wget \ \ - # bzr \ - # git \ - # mercurial \ - openssh-client \ - # subversion \ - \ -# we need "gsfonts" for generating PNGs of Gantt charts -# and "ghostscript" for creating PDF thumbnails (in 4.1+) + # we need "gsfonts" for generating PNGs of Gantt charts + # and "ghostscript" for creating PDF thumbnails (in 4.1+) ghostscript \ gsfonts \ imagemagick \ -# https://github.com/docker-library/ruby/issues/344 - shared-mime-info \ -# grab gosu for easy step-down from root + # grab gosu for easy step-down from root gosu \ -# grab tini for signal processing and zombie killing + # grab tini for signal processing and zombie killing tini \ ; \ -# allow imagemagick to use ghostscript for PDF -> PNG thumbnail conversion (4.1+) + # allow imagemagick to use ghostscript for PDF -> PNG thumbnail conversion (4.1+) sed -ri 's/(rights)="none" (pattern="PDF")/\1="read" \2/' /etc/ImageMagick-6/policy.xml; \ rm -rf /var/lib/apt/lists/* @@ -44,94 +54,52 @@ RUN set -eux; \ chown redmine:redmine "$HOME"; \ chmod 1777 "$HOME" -ARG REDMINE_VERSION="4.2.3" -ARG REDMICA_VERSION="" -# ENV REDMINE_DOWNLOAD_SHA256 ad4109c3425f1cfe4c8961f6ae6494c76e20d81ed946caa1e297d9eda13b41b4 +# To support Redmine 5.0 +ENV GEM_RGEO_ACTIVERECORD_VERSION=7.0.1 +ENV GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION=7.1.1 + +# Defined in docker-compose.yml +ARG REDMINE_VERSION +ARG REDMINE_DOWNLOAD_SHA256 RUN set -eux; \ - if [ -n "$REDMINE_VERSION" ]; then \ - wget -O redmine.tar.gz "https://www.redmine.org/releases/redmine-${REDMINE_VERSION}.tar.gz"; \ - # echo "$REDMINE_DOWNLOAD_SHA256 *redmine.tar.gz" | sha256sum -c -; - elif [ -n "$REDMICA_VERSION" ]; then \ - wget -O redmine.tar.gz "https://github.com/redmica/redmica/archive/v${REDMICA_VERSION}.tar.gz"; \ - fi; \ + # bullseye hack + wget --no-check-certificate -O redmine.tar.gz "https://www.redmine.org/releases/redmine-${REDMINE_VERSION}.tar.gz"; \ + echo "${REDMINE_DOWNLOAD_SHA256} *redmine.tar.gz" | sha256sum -c -; \ tar -xf redmine.tar.gz --strip-components=1; \ rm redmine.tar.gz files/delete.me log/delete.me; \ - mkdir -p log public/plugin_assets sqlite tmp/pdf tmp/pids; \ - chown -R redmine:redmine ./; \ -# log to STDOUT (https://github.com/docker-library/redmine/issues/108) - echo 'config.logger = Logger.new(STDOUT)' > config/additional_environment.rb; \ -# fix permissions for running as an arbitrary user - chmod -R ugo=rwX config db sqlite; \ - find log tmp -type d -exec chmod 1777 '{}' + - -# for Redmine patches -ARG PATCH_STRIP=1 -ARG PATCH_DIRS="" -COPY patches/ ./patches/ - -# for GTT gem native extensions -ARG GEM_PG_VERSION="1.2.3" -COPY Gemfile.local ./ -COPY plugins/ ./plugins/ + mkdir -p log public/plugin_assets tmp/pdf tmp/pids; \ + chown -R redmine:redmine ./ ; \ + chmod -R ugo=rwX config ; \ + find log tmp -type d -exec chmod 1777 '{}' + + +COPY --from=gtt-builder --chown=redmine:redmine /app/ ./plugins/ + +COPY --chown=redmine:redmine config/ ./config/ + +COPY --chown=redmine:redmine Gemfile.local ./ RUN set -eux; \ \ savedAptMark="$(apt-mark showmanual)"; \ apt-get update; \ apt-get install -y --no-install-recommends \ - # freetds-dev \ + freetds-dev \ gcc \ - # libmariadbclient-dev \ libpq-dev \ - # libsqlite3-dev \ + libgeos-dev \ make \ patch \ -# in 4.1+, libmagickcore-dev and libmagickwand-dev are no longer necessary/used: https://www.redmine.org/issues/30492 - libmagickcore-dev libmagickwand-dev \ -# for GTT dependencies - g++ \ - libgeos-dev \ - curl \ ; \ rm -rf /var/lib/apt/lists/*; \ \ - if [ -n "$PATCH_DIRS" ]; then \ - for dir in $(echo $PATCH_DIRS | sed "s/,/ /g"); do \ - for file in ./patches/"$dir"/*; do \ - patch -p"$PATCH_STRIP" < $file; \ - done; \ - done; \ - rm -rf ./patches/*; \ - fi; \ - curl -sL https://deb.nodesource.com/setup_14.x | bash -; \ - apt-get install -y --no-install-recommends nodejs; \ - curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -; \ - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list; \ - apt-get update; \ - apt-get install -y --no-install-recommends yarn; \ - for plugin in ./plugins/*; do \ - if [ -f "$plugin/webpack.config.js" ]; then \ - cd "$plugin" && yarn && npx webpack && rm -rf node_modules && cd ../..; \ - fi; \ - done; \ - export GEM_PG_VERSION="$GEM_PG_VERSION"; \ gosu redmine bundle config --local without 'development test'; \ -# fill up "database.yml" with bogus entries so the redmine Gemfile will pre-install all database adapter dependencies -# https://github.com/redmine/redmine/blob/e9f9767089a4e3efbd73c35fc55c5c7eb85dd7d3/Gemfile#L50-L79 - echo '# the following entries only exist to force `bundle install` to pre-install all database adapter dependencies -- they can be safely removed/ignored' > ./config/database.yml; \ - # for adapter in mysql2 postgresql sqlserver sqlite3; do \ - for adapter in postgis; do \ - echo "$adapter:" >> ./config/database.yml; \ - echo " adapter: $adapter" >> ./config/database.yml; \ - done; \ gosu redmine bundle install --jobs "$(nproc)"; \ - rm ./config/database.yml; \ -# fix permissions for running as an arbitrary user + # fix permissions for running as an arbitrary user chmod -R ugo=rwX Gemfile.lock "$GEM_HOME"; \ rm -rf ~redmine/.bundle; \ \ -# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies + # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies apt-mark auto '.*' > /dev/null; \ [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ find /usr/local -type f -executable -exec ldd '{}' ';' \ @@ -145,11 +113,10 @@ RUN set -eux; \ ; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -COPY config/ ./config/ -VOLUME /usr/src/redmine/files - -COPY docker-entrypoint.sh / -ENTRYPOINT ["/docker-entrypoint.sh"] +COPY --chown=redmine:redmine docker-entrypoint.sh / EXPOSE 3000 -CMD ["rails", "server", "-b", "0.0.0.0"] + +ENTRYPOINT [ "/docker-entrypoint.sh" ] + +CMD [ "rails", "s", "-b", "0.0.0.0" ] diff --git a/Gemfile.local b/Gemfile.local index 64e8352..5475b94 100644 --- a/Gemfile.local +++ b/Gemfile.local @@ -1,5 +1,3 @@ -source 'https://rubygems.org' - -# each plugin's native extensions should be added to here -gem "rgeo" -gem "pg", (ENV['GEM_PG_VERSION'] ? "~> #{ENV['GEM_PG_VERSION']}" : "~> 1.2.3") +gem 'puma' +gem 'puma_worker_killer' +gem 'lograge' diff --git a/README.md b/README.md index 1899215..9c71a3e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Open the application on `http://localhost:3000/` Default user is `admin/admin`. -## How to use GTT: +## How to use GTT Find more information [how to get started with the GTT plugin](https://github.com/gtt-project/redmine_gtt#how-to-use). diff --git a/config/configuration.yml b/config/configuration.yml index 8cff2e7..ea2551c 100644 --- a/config/configuration.yml +++ b/config/configuration.yml @@ -21,15 +21,10 @@ default: email_delivery: delivery_method: :smtp smtp_settings: - enable_starttls_auto: <%= ENV['SMTP_ENABLE_STARTTLS_AUTO'] %> + enable_starttls_auto: true address: <%= ENV['SMTP_ADDRESS'] %> - port: <%= ENV['SMTP_PORT'] %> + port: <%= ENV['SMTP_PORT'] || 587 %> domain: <%= ENV['SMTP_DOMAIN'] %> - authentication: <%= ENV['SMTP_AUTHENTICATION'] %> - user_name: <%= ENV['SMTP_USER_NAME'] %> - password: <%= ENV['SMTP_PASSWORD'] %> - - # ==== Sendmail command - # - # email_delivery: - # delivery_method: :sendmail + authentication: :plain + user_name: <%= ENV['EMAIL_ADDRESS'] %> + password: <%= ENV['SMTP_PASS'] %> diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..6be21a9 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,17 @@ +default: &default + adapter: postgis + database: <%= ENV['DB_NAME'] %> + host: <%= ENV['DB_HOST'] %> + username: <%= ENV['DB_USER'] %> + password: <%= ENV['DB_PASS'] %> + port: <%= ENV['DB_PORT'] || 5432 %> + encoding: utf8 + +production: + <<: *default + +test: + <<: *default + +development: + <<: *default diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..61b3cb1 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable delivery errors + config.action_mailer.raise_delivery_errors = false + + # No email in production log + config.action_mailer.logger = nil + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Logging by JSON + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end +end diff --git a/config/initializers/lograge.rb b/config/initializers/lograge.rb new file mode 100644 index 0000000..89a7ba3 --- /dev/null +++ b/config/initializers/lograge.rb @@ -0,0 +1,14 @@ +Rails.application.configure do + config.lograge.enabled = true + config.lograge.formatter = Lograge::Formatters::Json.new + config.lograge.custom_payload do |controller| + current_user = controller.find_current_user + user_name = current_user&.logged? ? "#{current_user.login}" : "anonymous" + user_id = current_user&.logged? ? "#{current_user.id}" : "0" + { + remote_ip: controller.request.remote_ip, + user_name: user_name, + user_id: user_id + } + end +end diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..c42024d --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,15 @@ +workers 3 + +before_fork do + require 'puma_worker_killer' + + PumaWorkerKiller.config do |config| + config.ram = (ENV['RAILS_MEMORY_LIMIT'] || 2048).to_i + config.frequency = 10 + config.percent_usage = 0.8 + config.rolling_restart_frequency = false + config.reaper_status_logs = false + end + + PumaWorkerKiller.start +end diff --git a/docker-compose.yml b/docker-compose.yml index cc5cf32..176d6ee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,34 +2,32 @@ version: "3" services: - gtt: + postgis: + image: postgis/postgis:14-master + environment: + POSTGRES_PASSWORD: ${DB_PASS} + POSTGRES_USER: ${DB_USER} + POSTGRES_DB: ${DB_NAME} + volumes: + - postgis:/var/lib/postgresql/data + healthcheck: + test: ["CMD", "pg_isready", "-U", "${DB_USER}", "-d", "${DB_NAME}"] + interval: 10s + timeout: 2s + retries: 5 + start_period: 10s + + redmine: build: - context: ./ + context: . dockerfile: ./Dockerfile args: - REDMINE_VERSION: 4.2.3 - REDMICA_VERSION: "" - GEM_PG_VERSION: ${GEM_PG_VERSION} - PATCH_STRIP: 1 - PATCH_DIRS: "" + REDMINE_VERSION: 5.0.2 + REDMINE_DOWNLOAD_SHA256: "4e718f44ba33716faf58c8fabf5d5f55b33c93426b7a33a83b5fc1b880585d57" ports: - 3000:3000 - environment: - REDMINE_DB_POSTGRES: postgres - REDMINE_DB_USERNAME: ${POSTGRES_USER} - REDMINE_DB_PASSWORD: ${POSTGRES_PASSWORD} - REDMINE_DB_DATABASE: ${POSTGRES_DB} - REDMINE_PLUGINS_MIGRATE: 1 - # Gemfile - GEM_PG_VERSION: ${GEM_PG_VERSION} - # config/configuration.yml - SMTP_ENABLE_STARTTLS_AUTO: ${SMTP_ENABLE_STARTTLS_AUTO} - SMTP_ADDRESS: ${SMTP_ADDRESS} - SMTP_PORT: ${SMTP_PORT} - SMTP_DOMAIN: ${SMTP_DOMAIN} - SMTP_AUTHENTICATION: ${SMTP_AUTHENTICATION} - SMTP_USER_NAME: ${SMTP_USER_NAME} - SMTP_PASSWORD: ${SMTP_PASSWORD} + env_file: + - .env volumes: - ./files:/usr/src/redmine/files - ./plugins:/usr/src/redmine/plugins @@ -37,32 +35,29 @@ services: # Exclude node package and webpack contents folders - /usr/src/redmine/plugins/redmine_gtt/node_modules - /usr/src/redmine/plugins/redmine_gtt/assets/javascripts + # TODO: remove the following line when adding GTT Print back + - /usr/src/redmine/plugins/redmine_gtt_print depends_on: - - postgres - - mapfish-print - restart: always + postgis: + condition: service_healthy + # mapfish: + # condition: service_started - postgres: - image: postgis/postgis:13-3.1 - environment: - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_DB: ${POSTGRES_DB} - volumes: - - postgres:/var/lib/postgresql/data - restart: always + # mapfish: + # image: camptocamp/mapfish_print:3.29 + # ports: + # - 8080:8080 + # environment: + # EXTRA_JARS: /usr/local/tomcat/webapps/ROOT/print-apps/lib + # # CATALINA_OPTS: "" + # volumes: + # - ./plugins/redmine_gtt_print/server-example/print-apps:/usr/local/tomcat/webapps/ROOT/print-apps - mapfish-print: - image: camptocamp/mapfish_print:3.28 + smtp: + image: smellman/mailcatcher:0.8.2 ports: - - 8080:8080 - environment: - EXTRA_JARS: /usr/local/tomcat/webapps/ROOT/print-apps/lib - volumes: - - ./mapfish-print-apps:/usr/local/tomcat/webapps/ROOT/print-apps - restart: always + - 1080:1080 volumes: - gtt: - postgres: - mapfish-print: + postgis: + # mapfish: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 7b6e8b9..01e662b 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,157 +1,24 @@ -#!/usr/bin/env bash -set -Eeo pipefail -# TODO add "-u" - -# usage: file_env VAR [DEFAULT] -# ie: file_env 'XYZ_DB_PASSWORD' 'example' -# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of -# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) -file_env() { - local var="$1" - local fileVar="${var}_FILE" - local def="${2:-}" - if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then - echo >&2 "error: both $var and $fileVar are set (but are exclusive)" - exit 1 - fi - local val="$def" - if [ "${!var:-}" ]; then - val="${!var}" - elif [ "${!fileVar:-}" ]; then - val="$(< "${!fileVar}")" - fi - export "$var"="$val" - unset "$fileVar" -} - -isLikelyRedmine= -case "$1" in - rails | rake | passenger ) isLikelyRedmine=1 ;; -esac - -_fix_permissions() { - # https://www.redmine.org/projects/redmine/wiki/RedmineInstall#Step-8-File-system-permissions - if [ "$(id -u)" = '0' ]; then - find config files log public/plugin_assets \! -user redmine -exec chown redmine:redmine '{}' + - fi - # directories 755, files 644: - find config files log public/plugin_assets tmp -type d \! -perm 755 -exec chmod 755 '{}' + 2>/dev/null || : - find config files log public/plugin_assets tmp -type f \! -perm 644 -exec chmod 644 '{}' + 2>/dev/null || : -} - -# allow the container to be started with `--user` -if [ -n "$isLikelyRedmine" ] && [ "$(id -u)" = '0' ]; then - _fix_permissions - exec gosu redmine "$BASH_SOURCE" "$@" +#!/bin/bash + +if [[ -v REDMINE_LANG ]]; +then +echo "REDMINE_LANG is already set: ${REDMINE_LANG}" +else +echo "Set REDMINE_LANG variable to: en" +export REDMINE_LANG="en" fi -if [ -n "$isLikelyRedmine" ]; then - _fix_permissions - if [ ! -f './config/database.yml' ]; then - file_env 'REDMINE_DB_MYSQL' - file_env 'REDMINE_DB_POSTGRES' - file_env 'REDMINE_DB_SQLSERVER' - - if [ "$MYSQL_PORT_3306_TCP" ] && [ -z "$REDMINE_DB_MYSQL" ]; then - export REDMINE_DB_MYSQL='mysql' - elif [ "$POSTGRES_PORT_5432_TCP" ] && [ -z "$REDMINE_DB_POSTGRES" ]; then - export REDMINE_DB_POSTGRES='postgres' - fi - - if [ "$REDMINE_DB_MYSQL" ]; then - adapter='mysql2' - host="$REDMINE_DB_MYSQL" - file_env 'REDMINE_DB_PORT' '3306' - file_env 'REDMINE_DB_USERNAME' "${MYSQL_ENV_MYSQL_USER:-root}" - file_env 'REDMINE_DB_PASSWORD' "${MYSQL_ENV_MYSQL_PASSWORD:-${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}" - file_env 'REDMINE_DB_DATABASE' "${MYSQL_ENV_MYSQL_DATABASE:-${MYSQL_ENV_MYSQL_USER:-redmine}}" - file_env 'REDMINE_DB_ENCODING' '' - elif [ "$REDMINE_DB_POSTGRES" ]; then - # adapter='postgresql' - adapter='postgis' - host="$REDMINE_DB_POSTGRES" - file_env 'REDMINE_DB_PORT' '5432' - file_env 'REDMINE_DB_USERNAME' "${POSTGRES_ENV_POSTGRES_USER:-postgres}" - file_env 'REDMINE_DB_PASSWORD' "${POSTGRES_ENV_POSTGRES_PASSWORD}" - file_env 'REDMINE_DB_DATABASE' "${POSTGRES_ENV_POSTGRES_DB:-${REDMINE_DB_USERNAME:-}}" - file_env 'REDMINE_DB_ENCODING' 'utf8' - elif [ "$REDMINE_DB_SQLSERVER" ]; then - adapter='sqlserver' - host="$REDMINE_DB_SQLSERVER" - file_env 'REDMINE_DB_PORT' '1433' - file_env 'REDMINE_DB_USERNAME' '' - file_env 'REDMINE_DB_PASSWORD' '' - file_env 'REDMINE_DB_DATABASE' '' - file_env 'REDMINE_DB_ENCODING' '' - else - echo >&2 - echo >&2 'warning: missing REDMINE_DB_MYSQL, REDMINE_DB_POSTGRES, or REDMINE_DB_SQLSERVER environment variables' - echo >&2 - echo >&2 '*** Using sqlite3 as fallback. ***' - echo >&2 - - adapter='sqlite3' - host='localhost' - file_env 'REDMINE_DB_PORT' '' - file_env 'REDMINE_DB_USERNAME' 'redmine' - file_env 'REDMINE_DB_PASSWORD' '' - file_env 'REDMINE_DB_DATABASE' 'sqlite/redmine.db' - file_env 'REDMINE_DB_ENCODING' 'utf8' +bundle exec rake generate_secret_token +bundle config set without 'development test' +bundle install +bundle exec rake db:create +bundle exec rake db:migrate +bundle exec rake redmine:plugins:migrate - mkdir -p "$(dirname "$REDMINE_DB_DATABASE")" - if [ "$(id -u)" = '0' ]; then - find "$(dirname "$REDMINE_DB_DATABASE")" \! -user redmine -exec chown redmine '{}' + - fi - fi +# Load default data and settings +bundle exec rake redmine:load_default_data - REDMINE_DB_ADAPTER="$adapter" - REDMINE_DB_HOST="$host" - echo "$RAILS_ENV:" > config/database.yml - for var in \ - adapter \ - host \ - port \ - username \ - password \ - database \ - encoding \ - ; do - env="REDMINE_DB_${var^^}" - val="${!env}" - [ -n "$val" ] || continue - echo " $var: \"$val\"" >> config/database.yml - done - fi - - # install additional gems for Gemfile.local and plugins - bundle check || bundle install - - if [ ! -s config/secrets.yml ]; then - file_env 'REDMINE_SECRET_KEY_BASE' - if [ -n "$REDMINE_SECRET_KEY_BASE" ]; then - cat > 'config/secrets.yml' <<-YML - $RAILS_ENV: - secret_key_base: "$REDMINE_SECRET_KEY_BASE" - YML - elif [ ! -f config/initializers/secret_token.rb ]; then - rake generate_secret_token - fi - fi - if [ "$1" != 'rake' -a -z "$REDMINE_NO_DB_MIGRATE" ]; then - rake db:migrate - fi - - if [ "$1" != 'rake' -a -n "$REDMINE_PLUGINS_MIGRATE" ]; then - rake redmine:plugins:migrate - fi - - # remove PID file to enable restarting the container - rm -f tmp/pids/server.pid - - if [ "$1" = 'passenger' ]; then - # Don't fear the reaper. - set -- tini -- "$@" - fi -fi +# Cleanup +rm -f tmp/pids/server.pid exec "$@" From dfef10b79f4ba689aacabc249420c8f59c59e92c Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Thu, 15 Sep 2022 15:51:26 +0900 Subject: [PATCH 4/9] Removes indents and unnecessary lines Signed-off-by: Daniel Kastl --- Dockerfile | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8f2c5b6..bf4ee11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,17 +28,17 @@ RUN set -eux; \ ca-certificates \ wget \ \ - # we need "gsfonts" for generating PNGs of Gantt charts - # and "ghostscript" for creating PDF thumbnails (in 4.1+) +# we need "gsfonts" for generating PNGs of Gantt charts +# and "ghostscript" for creating PDF thumbnails (in 4.1+) ghostscript \ gsfonts \ imagemagick \ - # grab gosu for easy step-down from root +# grab gosu for easy step-down from root gosu \ - # grab tini for signal processing and zombie killing +# grab tini for signal processing and zombie killing tini \ ; \ - # allow imagemagick to use ghostscript for PDF -> PNG thumbnail conversion (4.1+) +# allow imagemagick to use ghostscript for PDF -> PNG thumbnail conversion (4.1+) sed -ri 's/(rights)="none" (pattern="PDF")/\1="read" \2/' /etc/ImageMagick-6/policy.xml; \ rm -rf /var/lib/apt/lists/* @@ -54,10 +54,6 @@ RUN set -eux; \ chown redmine:redmine "$HOME"; \ chmod 1777 "$HOME" -# To support Redmine 5.0 -ENV GEM_RGEO_ACTIVERECORD_VERSION=7.0.1 -ENV GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION=7.1.1 - # Defined in docker-compose.yml ARG REDMINE_VERSION ARG REDMINE_DOWNLOAD_SHA256 @@ -84,7 +80,6 @@ RUN set -eux; \ savedAptMark="$(apt-mark showmanual)"; \ apt-get update; \ apt-get install -y --no-install-recommends \ - freetds-dev \ gcc \ libpq-dev \ libgeos-dev \ @@ -95,11 +90,11 @@ RUN set -eux; \ \ gosu redmine bundle config --local without 'development test'; \ gosu redmine bundle install --jobs "$(nproc)"; \ - # fix permissions for running as an arbitrary user +# fix permissions for running as an arbitrary user chmod -R ugo=rwX Gemfile.lock "$GEM_HOME"; \ rm -rf ~redmine/.bundle; \ \ - # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies +# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies apt-mark auto '.*' > /dev/null; \ [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ find /usr/local -type f -executable -exec ldd '{}' ';' \ From 0448392597c9e51256edc12d70874eeefc64e6eb Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Fri, 16 Sep 2022 11:22:28 +0900 Subject: [PATCH 5/9] Resolves suggestons Signed-off-by: Daniel Kastl --- docker-compose.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 176d6ee..6d50951 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: volumes: - postgis:/var/lib/postgresql/data healthcheck: - test: ["CMD", "pg_isready", "-U", "${DB_USER}", "-d", "${DB_NAME}"] + test: ["CMD", "pg_isready", "-U", "${DB_USER}", "-d", "${DB_NAME}", "-h", "postgis"] interval: 10s timeout: 2s retries: 5 @@ -32,9 +32,6 @@ services: - ./files:/usr/src/redmine/files - ./plugins:/usr/src/redmine/plugins - ./public/themes:/usr/src/redmine/public/themes - # Exclude node package and webpack contents folders - - /usr/src/redmine/plugins/redmine_gtt/node_modules - - /usr/src/redmine/plugins/redmine_gtt/assets/javascripts # TODO: remove the following line when adding GTT Print back - /usr/src/redmine/plugins/redmine_gtt_print depends_on: From e47af6b7861a2887414bec7e6c932d3c5ea8f2c5 Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Fri, 16 Sep 2022 11:24:40 +0900 Subject: [PATCH 6/9] Adds indents Signed-off-by: Daniel Kastl --- docker-entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 01e662b..f627758 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,10 +2,10 @@ if [[ -v REDMINE_LANG ]]; then -echo "REDMINE_LANG is already set: ${REDMINE_LANG}" + echo "REDMINE_LANG is already set: ${REDMINE_LANG}" else -echo "Set REDMINE_LANG variable to: en" -export REDMINE_LANG="en" + echo "Set REDMINE_LANG variable to: en" + export REDMINE_LANG="en" fi bundle exec rake generate_secret_token From 82de2a9c9d95ac4da0dedd4073f140ac0ef43b42 Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Fri, 16 Sep 2022 11:44:39 +0900 Subject: [PATCH 7/9] More system settings Signed-off-by: Daniel Kastl --- .env.example | 6 ++++++ config/puma.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index c7fb6cb..0bb6f21 100644 --- a/.env.example +++ b/.env.example @@ -17,3 +17,9 @@ SMTP_ENABLE_STARTTLS_AUTO=false # Setup REDMINE_LANG=en REDMINE_EMAIL=gtt@example.com + +# System +RAILS_ENV=production +RAILS_LOG_TO_STDOUT=1 +RAILS_MEMORY_LIMIT=1024 +PUMA_WORKERS=3 diff --git a/config/puma.rb b/config/puma.rb index c42024d..8a9e17e 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,4 +1,4 @@ -workers 3 +workers (ENV['PUMA_WORKERS'] || 3).to_i before_fork do require 'puma_worker_killer' From 25237808ddd0844b98eae96daf7d9e3e39b48463 Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Fri, 16 Sep 2022 12:19:54 +0900 Subject: [PATCH 8/9] Fixes ENV inconsstencies Signed-off-by: Daniel Kastl --- .env.example | 3 +-- config/configuration.yml | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 0bb6f21..f028914 100644 --- a/.env.example +++ b/.env.example @@ -11,8 +11,7 @@ SMTP_DOMAIN=smtp.example.com SMTP_PORT=1025 SMTP_USER_NAME=YOUR_EMAIL_ADDRESS SMTP_PASSWORD=YOUR_PASSWORD -SMTP_AUTHENTICATION=plain # (or login) -SMTP_ENABLE_STARTTLS_AUTO=false +SMTP_ENABLE_STARTTLS_AUTO=true # Setup REDMINE_LANG=en diff --git a/config/configuration.yml b/config/configuration.yml index ea2551c..b602ceb 100644 --- a/config/configuration.yml +++ b/config/configuration.yml @@ -21,10 +21,10 @@ default: email_delivery: delivery_method: :smtp smtp_settings: - enable_starttls_auto: true + enable_starttls_auto: <%= ENV['SMTP_ENABLE_STARTTLS_AUTO'] || true %> address: <%= ENV['SMTP_ADDRESS'] %> port: <%= ENV['SMTP_PORT'] || 587 %> domain: <%= ENV['SMTP_DOMAIN'] %> authentication: :plain - user_name: <%= ENV['EMAIL_ADDRESS'] %> - password: <%= ENV['SMTP_PASS'] %> + user_name: <%= ENV['SMTP_USER_NAME'] %> + password: <%= ENV['SMTP_PASSWORD'] %> From 79ad4994edb938955fcb8ef579f0a736b14119df Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Fri, 16 Sep 2022 12:33:14 +0900 Subject: [PATCH 9/9] Exclude js folders Signed-off-by: Daniel Kastl --- docker-compose.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 6d50951..a8c25f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,6 +32,10 @@ services: - ./files:/usr/src/redmine/files - ./plugins:/usr/src/redmine/plugins - ./public/themes:/usr/src/redmine/public/themes + # Exclude node package and webpack contents folders + # Needed to build with webpack! + - /usr/src/redmine/plugins/redmine_gtt/node_modules + - /usr/src/redmine/plugins/redmine_gtt/assets/javascripts # TODO: remove the following line when adding GTT Print back - /usr/src/redmine/plugins/redmine_gtt_print depends_on: