diff --git a/4.1/Dockerfile b/4.1/Dockerfile index 996a5cb..da5ba95 100644 --- a/4.1/Dockerfile +++ b/4.1/Dockerfile @@ -77,6 +77,10 @@ RUN set -eux; \ rm -rf /var/lib/apt/lists/*; \ \ gosu redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ # 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; \ diff --git a/4.1/alpine/Dockerfile b/4.1/alpine/Dockerfile index 16685a6..1734de8 100644 --- a/4.1/alpine/Dockerfile +++ b/4.1/alpine/Dockerfile @@ -75,6 +75,10 @@ RUN set -eux; \ ; \ \ su-exec redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ # 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; \ diff --git a/4.2/Dockerfile b/4.2/Dockerfile index 20abc30..69e33d9 100644 --- a/4.2/Dockerfile +++ b/4.2/Dockerfile @@ -77,6 +77,10 @@ RUN set -eux; \ rm -rf /var/lib/apt/lists/*; \ \ gosu redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ # 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; \ diff --git a/4.2/alpine/Dockerfile b/4.2/alpine/Dockerfile index 37b17dd..1734dcb 100644 --- a/4.2/alpine/Dockerfile +++ b/4.2/alpine/Dockerfile @@ -75,6 +75,10 @@ RUN set -eux; \ ; \ \ su-exec redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ # 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; \ diff --git a/5.0/Dockerfile b/5.0/Dockerfile new file mode 100644 index 0000000..2e4db88 --- /dev/null +++ b/5.0/Dockerfile @@ -0,0 +1,117 @@ +FROM ruby:3.1-slim-bullseye + +# 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 +RUN groupadd -r -g 999 redmine && useradd -r -g redmine -u 999 redmine + +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + 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+) + ghostscript \ + gsfonts \ + imagemagick \ +# grab gosu for easy step-down from root + gosu \ +# grab tini for signal processing and zombie killing + tini \ + ; \ +# 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/* + +ENV RAILS_ENV production +WORKDIR /usr/src/redmine + +# https://github.com/docker-library/redmine/issues/138#issuecomment-438834176 +# (bundler needs this for running as an arbitrary user) +ENV HOME /home/redmine +RUN set -eux; \ + [ ! -d "$HOME" ]; \ + mkdir -p "$HOME"; \ + chown redmine:redmine "$HOME"; \ + chmod 1777 "$HOME" + +ENV REDMINE_VERSION 5.0.0 +ENV REDMINE_DOWNLOAD_URL https://www.redmine.org/releases/redmine-5.0.0.tar.gz +ENV REDMINE_DOWNLOAD_SHA256 7e840dec846646dae52fff5c631b135d1c915d6e03ea6f01ca8f12ad35803bef + +RUN set -eux; \ +# if we use wget here, we get certificate issues (https://github.com/docker-library/redmine/pull/249#issuecomment-984176479) + curl -fL -o redmine.tar.gz "$REDMINE_DOWNLOAD_URL"; \ + 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 '{}' + + +RUN set -eux; \ + \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + default-libmysqlclient-dev \ + freetds-dev \ + gcc \ + libpq-dev \ + libsqlite3-dev \ + make \ + patch \ + ; \ + rm -rf /var/lib/apt/lists/*; \ + \ + gosu redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ +# 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 \ + 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 + 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 + apt-mark auto '.*' > /dev/null; \ + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ + find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { print $(NF-1) }' \ + | sort -u \ + | grep -v '^/usr/local/' \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual \ + ; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false + +VOLUME /usr/src/redmine/files + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] + +EXPOSE 3000 +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/5.0/alpine/Dockerfile b/5.0/alpine/Dockerfile new file mode 100644 index 0000000..63f18cb --- /dev/null +++ b/5.0/alpine/Dockerfile @@ -0,0 +1,114 @@ +FROM ruby:3.1-alpine3.15 + +# 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 +# alpine already has a gid 999, so we'll use the next id +RUN addgroup -S -g 1000 redmine && adduser -S -H -G redmine -u 999 redmine + +RUN set -eux; \ + apk add --no-cache \ + bash \ + ca-certificates \ + su-exec \ + tini \ + tzdata \ + wget \ + \ + breezy \ + git \ + mercurial \ + openssh-client \ + subversion \ + \ +# we need "gsfonts" for generating PNGs of Gantt charts +# and "ghostscript" for creating PDF thumbnails (in 4.1+) + ghostscript \ + ghostscript-fonts \ + imagemagick \ + ; + +ENV RAILS_ENV production +WORKDIR /usr/src/redmine + +# https://github.com/docker-library/redmine/issues/138#issuecomment-438834176 +# (bundler needs this for running as an arbitrary user) +ENV HOME /home/redmine +RUN set -eux; \ + [ ! -d "$HOME" ]; \ + mkdir -p "$HOME"; \ + chown redmine:redmine "$HOME"; \ + chmod 1777 "$HOME" + +ENV REDMINE_VERSION 5.0.0 +ENV REDMINE_DOWNLOAD_URL https://www.redmine.org/releases/redmine-5.0.0.tar.gz +ENV REDMINE_DOWNLOAD_SHA256 7e840dec846646dae52fff5c631b135d1c915d6e03ea6f01ca8f12ad35803bef + +RUN set -eux; \ + wget -O redmine.tar.gz "$REDMINE_DOWNLOAD_URL"; \ + 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 '{}' + + +# build for musl-libc, not glibc (see https://github.com/sparklemotion/nokogiri/issues/2075, https://github.com/rubygems/rubygems/issues/3174) +ENV BUNDLE_FORCE_RUBY_PLATFORM 1 +RUN set -eux; \ + \ + apk add --no-cache --virtual .build-deps \ + coreutils \ + freetds-dev \ + gcc \ + make \ + mariadb-dev \ + musl-dev \ + patch \ + postgresql-dev \ + sqlite-dev \ + ttf2ufm \ + zlib-dev \ + ; \ + \ + su-exec redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ +# 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 \ + echo "$adapter:" >> ./config/database.yml; \ + echo " adapter: $adapter" >> ./config/database.yml; \ + done; \ + su-exec redmine bundle install --jobs "$(nproc)"; \ + rm ./config/database.yml; \ +# fix permissions for running as an arbitrary user + chmod -R ugo=rwX Gemfile.lock "$GEM_HOME"; \ +# this requires coreutils because "chmod +X" in busybox will remove +x on files (and coreutils leaves files alone with +X) + rm -rf ~redmine/.bundle; \ + \ +# https://github.com/naitoh/rbpdf/issues/31 + rm /usr/local/bundle/gems/rbpdf-font-1.19.*/lib/fonts/ttf2ufm/ttf2ufm; \ + \ + runDeps="$( \ + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/bundle/gems \ + | tr ',' '\n' \ + | sort -u \ + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ + )"; \ + apk add --no-network --virtual .redmine-rundeps $runDeps; \ + apk del --no-network .build-deps + +VOLUME /usr/src/redmine/files + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] + +EXPOSE 3000 +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/5.0/alpine/docker-entrypoint.sh b/5.0/alpine/docker-entrypoint.sh new file mode 100755 index 0000000..9c57f07 --- /dev/null +++ b/5.0/alpine/docker-entrypoint.sh @@ -0,0 +1,156 @@ +#!/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 su-exec redmine "$BASH_SOURCE" "$@" +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' + 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' + + mkdir -p "$(dirname "$REDMINE_DB_DATABASE")" + if [ "$(id -u)" = '0' ]; then + find "$(dirname "$REDMINE_DB_DATABASE")" \! -user redmine -exec chown redmine '{}' + + fi + fi + + 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 + +exec "$@" diff --git a/5.0/docker-entrypoint.sh b/5.0/docker-entrypoint.sh new file mode 100755 index 0000000..6799776 --- /dev/null +++ b/5.0/docker-entrypoint.sh @@ -0,0 +1,156 @@ +#!/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" "$@" +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' + 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' + + mkdir -p "$(dirname "$REDMINE_DB_DATABASE")" + if [ "$(id -u)" = '0' ]; then + find "$(dirname "$REDMINE_DB_DATABASE")" \! -user redmine -exec chown redmine '{}' + + fi + fi + + 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 + +exec "$@" diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index 83f7a34..ebf7626 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -75,6 +75,10 @@ RUN set -eux; \ ; \ \ su-exec redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ # 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; \ diff --git a/Dockerfile-debian.template b/Dockerfile-debian.template index 8d6f095..5a90f28 100644 --- a/Dockerfile-debian.template +++ b/Dockerfile-debian.template @@ -77,6 +77,10 @@ RUN set -eux; \ rm -rf /var/lib/apt/lists/*; \ \ gosu redmine bundle config --local without 'development test'; \ +# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557 +# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time) + puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \ + { echo; echo "$puma"; } | sed -re 's/^[[:space:]]+//' >> Gemfile; \ # 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; \ diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index f265fb0..e0c950f 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -2,7 +2,8 @@ set -Eeuo pipefail declare -A aliases=( - [4.2]='4 latest' + [5.0]='5 latest' + [4.2]='4' ) self="$(basename "$BASH_SOURCE")" diff --git a/update.sh b/update.sh index 86dde95..8d9dd13 100755 --- a/update.sh +++ b/update.sh @@ -2,8 +2,9 @@ set -Eeuo pipefail # see https://www.redmine.org/projects/redmine/wiki/redmineinstall -defaultRubyVersion='2.7' +defaultRubyVersion='3.1' declare -A rubyVersions=( + [4.2]='2.7' [4.1]='2.6' ) @@ -50,7 +51,14 @@ for version in "${versions[@]}"; do rubyVersion="${rubyVersions[$version]:-$defaultRubyVersion}" - echo "$version: $fullVersion (ruby $rubyVersion; passenger $passenger)" + text="ruby $rubyVersion" + doPassenger= + if [ "$version" = '4.1' ] || [ "$version" = '4.2' ]; then + text+="; passenger $passenger" + doPassenger=1 + fi + + echo "$version: $fullVersion ($text)" commonSedArgs=( -r @@ -59,15 +67,18 @@ for version in "${versions[@]}"; do -e 's!%%REDMINE_DOWNLOAD_URL%%!'"$url"'!' -e 's/%%REDMINE_DOWNLOAD_SHA256%%/'"$sha256"'/' -e 's/%%REDMINE%%/redmine:'"$version"'/' - -e 's/%%PASSENGER_VERSION%%/'"$passenger"'/' ) mkdir -p "$version" cp docker-entrypoint.sh "$version/" sed "${commonSedArgs[@]}" Dockerfile-debian.template > "$version/Dockerfile" - mkdir -p "$version/passenger" - sed "${commonSedArgs[@]}" Dockerfile-passenger.template > "$version/passenger/Dockerfile" + if [ -n "$doPassenger" ]; then + mkdir -p "$version/passenger" + sed "${commonSedArgs[@]}" \ + -e 's/%%PASSENGER_VERSION%%/'"$passenger"'/' \ + Dockerfile-passenger.template > "$version/passenger/Dockerfile" + fi mkdir -p "$version/alpine" cp docker-entrypoint.sh "$version/alpine/"