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 postgres13 the default version when installing OpenProject (#9088)

Cyril Rohr588a5265313e
diff --git a/docker/ci/Dockerfile b/docker/ci/Dockerfile
index 82e14f56d22..57983c28bd3 100644
--- a/docker/ci/Dockerfile
+++ b/docker/ci/Dockerfile
@@ -1,4 +1,4 @@
-FROM ruby:2.7-buster
+FROM ruby:2.7.3-buster
MAINTAINER [email protected]
ENV NODE_VERSION="14.17.0"
@@ -15,7 +15,7 @@ RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/a
RUN apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
- postgresql-9.6 postgresql-client-9.6 time pandoc imagemagick libpq-dev default-jre-headless firefox-esr
+ postgresql-9.6 postgresql-client-9.6 postgresql-13 postgresql-client-13 time pandoc imagemagick libpq-dev default-jre-headless firefox-esr
RUN wget --no-verbose -O /tmp/$(basename $CHROME_SOURCE_URL) $CHROME_SOURCE_URL && \
apt install -y /tmp/$(basename $CHROME_SOURCE_URL) && rm -f /tmp/$(basename $CHROME_SOURCE_URL)
@@ -30,6 +30,7 @@ ENV CAPYBARA_DOWNLOADED_FILE_DIR=/tmp
# disable deprecations and other warnings in output
ENV RUBYOPT="-W0"
ENV DATABASE_URL=postgres://app:[email protected]/app
+ENV PGVERSION=13
RUN gem install bundler --version "$BUNDLER_VERSION" --no-document
diff --git a/docker/ci/entrypoint.sh b/docker/ci/entrypoint.sh
index 526e58b339a..762cad043d8 100755
--- a/docker/ci/entrypoint.sh
+++ b/docker/ci/entrypoint.sh
@@ -1,7 +1,7 @@
#!/bin/bash
set -e
-export PGBIN="$(pg_config --bindir)"
+export PGBIN="/usr/lib/postgresql/$PGVERSION/bin"
export JOBS="${CI_JOBS:=$(nproc)}"
# for parallel rspec
export PARALLEL_TEST_PROCESSORS=$JOBS
@@ -11,7 +11,7 @@ if [ $(id -u) -eq 0 ]; then
if [ ! -d "/tmp/nulldb" ]; then
su - postgres -c "$PGBIN/initdb -E UTF8 -D /tmp/nulldb"
su - postgres -c "$PGBIN/pg_ctl -D /tmp/nulldb -l /dev/null -w start"
- echo "create database app; create user app with superuser encrypted password 'p4ssw0rd'; grant all privileges on database app to app;" | su - postgres -c psql
+ echo "create database app; create user app with superuser encrypted password 'p4ssw0rd'; grant all privileges on database app to app;" | su - postgres -c $PGBIN/psql
fi
mkdir -p /usr/local/bundle
diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile
index dfa2850824f..4e8f7ac8565 100644
--- a/docker/prod/Dockerfile
+++ b/docker/prod/Dockerfile
@@ -1,4 +1,4 @@
-FROM ruby:2.7-buster
+FROM ruby:2.7.3-buster
MAINTAINER [email protected]
# Allow platform-specific additions. Valid values are: on-prem,saas,bahn
@@ -7,17 +7,15 @@ ARG PLATFORM=on-prem
ARG GITHUB_OAUTH_TOKEN
ARG DEBIAN_FRONTEND=noninteractive
-ARG PGLOADER_BINARY_DOWNLOAD_URL=https://openproject-docker-public.s3-eu-west-1.amazonaws.com/pgloader/bin/pgloader-ccl
-
ENV NODE_VERSION="14.17.0"
ENV BUNDLER_VERSION="2.1.4"
ENV BUNDLE_PATH__SYSTEM=false
ENV APP_USER=app
ENV APP_PATH=/app
ENV APP_DATA_PATH=/var/openproject/assets
-ENV APP_DATA_PATH_LEGACY=/var/db/openproject
ENV PGDATA=/var/openproject/pgdata
-ENV PGDATA_LEGACY=/var/lib/postgresql/9.6/main
+ENV PGVERSION="13"
+ENV PGBIN="/usr/lib/postgresql/$PGVERSION/bin"
ENV DATABASE_URL=postgres://openproject:[email protected]/openproject
ENV RAILS_ENV=production
@@ -33,8 +31,6 @@ ENV ATTACHMENTS_STORAGE_PATH=$APP_DATA_PATH/files
# Set a default key base, ensure to provide a secure value in production environments!
ENV SECRET_KEY_BASE=OVERWRITE_ME
-RUN curl ${PGLOADER_BINARY_DOWNLOAD_URL} > /usr/local/bin/pgloader-ccl && chmod +x /usr/local/bin/pgloader-ccl
-
WORKDIR $APP_PATH
COPY docker/prod/setup ./docker/prod/setup
diff --git a/docker/prod/entrypoint.sh b/docker/prod/entrypoint.sh
index c7649e68b83..74df37f79ea 100755
--- a/docker/prod/entrypoint.sh
+++ b/docker/prod/entrypoint.sh
@@ -5,39 +5,28 @@ set -o pipefail
APACHE_PIDFILE=/run/apache2/apache2.pid
-if [ -n "$DATABASE_URL" ]; then
- /usr/local/bin/migrate-mysql-to-postgres || exit 1
-fi
-
# handle legacy configs
-if [ -d "$PGDATA_LEGACY" ]; then
- echo "WARN: You are using a legacy volume path for your postgres data. You should mount your postgres volumes at $PGDATA instead of $PGDATA_LEGACY."
- if [ "$(find "$PGDATA" -type f | wc -l)" = "0" ]; then
- echo "INFO: $PGDATA is empty, so $PGDATA will be symlinked to $PGDATA_LEGACY as a temporary measure."
- sed -i "s|$PGDATA|$PGDATA_LEGACY|" /etc/postgresql/9.6/main/postgresql.conf
- export PGDATA="$PGDATA_LEGACY"
- else
- echo "ERROR: $PGDATA contains files, so we will not attempt to symlink $PGDATA to $PGDATA_LEGACY. Please fix your docker configuration."
- exit 2
- fi
+if [ -f "/var/lib/postgresql/9.6/main/PG_VERSION" ]; then
+ echo "ERROR: You are using a legacy volume path for your postgres data. You should mount your postgres volumes at $PGDATA instead of /var/lib/postgresql/9.6/main"
+ exit 2
fi
-
-if [ -d "$APP_DATA_PATH_LEGACY" ]; then
- echo "WARN: You are using a legacy volume path for your openproject data. You should mount your openproject volume at $APP_DATA_PATH instead of $APP_DATA_PATH_LEGACY."
- if [ "$(find "$APP_DATA_PATH" -type f | wc -l)" = "0" ]; then
- echo "INFO: $APP_DATA_PATH is empty, so $APP_DATA_PATH will be symlinked to $APP_DATA_PATH_LEGACY as a temporary measure."
- # also set ATTACHMENTS_STORAGE_PATH back to its legacy value in case it hasn't been changed
- if [ "$ATTACHMENTS_STORAGE_PATH" = "$APP_DATA_PATH/files" ]; then
- export ATTACHMENTS_STORAGE_PATH="$APP_DATA_PATH_LEGACY/files"
- fi
- export APP_DATA_PATH="$APP_DATA_PATH_LEGACY"
- else
- echo "ERROR: $APP_DATA_PATH contains files, so we will not attempt to symlink $APP_DATA_PATH to $APP_DATA_PATH_LEGACY. Please fix your docker configuration."
- exit 2
- fi
+if [ -d "/var/db/openproject" ]; then
+ echo "ERROR: You are using a legacy volume path for your openproject data. You should mount your openproject volume at $APP_DATA_PATH instead of /var/db/openproject"
+ exit 2
fi
if [ "$(id -u)" = '0' ]; then
+ # reexport PGVERSION and PGBIN env variables according to postgres version of existing cluster (if any)
+ # this must happen in the entrypoint
+ if [ -f "$PGDATA/PG_VERSION" ]; then
+ export PGVERSION="$(cat "$PGDATA/PG_VERSION")"
+ echo "-----> Existing PostgreSQL cluster found in $PGDATA."
+ fi
+ export PGBIN="/usr/lib/postgresql/$PGVERSION/bin"
+ export PGCONF_FILE="/etc/postgresql/$PGVERSION/main/postgresql.conf"
+ echo "-----> Setting PGVERSION=$PGVERSION PGBIN=$PGBIN PGCONF_FILE=$PGCONF_FILE"
+ export PATH="$PGBIN:$PATH"
+
mkdir -p $APP_DATA_PATH/{files,git,svn}
chown -R $APP_USER:$APP_USER $APP_DATA_PATH
if [ -d /etc/apache2/sites-enabled ]; then
diff --git a/docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres b/docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres
deleted file mode 100755
index 6b11e9edb29..00000000000
--- a/docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres
+++ /dev/null
@@ -1,221 +0,0 @@
-#!/usr/bin/env ruby
-require 'uri'
-
-db_url = URI(ENV.fetch("DATABASE_URL"))
-mysql_url = URI(ENV.fetch("MYSQL_DATABASE_URL")) if ENV.has_key?("MYSQL_DATABASE_URL")
-pgloader_path = ENV.fetch('PGLOADER_PATH', 'pgloader-ccl')
-
-if db_url.scheme.start_with?("mysql")
- puts "WARNING: You are running MySQL. OpenProject will drop support for MySQL in 10.0."
- puts " We can convert it to Postgres for you. Please setup postgres and "
- puts " rerun this with MYSQL_DATABASE_URL pointing to your original database "
- puts " and DATABASE_URL pointing to a new Postgres database."
- puts ""
- puts "EXAMPLE: docker run \\"
- puts " -e MYSQL_DATABASE_URL=mysql://openproject:<PASSWORD>@localhost:3306/openproject \\"
- puts " -e DATABASE_URL=postgresql://openproject:<PASSWORD>@localhost:5432/openproject \\"
- puts " -it openproject/community:latest"
-
- exit 0 # MySQL still supported until 9.x - with 10.0 we must make this an error (exit 1)
-end
-
-if db_url.scheme.start_with?("postgres") && mysql_url.nil?
- # nothing to do
- exit 0
-end
-
-# Correct the URL scheme
-if mysql_url.scheme == 'mysql2'
- mysql_url.scheme = 'mysql'
-end
-
-filtered_mysql_url = mysql_url.dup.tap { |url| url.password = "REDACTED" }
-filtered_db_url = db_url.dup.tap { |url| url.password = "REDACTED" }
-
-puts "Migrating database from MySQL to PostgreSQL."
-puts
-puts "Import"
-puts " MySQL database"
-puts " #{filtered_mysql_url}"
-puts " into Postgres database "
-puts " #{filtered_db_url}"
-puts " ?"
-puts "WARNING: This resets the given Postgres database."
-puts
-print "Y/n "
-
-answer = ENV.fetch("FORCE_YES") { gets.chomp }
-
-if answer.downcase == "n"
- exit 0
-end
-
-db_user = db_url.user
-db_password = db_url.password
-db_host = db_url.host
-db_port = db_url.port
-db_name = db_url.path.sub("/", "")
-db_port ||= 5432
-
-if [db_host, db_name, db_port].any? { |value| [nil, ""].include?(value) }
- puts "ERROR: Could not parse database URL (#{filtered_db_url})"
-
- exit 1
-end
-
-require 'pty'
-
-# Memcached is not yet running at this point so we use the file cache store.
-# This will and is supposed to affect the spawned ruby processes.
-ENV["RAILS_CACHE_STORE"] = "file_store"
-
-def run(cmd, silent: false, record_output: true)
- output = []
-
- PTY.spawn(cmd) do |stdout, stdin, pid|
- begin
- stdout.each do |line|
- output << line if record_output
- puts line unless silent
- end
- rescue Errno::EIO
- # raised when stdout is closed after process finished
- ensure
- stdout.close
- stdin.close
- end
-
- Process.wait pid
- end
-
- [output.join("\n").strip, $?.to_i]
-end
-
-unless ENV['SKIP_OPENPROJECT_DB_RESET'] == 'true'
- puts "Resetting target database..."
- drop_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d postgres -c 'DROP DATABASE IF EXISTS #{db_name}'"
- drop_output, dropped_status = run drop_cmd, silent: true
-
- if dropped_status == 0
- # that's ok then we don't have to drop it or dropped database successfully
- puts "Database dropped (or was not present)"
- else
- puts drop_output
- exit 1 # something went wrong
- end
-
- puts "Creating database..."
- create_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d postgres -c 'CREATE DATABASE #{db_name}'"
- create_output, = run create_cmd, silent: true
-
- if create_output == "CREATE DATABASE"
- # created database successfully
- else
- puts create_output
- exit 1 # something went wrong
- end
-end
-
-puts "Importing database ..."
-
-mysql_url.query = nil
-mysql_url.scheme = "mysql"
-_, pgloader_status = run "#{pgloader_path} --verbose #{mysql_url} #{db_url}", record_output: false
-
-if pgloader_status != 0
- puts "\nFailed to import MySQL database into Postgres. See above."
-
- exit 1
-end
-
-mysql_db_name = mysql_url.path.sub("/", "")
-if mysql_db_name != 'public'
- puts "Renaming to public schema"
- rename_schema_cmd = "PGPASSWORD=#{db_password} psql -o /dev/stdout -U #{db_user} -h #{db_host} -p #{db_port} -d #{db_name} -c \"DROP schema public; ALTER schema #{mysql_db_name} RENAME to public;\""
- check_output, check_status = run rename_schema_cmd, silent: false
-
- if check_status != 0
- puts check_output
- puts "Failed to rename schema #{mysql_db_name} to public. See above."
-
- exit 1
- end
-end
-
-check_fulltext_cmd = "PGPASSWORD=#{db_password} psql -o /dev/stdout -U #{db_user} -h #{db_host} -p #{db_port} -d #{db_name} -c \"select 'true' from schema_migrations where version = '20180122135443'\""
-check_output, check_status = run check_fulltext_cmd, silent: true
-
-if check_status != 0
- puts check_output
- puts "Failed to check full-text status of database. See above."
-
- exit 1
-end
-
-# We need to ensure primary keys get renamed to `<table_name>_pkey`
-# because pgloader uses unique index names and we will otherwise be unable
-# to rename them in the future
-puts "Renaming primary keys"
-
-_, redo_status = run "bundle exec rake db:migrate:redo VERSION=20190502102512", record_output: false
-
-if redo_status != 0
- puts "\nRenaming of indices for PostgreSQL failed. See above."
-
- exit 1
-end
-
-# if the version was present on MySQL already we need to redo it to
-# add the postgres specific columns.
-needs_fulltext_migration = check_output.include?("true")
-
-puts "Running OpenProject migrations ..."
-
-_, migrate_status = run "bundle exec rake db:migrate", record_output: false
-
-if migrate_status != 0
- puts "\nMigration failed. See above."
-end
-
-puts "\nRe-building DAG to create Postgres-specific indices"
-_, dag_status = run "bundle exec rake db:migrate:redo VERSION=20180105130053", record_output: false
-
-if dag_status != 0
- puts "\nRebuild DAG migration failed. See above."
-
- exit 1
-end
-
-if needs_fulltext_migration
- drop_version_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d #{db_name} -c \"delete from schema_migrations where version = '20180122135443'\""
- drop_version_output, drop_version_status = run drop_version_cmd, silent: true
-
- if drop_version_status != 0
- puts drop_version_output
- puts "Failed to drop schema_migrations entry. See above."
-
- exit 1
- end
-
- puts "Running full-text search migration"
-
- _, redo_status = run "bundle exec rake db:migrate:redo VERSION=20180122135443", record_output: false
-
- if redo_status != 0
- puts "\nFull-text search migration failed. See above."
-
- exit 1
- end
-
- _, extract_status = run "bundle exec rake attachments:schedule_fulltext_extraction_where_missing", record_output: false
-
- if extract_status == 0
- puts "\nFull-text extraction for attachments have successfully been requested in background jobs."
- else
- puts "\nFull-text extraction failed. See above."
-
- exit 1
- end
-end
-
-puts "Migration from MySQL to Postgres completed successfully!"
diff --git a/docker/prod/postgres-db-init b/docker/prod/postgres-db-init
new file mode 100755
index 00000000000..dd6c1226b51
--- /dev/null
+++ b/docker/prod/postgres-db-init
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+set -o pipefail
+
+PGUSER=${PGUSER:=postgres}
+PGPASSWORD=${PGPASSWORD:=postgres}
+chown -R postgres.postgres "$PGDATA"
+pwfile=$(mktemp)
+echo "$PGPASSWORD" > $pwfile
+chown postgres $pwfile
+su postgres -c "$PGBIN/initdb --pgdata=${PGDATA} --username=${PGUSER} --encoding=unicode --auth=trust --pwfile=$pwfile"
+rm -f $pwfile
diff --git a/docker/prod/postgres-db-upgrade b/docker/prod/postgres-db-upgrade
new file mode 100755
index 00000000000..1f94997c802
--- /dev/null
+++ b/docker/prod/postgres-db-upgrade
@@ -0,0 +1,33 @@
+#!/bin/bash
+set -e
+set -o pipefail
+
+CURRENT_PGVERSION="$(cat $PGDATA/PG_VERSION)"
+NEW_PGVERSION="13"
+
+if [ "$CURRENT_PGVERSION" == "$NEW_PGVERSION" ]; then
+ echo "Current and new postgres version are identical. Aborting."
+ exit 1
+fi
+
+export PGBINOLD="/usr/lib/postgresql/$CURRENT_PGVERSION/bin"
+export PGBINNEW="/usr/lib/postgresql/$NEW_PGVERSION/bin"
+export PGDATAOLD="$PGDATA"
+if [ "$OPENPROJECT_INSTALLATION__TYPE" == "docker" ]; then
+ export PGDATANEW="$PGDATA-next"
+else
+ export PGDATANEW="/var/lib/postgresql/$NEW_PGVERSION/main"
+fi
+
+if [ ! -d "$PGDATANEW" ]; then
+ echo "$PGDATANEW does not exist."
+ exit 1
+fi
+
+if [ ! -f "$PGDATANEW/PG_VERSION" ]; then
+ echo "Empty cluster found in $PGDATANEW. Generating cluster..."
+ PGBIN=$PGBINNEW PGDATA=$PGDATANEW ./docker/prod/postgres-db-init
+fi
+
+cd /var/lib/postgresql
+su -m postgres -c "$PGBINNEW/pg_upgrade"
diff --git a/docker/prod/setup/postinstall.sh b/docker/prod/setup/postinstall.sh
index 3247d40bc22..416eb24c813 100755
--- a/docker/prod/setup/postinstall.sh
+++ b/docker/prod/setup/postinstall.sh
@@ -13,9 +13,6 @@ display_error() {
echo " ---> POSTINSTALL"
-# Add MySQL-to-Postgres migration script to path (used in entrypoint.sh)
-cp ./docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres /usr/local/bin/
-
# Ensure we can write in /tmp/op_uploaded_files (cf. #29112)
mkdir -p /tmp/op_uploaded_files/ && chown -R $APP_USER:$APP_USER /tmp/op_uploaded_files/
diff --git a/docker/prod/setup/preinstall-common.sh b/docker/prod/setup/preinstall-common.sh
index ea60f6a78d5..5d9366b8a57 100755
--- a/docker/prod/setup/preinstall-common.sh
+++ b/docker/prod/setup/preinstall-common.sh
@@ -19,9 +19,13 @@ apt-get install -y \
catdoc \
postgresql-9.6 \
postgresql-client-9.6 \
+ postgresql-13 \
+ postgresql-client-13 \
imagemagick
-rm -rf "$PGDATA_LEGACY"
+# remove any existing cluster
+service postgresql stop
+rm -rf /var/lib/postgresql/{9.6,13}
# Specifics for BIM edition
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
diff --git a/docker/prod/supervisord b/docker/prod/supervisord
index f2fe4587b8e..3f6c3ee6b4b 100755
--- a/docker/prod/supervisord
+++ b/docker/prod/supervisord
@@ -4,7 +4,7 @@ set -e
set -o pipefail
indent() {
- sed -u 's/^/ /'
+ sed '/^-----> /! s/^/ /'
}
echo "-----> Starting the all-in-one OpenProject setup at $BASH_SOURCE..."
@@ -14,18 +14,10 @@ if [ "$PGDATA" == "" ]; then
exit 2
fi
-export PGBIN="$(pg_config --bindir)"
-export PGCONF_FILE="/etc/postgresql/9.6/main/postgresql.conf"
-PGUSER=${PGUSER:=postgres}
-PGPASSWORD=${PGPASSWORD:=postgres}
PG_STARTUP_WAIT_TIME=${PG_STARTUP_WAIT_TIME:=10}
SUPERVISORD_LOG_LEVEL=${SUPERVISORD_LOG_LEVEL:=info}
dbhost=$(ruby -ruri -e 'puts URI(ENV.fetch("DATABASE_URL")).host')
-pwfile=$(mktemp)
-echo "$PGPASSWORD" > $pwfile
-chown postgres $pwfile
-
PLUGIN_GEMFILE_TMP=$(mktemp)
PLUGIN_GEMFILE=$APP_PATH/Gemfile.local
@@ -69,8 +61,10 @@ migrate() {
wait_for_postgres
pushd $APP_PATH >/dev/null
/etc/init.d/memcached start
+ echo "-----> Running migrations..."
bundle exec rake db:migrate
# run seed as app user so created attachments (and folder) belong to app, not root
+ echo "-----> Seeding database..."
su app -c 'bundle exec rake db:seed'
/etc/init.d/memcached stop
popd >/dev/null
@@ -103,8 +97,9 @@ configure_local_postgres() {
rm -f $PGDATA/postmaster.pid
# Set up pg defaults
- echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.6/main/pg_hba.conf
+ echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf
echo "listen_addresses='0.0.0.0'" >> "$PGCONF_FILE"
+ echo "port=5432" >> "$PGCONF_FILE"
echo "data_directory='$PGDATA'" >> "$PGCONF_FILE"
}
@@ -114,26 +109,26 @@ if [ "$dbhost" = "127.0.0.1" ]; then
# initialize cluster if it does not exist yet
if [ -f "$PGDATA/PG_VERSION" ]; then
echo "-----> Database cluster already exists, not modifying."
- su - postgres -c "$PGBIN/pg_ctl -w -l /dev/null -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
- (install_plugins && migrate) | indent
+ su - postgres -c "$PGBIN/pg_ctl -l /tmp/log -w -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
+ (install_plugins && migrate) 2>&1 | indent
su - postgres -c "$PGBIN/pg_ctl -D '$PGDATA' stop" | indent
else
echo "-----> Database cluster not found. Creating a new one in $PGDATA..."
- su postgres -c "$PGBIN/initdb --pgdata=${PGDATA} --username=${PGUSER} --encoding=unicode --auth=trust --pwfile=$pwfile" | indent
- su postgres -c "rm -f $pwfile"
- su - postgres -c "$PGBIN/pg_ctl -w -l /dev/null -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
+ PGBIN=$PGBIN PGDATA=$PGDATA ./docker/prod/postgres-db-init | indent
+ su postgres -c "$PGBIN/pg_ctl -w -l /dev/null -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
su postgres -c "$PGBIN/psql --command \"CREATE USER openproject WITH SUPERUSER PASSWORD 'openproject';\"" | indent
su postgres -c "$PGBIN/createdb -O openproject openproject" | indent
- (install_plugins && migrate) | indent
+ (install_plugins && migrate) 2>&1 | indent
su - postgres -c "$PGBIN/pg_ctl -D '$PGDATA' stop" | indent
fi
else
echo "-----> You're using an external database. Not initializing a local database cluster."
- migrate | indent
+ migrate 2>&1 | indent
fi
echo "-----> Database setup finished."
echo " On first installation, the default admin credentials are login: admin, password: admin"
echo "-----> Launching supervisord..."
-exec /usr/bin/supervisord -c $APP_PATH/docker/prod/supervisord.conf -e ${SUPERVISORD_LOG_LEVEL}
+erb -r uri $APP_PATH/docker/prod/supervisord.conf.erb > /etc/supervisor/supervisord.conf
+exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf -e ${SUPERVISORD_LOG_LEVEL}
diff --git a/docker/prod/supervisord.conf b/docker/prod/supervisord.conf.erb
similarity index 96%
rename from docker/prod/supervisord.conf
rename to docker/prod/supervisord.conf.erb
index e4579373d2b..aee970f9c58 100644
--- a/docker/prod/supervisord.conf
+++ b/docker/prod/supervisord.conf.erb
@@ -1,5 +1,6 @@
[supervisord]
nodaemon=true
+user=root
[unix_http_server]
file=/var/run/supervisor.sock
@@ -76,6 +77,7 @@ stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0
+<% if URI(ENV.fetch("DATABASE_URL")).host == "127.0.0.1" %>
[program:postgres]
user=postgres
priority=1
@@ -85,3 +87,4 @@ stderr_logfile = /dev/stderr
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0
+<% end %>
diff --git a/docs/installation-and-operations/installation/docker/README.md b/docs/installation-and-operations/installation/docker/README.md
index 7dbbd6d1f15..a975fe87f8a 100644
--- a/docs/installation-and-operations/installation/docker/README.md
+++ b/docs/installation-and-operations/installation/docker/README.md
@@ -20,6 +20,8 @@ OpenProject with Docker can be launched in two ways:
2. One container with all the processes inside. Easy but not recommended for production. This is the legacy behaviour.
+<a name="compose-based-docker-installation"></a>
+
## One container per process (recommended)
### Quick Start
@@ -58,6 +60,8 @@ You can stop the Compose stack by running:
docker-compose down
```
+<a name="all-in-one-docker-installation"></a>
+
## All-in-one container
### Quick Start
diff --git a/docs/installation-and-operations/misc/migration-to-postgresql13/README.md b/docs/installation-and-operations/misc/migration-to-postgresql13/README.md
new file mode 100644
index 00000000000..200d0a455bc
--- /dev/null
+++ b/docs/installation-and-operations/misc/migration-to-postgresql13/README.md
@@ -0,0 +1,178 @@
+# Migrating your OpenProject installation to PostgreSQL 13
+
+OpenProject version 12+ will default to PostgreSQL 13. If you have an existing OpenProject installation, please follow the guide below to upgrade your PostgreSQL version.
+
+## Package-based installation
+
+<div class="alert alert-info" role="alert">
+Please follow this section only if you have installed OpenProject using [this procedure][package-based-installation].
+
+Before attempting the upgrade, please ensure you have performed a backup of your installation by following the [backup guide][backup-guide].
+</div>
+
+In the following, we assume that you initially let OpenProject setup your PostgreSQL installation, using a local database. If you are using an external database, please follow the instructions from your provider, or adapt the instructions given below.
+
+1. First, connect to your server and make sure your local version is PostgreSQL v10:
+
+```bash
+sudo cat /var/lib/postgresql/10/main/PG_VERSION
+10
+```
+
+2. Install the new version of PostgreSQL:
+
+For Debian/Ubuntu:
+
+```bash
+sudo apt-get update
+sudo apt-get install postgresql-13
+```
+
+For RedHat/CentOS:
+
+```bash
+sudo yum install postgresql-13
+```
+
+For SLES:
+
+```bash
+sudo zypper install postgresql-13
+```
+
+3. Stop the PostgreSQL servers:
+
+```bash
+sudo su - postgres -c "/usr/lib/postgresql/10/bin/pg_ctl stop --wait --pgdata=/var/lib/postgresql/10/main"
+sudo su - postgres -c "/usr/lib/postgresql/13/bin/pg_ctl stop --wait --pgdata=/var/lib/postgresql/13/main"
+```
+
+4. Migrate your data to PostgreSQL 13:
+
+```bash
+sudo su - postgres <<CMD
+/usr/lib/postgresql/13/bin/pg_upgrade \
+ --old-bindir=/usr/lib/postgresql/10/bin \
+ --new-bindir=/usr/lib/postgresql/13/bin \
+ --old-datadir=/var/lib/postgresql/10/main \
+ --new-datadir=/var/lib/postgresql/13/main \
+ --old-options '-c config_file=/etc/postgresql/10/main/postgresql.conf' \
+ --new-options '-c config_file=/etc/postgresql/13/main/postgresql.conf'
+CMD
+
+5. Make PostgreSQL v13 the new default server to run on port 45432:
+
+```bash
+sudo su - postgres -c "cp /etc/postgresql/{10,13}/main/conf.d/custom.conf"
+sudo su - postgres -c "sed -i 's|45432|45433|' /etc/postgresql/10/main/conf.d/custom.conf"
+sudo su - postgres -c "/usr/lib/postgresql/13/bin/pg_ctl start --wait --pgdata=/var/lib/postgresql/13/main -o '-c config_file=/etc/postgresql/13/main/postgresql.conf'"
+```
+
+6. Check your OpenProject installation. A version higher than `13` should be displayed for `PostgreSQL version` in the "Administration > Information" section.
+
+7. If everything is fine, you can then remove your older PostgreSQL installation:
+
+```bash
+rm -rf /var/lib/postgresql/10/main
+# you can optionally go further and purge postgresql-10 from your system if you wish
+sudo apt-get purge postgresql-10 # debian/ubuntu
+sudo yum remove postgresql-10 # rhel/centos
+sudo zypper remove postgresql-10 # sles
+```
+
+[pg_upgrade]: https://www.postgresql.org/docs/10/pgupgrade.html
+
+### Debian/Ubuntu
+
+Refresh your package list:
+
+```bash
+apt-get update
+apt-get -y install postgresql-13
+
+[package-based-installation]: https://docs.openproject.org/installation-and-operations/installation/packaged/
+
+## Compose-based docker installation
+
+<div class="alert alert-info" role="alert">
+Please follow this section only if you have installed OpenProject using [this procedure][compose-based-installation].
+
+Before attempting the upgrade, please ensure you have performed a backup of your installation by following the [backup guide][backup-guide].
+</div>
+
+[compose-based-installation]: https://docs.openproject.org/installation-and-operations/installation/docker/#compose-based-docker-installation
+
+## All-in-one docker installation
+
+<div class="alert alert-info" role="alert">
+Please follow this section only if you have installed OpenProject using [this procedure][all-in-one-docker-installation].
+
+Before attempting the upgrade, please ensure you have performed a backup of your installation by following the [backup guide][backup-guide].
+</div>
+
+The newer version of OpenProject includes an utility to automatically perform the upgrade for you. Assuming you followed the standard installation procedure, the folder (within the docker container) containing your PostgreSQL data will be located at `/var/openproject/pgdata`.
+
+Then the goal is to take this folder, and apply `pg_upgrade` on it. This will generate an upgraded cluster in another folder. We can finally switch the old postgres folder with the upgraded one and restart the container.
+
+First, ensure that you have stopped your container:
+
+```bash
+docker stop openproject
+```
+
+Once the docker has stopped, you are ready to run the upgrade command. In this case, we assume that your existing PostgreSQL data is stored on the host at `/var/lib/openproject/pgdata`. We will also map a local folder named `/var/lib/openproject/pgdata-next` to a special volume in the container, named `/var/openproject/pgdata-next`. This volume will contain the upgraded cluster:
+
+```bash
+docker run --rm -it \
+ -v /var/lib/openproject/pgdata:/var/openproject/pgdata \
+ -v /var/lib/openproject/pgdata-next:/var/openproject/pgdata-next \
+ openproject/community:12 root ./docker/prod/postgres-db-upgrade
+```
+
+If everything goes well, the process should end with a message as follows:
+
+```
+Upgrade Complete
+----------------
+Optimizer statistics are not transferred by pg_upgrade so,
+once you start the new server, consider running:
+ ./analyze_new_cluster.sh
+
+Running this script will delete the old cluster's data files:
+ ./delete_old_cluster.sh
+```
+
+You can then perform the following operation to switch the upgraded PostgreSQL with the older version:
+
+```bash
+sudo mv /var/lib/openproject/pgdata /var/lib/openproject/pgdata-prev
+sudo mv /var/lib/openproject/pgdata-next /var/lib/openproject/pgdata
+```
+
+Finally, you can restart OpenProject with the same command that you used before. For instance:
+
+docker run -d -p 8080:80 --name openproject -e SECRET_KEY_BASE=secret \
+ -v /var/lib/openproject/pgdata:/var/openproject/pgdata \
+ -v /var/lib/openproject/assets:/var/openproject/assets \
+ [...]
+ openproject/community:12
+
+If your new installation looks fine, you can then choose to remove `/var/lib/openproject/pgdata-prev`:
+
+```bash
+sudo rm -rf /var/lib/openproject/pgdata-prev
+```
+
+If you encounter an issue, you can switch back to the previous PostgreSQL folder by reverting the folder switch:
+
+```bash
+sudo mv /var/lib/openproject/pgdata /var/lib/openproject/pgdata-next
+sudo mv /var/lib/openproject/pgdata-prev /var/lib/openproject/pgdata
+```
+
+And then restart OpenProject.
+
+[all-in-one-docker-installation]: https://docs.openproject.org/installation-and-operations/installation/docker/#all-in-one-docker-installation
+
+[backup-guide]:
+https://docs.openproject.org/installation-and-operations/operation/backing-up/
\ No newline at end of file
diff --git a/docs/installation-and-operations/operation/upgrading/README.md b/docs/installation-and-operations/operation/upgrading/README.md
index 3333a8a341e..737152cafbf 100644
--- a/docs/installation-and-operations/operation/upgrading/README.md
+++ b/docs/installation-and-operations/operation/upgrading/README.md
@@ -61,7 +61,7 @@ Note that this still takes previous values into consideration. Values that shoul
</div>
-## Docker-based installation
+## Compose-based installation
When using the Compose-based docker installation, you can simply do the following:
diff --git a/lib/open_project/database.rb b/lib/open_project/database.rb
index c816d98de69..ad2d3d1366a 100644
--- a/lib/open_project/database.rb
+++ b/lib/open_project/database.rb
@@ -43,6 +43,8 @@ module OpenProject
class UnsupportedDatabaseError < StandardError; end
+ class DeprecatedVersionWarning < StandardError; end
+
# This method returns a hash which maps the identifier of the supported
# adapter to a regex matching the adapter_name.
def self.supported_adapters
@@ -104,13 +106,18 @@ module OpenProject
"but current version is #{current}"
raise InsufficientVersionError.new message
+ elsif !version_matches?(130000)
+ message = "The next major release of OpenProject (v12) will require PostgreSQL 13 or later.\n" \
+ "You can anticipate this upgrade by updating your database installation by following the guide at " \
+ "https://docs.openproject.org/installation-and-operations/misc/migration-to-postgresql13/"
+ raise DeprecatedVersionWarning.new message
end
end
##
# Return +true+ if the required version is matched by the current connection.
- def self.version_matches?
- numeric_version >= required_version[:numeric]
+ def self.version_matches?(required_numeric_version = nil)
+ numeric_version >= (required_numeric_version || required_version[:numeric])
end
# Get the raw name of the currently used database adapter.
diff --git a/lib/tasks/database.rake b/lib/tasks/database.rake
index 5e243a828e3..9940bf3fc3e 100644
--- a/lib/tasks/database.rake
+++ b/lib/tasks/database.rake
@@ -62,6 +62,7 @@ namespace 'openproject' do
OpenProject::Database::check!
rescue OpenProject::Database::UnsupportedDatabaseError => e
warn <<~MESSAGE
+
---------------------------------------------------
DATABASE UNSUPPORTED ERROR
@@ -74,6 +75,7 @@ namespace 'openproject' do
Kernel.exit(1)
rescue OpenProject::Database::InsufficientVersionError => e
warn <<~MESSAGE
+
---------------------------------------------------
DATABASE INCOMPATIBILITY ERROR
@@ -84,6 +86,15 @@ namespace 'openproject' do
---------------------------------------------------
MESSAGE
Kernel.exit(1)
+ rescue OpenProject::Database::DeprecatedVersionWarning => e
+ warn <<~MESSAGE
+
+ ---------------------------------------------------
+ DATABASE DEPRECATION WARNING
+
+ #{e.message}
+ ---------------------------------------------------
+ MESSAGE
rescue ActiveRecord::ActiveRecordError => e
warn "Failed to perform postgres version check: #{e} - #{e.message}. #{override_msg}"
raise e