From 2815b702c3aa4b822bf4e967257915ff8837db30 Mon Sep 17 00:00:00 2001 From: Cyril Rohr Date: Mon, 28 Jul 2014 12:52:18 +0000 Subject: [PATCH] Add files required for packaging OpenProject with Packager.io --- .gitignore | 2 +- .pkgr.yml | 21 ++++++ Gemfile.local | 6 ++ Gemfile.lock | 13 ++++ Procfile | 3 + packaging/cron/openproject-clear-old-sessions | 2 + .../cron/openproject-create-svn-repositories | 1 + packaging/debian/conf/configuration.yml | 11 +++ packaging/debian/postinst | 69 +++++++++++++++++++ packaging/debian/setup.sh | 8 +++ packaging/scripts/backup | 61 ++++++++++++++++ packaging/scripts/create-svn-repositories | 18 +++++ 12 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 .pkgr.yml create mode 100644 Gemfile.local create mode 100644 Procfile create mode 100644 packaging/cron/openproject-clear-old-sessions create mode 100644 packaging/cron/openproject-create-svn-repositories create mode 100644 packaging/debian/conf/configuration.yml create mode 100755 packaging/debian/postinst create mode 100644 packaging/debian/setup.sh create mode 100755 packaging/scripts/backup create mode 100755 packaging/scripts/create-svn-repositories diff --git a/.gitignore b/.gitignore index 59b9124664b..041dd2072bb 100644 --- a/.gitignore +++ b/.gitignore @@ -68,7 +68,7 @@ /*.rbc /doc/app #/Gemfile.lock -/Gemfile.local +#/Gemfile.local /Gemfile.plugins /.rvmrc* /.ruby-version diff --git a/.pkgr.yml b/.pkgr.yml new file mode 100644 index 00000000000..0fef068ad1d --- /dev/null +++ b/.pkgr.yml @@ -0,0 +1,21 @@ +user: openproject +group: openproject +targets: + debian-7: + build_dependencies: + - libmagickwand-dev + - libsqlite3-dev + dependencies: + - debconf + - memcached +before_precompile: "./packaging/debian/setup.sh" +after_install: "packaging/debian/postinst" +addons: + - mysql + - apache2 + - svn-dav + - smtp +crons: + - packaging/cron/openproject-clear-old-sessions + - packaging/cron/openproject-create-svn-repositories + diff --git a/Gemfile.local b/Gemfile.local new file mode 100644 index 00000000000..d12abe45d48 --- /dev/null +++ b/Gemfile.local @@ -0,0 +1,6 @@ +ruby '2.1.1' +group :production do + gem 'rails_12factor' + gem 'unicorn' +end + diff --git a/Gemfile.lock b/Gemfile.lock index 8d869fabcd5..819ee098efe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -175,6 +175,7 @@ GEM json_spec (1.1.1) multi_json (~> 1.0) rspec (~> 2.0) + kgio (2.9.2) launchy (2.3.0) addressable (~> 2.3) letter_opener (1.0.0) @@ -251,8 +252,13 @@ GEM rails-dev-tweaks (0.6.1) actionpack (~> 3.1) railties (~> 3.1) + rails_12factor (0.0.2) + rails_serve_static_assets + rails_stdout_logging rails_autolink (1.1.0) rails (> 3.1) + rails_serve_static_assets (0.0.2) + rails_stdout_logging (0.0.3) railties (3.2.19) actionpack (= 3.2.19) activesupport (= 3.2.19) @@ -260,6 +266,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) + raindrops (0.13.0) rake (10.3.2) rb-fsevent (0.9.3) rb-inotify (0.9.2) @@ -350,6 +357,10 @@ GEM uglifier (2.1.1) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) + unicorn (4.8.3) + kgio (~> 2.6) + rack + raindrops (~> 0.7) websocket (1.0.7) will_paginate (3.0.5) xpath (2.0.0) @@ -417,6 +428,7 @@ DEPENDENCIES rack_session_access rails (~> 3.2.19) rails-dev-tweaks (~> 0.6.1) + rails_12factor rails_autolink rb-fsevent rb-readline @@ -444,4 +456,5 @@ DEPENDENCIES thin timecop (~> 0.6.1) uglifier (>= 1.0.3) + unicorn will_paginate (~> 3.0) diff --git a/Procfile b/Procfile new file mode 100644 index 00000000000..e9a7cf86ca3 --- /dev/null +++ b/Procfile @@ -0,0 +1,3 @@ +web: bundle exec unicorn --host ${HOST:="127.0.0.1"} --port ${PORT:="8080"} --env ${RAILS_ENV:="development"} +worker: bundle exec rake jobs:work +backup: ./packaging/scripts/backup diff --git a/packaging/cron/openproject-clear-old-sessions b/packaging/cron/openproject-clear-old-sessions new file mode 100644 index 00000000000..7fde77cdde0 --- /dev/null +++ b/packaging/cron/openproject-clear-old-sessions @@ -0,0 +1,2 @@ +15 1 * * * root openproject run rake -s db:sessions:expire[7] >> /var/log/openproject/cron-clear-old-sessions.log 2>&1 + diff --git a/packaging/cron/openproject-create-svn-repositories b/packaging/cron/openproject-create-svn-repositories new file mode 100644 index 00000000000..b3535cba923 --- /dev/null +++ b/packaging/cron/openproject-create-svn-repositories @@ -0,0 +1 @@ +*/10 * * * * root /opt/openproject/packaging/scripts/create-svn-repositories >> /var/log/openproject/cron-create-svn-repositories.log 2>&1 diff --git a/packaging/debian/conf/configuration.yml b/packaging/debian/conf/configuration.yml new file mode 100644 index 00000000000..a08c68b8766 --- /dev/null +++ b/packaging/debian/conf/configuration.yml @@ -0,0 +1,11 @@ +default: + rails_cache_store: :memcache + session_store: :cache_store + email_delivery_method: <%= ENV.fetch('EMAIL_DELIVERY_METHOD') { :sendmail } %> + smtp_address: <%= ENV['SMTP_HOST'] %> + smtp_port: <%= ENV.fetch('SMTP_PORT') { 25 }.to_i %> + smtp_domain: <%= ENV.fetch('SMTP_DOMAIN') { ENV['HOSTNAME'] } %> + smtp_authentication: :login + smtp_user_name: <%= ENV['SMTP_USERNAME'] %> + smtp_password: <%= ENV['SMTP_PASSWORD'] %> + attachments_storage_path: <%= ENV.fetch('ATTACHMENTS_STORAGE_PATH') { "/var/db/openproject/files" } %> diff --git a/packaging/debian/postinst b/packaging/debian/postinst new file mode 100755 index 00000000000..64f45f758bc --- /dev/null +++ b/packaging/debian/postinst @@ -0,0 +1,69 @@ +#!/bin/sh + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + +APP_NAME="openproject" +CLI="${APP_NAME}" + +# source debconf library +. /usr/share/debconf/confmodule + +case "$1" in + + configure) + rake_commands="db:migrate" + if [ "$2" = "" ]; then + rake_commands="${rake_commands} db:seed" + fi + + # create attachments folder + attachments_path=$(${CLI} config:get ATTACHMENTS_STORAGE_PATH || echo "/var/db/openproject/files") + mkdir -p "${attachments_path}" + chown ${APP_NAME}.${APP_NAME} "${attachments_path}" + ${CLI} config:set ATTACHMENTS_STORAGE_PATH="${attachments_path}" + + # set SECRET_TOKEN env variable + secret_token=$(${CLI} config:get SECRET_TOKEN || ( < /dev/urandom tr -dc a-z0-9 | head -c128; echo )) + ${CLI} config:set SECRET_TOKEN="$secret_token" + + # migrate + ${CLI} run rake ${rake_commands} || true + + sys_api_key=$(${CLI} config:get SYS_API_KEY) + + # set various settings + db_get openproject/server/hostname + if [ -z "$RET" ]; then web_hostname=$(hostname -f); else web_hostname="$RET"; fi + db_get openproject/server/ssl + if [ "$RET" = "true" ]; then web_protocol="https"; else web_protocol="http"; fi + + ${CLI} run rake setting:set[host_name=${web_hostname},protocol=${web_protocol},sys_api_enabled=1,sys_api_key=${sys_api_key}] 1>/dev/null + + # scale + ${CLI} scale web=1 worker=1 || true + + # let the admin reboot when he's ready + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + exit 0 + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + diff --git a/packaging/debian/setup.sh b/packaging/debian/setup.sh new file mode 100644 index 00000000000..869265724eb --- /dev/null +++ b/packaging/debian/setup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# we need postgresql for asset precompilation +# see: https://packager.io/documentation +sudo service postgresql start + +cp -f packaging/debian/conf/configuration.yml config/configuration.yml + diff --git a/packaging/scripts/backup b/packaging/scripts/backup new file mode 100755 index 00000000000..1a598f7dbfa --- /dev/null +++ b/packaging/scripts/backup @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +TARGET=${TARGET:=$ORIGINAL_PWD} +TARGET=${TARGET:=$(pwd)} +TARGET="/var/db/openproject/backup" + +mkdir -p "${TARGET}" + +timestamp=$(date +"%Y%m%d%H%M%S") + +echo -n "* Generating database backup..." >&2 + +tmpfile=$(mktemp) + +database=$(ruby -ruri -e 'puts URI(ENV["DATABASE_URL"]).path[1..-1]') + +ruby -ruri -e ' + uri = URI(ENV["DATABASE_URL"]) + config=< ${tmpfile} + +dst="${TARGET}/mysql-dump-${timestamp}.sql.gz" +mysqldump --defaults-file=${tmpfile} --single-transaction "${database}" | gzip > "$dst" +echo " done" >&2 +echo "$dst" +rm -f ${tmpfile} + +if [ -d "$SVN_REPOSITORIES" ]; then + dst="${TARGET}/svn-repositories-${timestamp}.tar.gz" + echo -n "* Generating SVN repositories backup..." >&2 + if tar czf "$dst" -C "${SVN_REPOSITORIES}" . ; then + echo " done" >&2 + echo "$dst" + else + echo " failed" >&2 + fi +else + echo "* No SVN repositories folder. Ignoring." >&2 +fi + +if [ -d "$ATTACHMENTS_STORAGE_PATH" ]; then + dst="${TARGET}/attachments-${timestamp}.tar.gz" + echo -n "* Generating attachments backup..." >&2 + if tar czf "$dst" -C "${ATTACHMENTS_STORAGE_PATH}" . ; then + echo " done" >&2 + echo "$dst" + else + echo " failed" >&2 + fi +else + echo "* No attachments folder. Ignoring." >&2 +fi + diff --git a/packaging/scripts/create-svn-repositories b/packaging/scripts/create-svn-repositories new file mode 100755 index 00000000000..5cda2b588a9 --- /dev/null +++ b/packaging/scripts/create-svn-repositories @@ -0,0 +1,18 @@ +#!/bin/bash + +SVN_REPOSITORIES=$(openproject config:get SVN_REPOSITORIES) +PORT=$(openproject config:get PORT) +SYS_API_KEY=$(openproject config:get SYS_API_KEY) + +/opt/openproject/bin/ruby /opt/openproject/extra/svn/reposman.rb \ + --openproject-host "http://127.0.0.1:${PORT}" \ + --owner "www-data" \ + --group "openproject" \ + --public-mode '2750' \ + --private-mode '2750' \ + --svn-dir "${SVN_REPOSITORIES}" \ + --url "file://${SVN_REPOSITORIES}" \ + --key "${SYS_API_KEY}" \ + --scm Subversion \ + --verbose +