docker-entrypoint.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. set -e
  3. case "$1" in
  4. rails|rake|passenger)
  5. if [ ! -f './config/database.yml' ]; then
  6. if [ "$MYSQL_PORT_3306_TCP" ]; then
  7. adapter='mysql2'
  8. host='mysql'
  9. port="${MYSQL_PORT_3306_TCP_PORT:-3306}"
  10. username="${MYSQL_ENV_MYSQL_USER:-root}"
  11. password="${MYSQL_ENV_MYSQL_PASSWORD:-$MYSQL_ENV_MYSQL_ROOT_PASSWORD}"
  12. database="${MYSQL_ENV_MYSQL_DATABASE:-${MYSQL_ENV_MYSQL_USER:-redmine}}"
  13. encoding=
  14. elif [ "$POSTGRES_PORT_5432_TCP" ]; then
  15. adapter='postgresql'
  16. host='postgres'
  17. port="${POSTGRES_PORT_5432_TCP_PORT:-5432}"
  18. username="${POSTGRES_ENV_POSTGRES_USER:-postgres}"
  19. password="${POSTGRES_ENV_POSTGRES_PASSWORD}"
  20. database="${POSTGRES_ENV_POSTGRES_DB:-$username}"
  21. encoding=utf8
  22. else
  23. echo >&2 'warning: missing MYSQL_PORT_3306_TCP or POSTGRES_PORT_5432_TCP environment variables'
  24. echo >&2 ' Did you forget to --link some_mysql_container:mysql or some-postgres:postgres?'
  25. echo >&2
  26. echo >&2 '*** Using sqlite3 as fallback. ***'
  27. adapter='sqlite3'
  28. host='localhost'
  29. username='redmine'
  30. database='sqlite/redmine.db'
  31. encoding=utf8
  32. mkdir -p "$(dirname "$database")"
  33. chown -R redmine:redmine "$(dirname "$database")"
  34. fi
  35. cat > './config/database.yml' <<-YML
  36. $RAILS_ENV:
  37. adapter: $adapter
  38. database: $database
  39. host: $host
  40. username: $username
  41. password: "$password"
  42. encoding: $encoding
  43. port: $port
  44. YML
  45. fi
  46. # ensure the right database adapter is active in the Gemfile.lock
  47. bundle install --without development test
  48. if [ ! -s config/secrets.yml ]; then
  49. if [ "$REDMINE_SECRET_KEY_BASE" ]; then
  50. cat > 'config/secrets.yml' <<-YML
  51. $RAILS_ENV:
  52. secret_key_base: "$REDMINE_SECRET_KEY_BASE"
  53. YML
  54. elif [ ! -f /usr/src/redmine/config/initializers/secret_token.rb ]; then
  55. rake generate_secret_token
  56. fi
  57. fi
  58. if [ "$1" != 'rake' -a -z "$REDMINE_NO_DB_MIGRATE" ]; then
  59. gosu redmine rake db:migrate
  60. fi
  61. chown -R redmine:redmine files log public/plugin_assets
  62. # remove PID file to enable restarting the container
  63. rm -f /usr/src/redmine/tmp/pids/server.pid
  64. if [ "$1" = 'passenger' ]; then
  65. # Don't fear the reaper.
  66. set -- tini -- "$@"
  67. fi
  68. set -- gosu redmine "$@"
  69. ;;
  70. esac
  71. exec "$@"