File discourse.spec of Package discourse

# spec file for package 
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

%bcond_with     discourse_ruby26

Name:           discourse
Version:        0
Release:        0
%define vhosts_dir     /srv/www/vhosts/
%define app_dir        %{vhosts_dir}/%{name}/
%define home_dir       %{app_dir}
License:        GPL-2.0+
Summary:        A platform for community discussion. Free, open, simple
Group:          Productivity/Networking/Web/Frontends
Source:         %{name}-%{version}.tar.xz
Source1:        %{name}-rpmlintrc
Source2:        %{name}-update
Source3:        %{name}-puma.service
Source4:        %{name}-sidekiq.service
Source5:        %{name}.target
Source6:        dump-version-info.rb
Source7:        discourse-update.service
Source9:        series
Patch:          discourse.fix.deps.patch
Patch2:         discourse.fix-puma-config.patch
Patch3:         discourse.fix-nginx-config.patch
Patch4:         es6.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
BuildRequires:  postgresql-contrib
BuildRequires:  postgresql-server
BuildRequires:  redis
BuildRequires:  rsync
BuildRequires:  ruby-common-rails >= 2.6
BuildRequires:  timezone
Requires:       timezone
BuildRequires:  brotli
Requires:       brotli
BuildRequires:  npm%{nodejs_min_version}
%requires_eq    nodejs%{nodejs_min_version}
BuildRequires:  pkgconfig(systemd)
Requires:       ImageMagick
%if 0%{suse_version} && 0%{suse_version} < 1330
%define rb_build_versions ruby25
%define rb_build_abi      ruby:2.5.0
%define rb_suffix         ruby2.5
%define rb_build_versions %{rb_default_ruby}
%define rb_build_abi      %{rb_default_ruby_abi}
%define rb_suffix    %{rb_default_ruby_suffix}
%if %{with discourse_ruby26}
%define rb_build_versions ruby26
%define rb_build_abi      ruby:2.6.0
%define rb_suffix         ruby2.6
# for a better rails console
BuildRequires:  %{rubygem pry-rails}
# generated!!!
BuildRequires:  %{rubygem bundler:1.17 >= 1.17.3}
BuildRequires:  %{rubygem bootsnap}
BuildRequires:  %{rubygem actionmailer = 5.2.3}
BuildRequires:  %{rubygem actionpack = 5.2.3}
BuildRequires:  %{rubygem actionview = 5.2.3}
BuildRequires:  %{rubygem activemodel = 5.2.3}
BuildRequires:  %{rubygem activerecord = 5.2.3}
BuildRequires:  %{rubygem activesupport = 5.2.3}
BuildRequires:  %{rubygem railties = 5.2.3}
BuildRequires:  %{rubygem sprockets-rails}
BuildRequires:  %{rubygem seed-fu}
BuildRequires:  %{rubygem mail}
BuildRequires:  %{rubygem mini_mime}
BuildRequires:  %{rubygem mini_suffix}
BuildRequires:  %{rubygem hiredis}
BuildRequires:  %{rubygem redis:4.0}
BuildRequires:  %{rubygem redis-namespace}
BuildRequires:  %{rubygem active_model_serializers:0.8 >= 0.8.3}
BuildRequires:  %{rubygem onebox}
BuildRequires:  %{rubygem http_accept_language:2.0 >= 2.0.5}
BuildRequires:  %{rubygem ember-rails = 0.18.5}
BuildRequires:  %{rubygem discourse-ember-source:3.8 >= 3.8.0}
BuildRequires:  %{rubygem ember-handlebars-template = 0.8.0}
BuildRequires:  %{rubygem barber}
BuildRequires:  %{rubygem message_bus}
BuildRequires:  %{rubygem rails_multisite}
BuildRequires:  %{rubygem fast_xs}
BuildRequires:  %{rubygem fast_xor}
BuildRequires:  %{rubygem fastimage}
BuildRequires:  %{rubygem aws-sdk-s3}
BuildRequires:  %{rubygem aws-sdk-sns}
BuildRequires:  %{rubygem excon}
BuildRequires:  %{rubygem unf}
BuildRequires:  %{rubygem email_reply_trimmer:0 >= 0.1}
BuildRequires:  %{rubygem discourse_image_optim}
BuildRequires:  %{rubygem multi_json}
BuildRequires:  %{rubygem mustache}
BuildRequires:  %{rubygem nokogiri}
BuildRequires:  %{rubygem omniauth}
BuildRequires:  %{rubygem omniauth-openid}
BuildRequires:  %{rubygem openid-redis-store}
BuildRequires:  %{rubygem omniauth-facebook}
BuildRequires:  %{rubygem omniauth-twitter}
BuildRequires:  %{rubygem omniauth-instagram}
BuildRequires:  %{rubygem omniauth-github}
BuildRequires:  %{rubygem omniauth-oauth2}
BuildRequires:  %{rubygem omniauth-google-oauth2}
BuildRequires:  %{rubygem oj}
BuildRequires:  %{rubygem pg}
BuildRequires:  %{rubygem mini_sql}
BuildRequires:  %{rubygem pry-rails}
BuildRequires:  %{rubygem r2:0.2 >= 0.2.5}
BuildRequires:  %{rubygem rake}
BuildRequires:  %{rubygem diffy}
BuildRequires:  %{rubygem thor}
BuildRequires:  %{rubygem rinku}
BuildRequires:  %{rubygem sanitize}
BuildRequires:  %{rubygem sidekiq}
BuildRequires:  %{rubygem mini_scheduler}
BuildRequires:  %{rubygem tilt}
BuildRequires:  %{rubygem execjs}
BuildRequires:  %{rubygem mini_racer}
BuildRequires:  %{rubygem highline:1.7 >= 1.7.0}
BuildRequires:  %{rubygem rack-protection}
BuildRequires:  %{rubygem uglifier}
BuildRequires:  %{rubygem rtlit}
BuildRequires:  %{rubygem fast_blank}
BuildRequires:  %{rubygem lru_redux}
BuildRequires:  %{rubygem htmlentities}
BuildRequires:  %{rubygem flamegraph}
BuildRequires:  %{rubygem rack-mini-profiler}
BuildRequires:  %{rubygem unicorn}
BuildRequires:  %{rubygem puma}
BuildRequires:  %{rubygem rbtrace}
BuildRequires:  %{rubygem gc_tracer}
BuildRequires:  %{rubygem ruby-readability}
BuildRequires:  %{rubygem stackprof}
BuildRequires:  %{rubygem memory_profiler}
BuildRequires:  %{rubygem cppjieba_rb}
BuildRequires:  %{rubygem lograge}
BuildRequires:  %{rubygem logstash-event}
BuildRequires:  %{rubygem logstash-logger}
BuildRequires:  %{rubygem logster}
BuildRequires:  %{rubygem sassc}
BuildRequires:  %{rubygem sassc-rails}
BuildRequires:  %{rubygem rotp}
BuildRequires:  %{rubygem rqrcode}
BuildRequires:  %{rubygem sshkey}
BuildRequires:  %{rubygem rchardet}
BuildRequires:  %{rubygem webpush}
BuildRequires:  %{rubygem colored2}
BuildRequires:  %{rubygem maxminddb}
# /generated
Discourse is the 100% open source discussion platform built for the next decade
of the Internet. It works as:

- a mailing list
- a discussion forum
- a long-form chat room

%setup -q
%patch -p1
#patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1

# 1.9.0.beta6~git14.d29fc781fb -> v1.9.0.beta6-14-gd29fc781fb
ruby %{S:6} %{version}
%rails_fix_ruby_shebang bin/* qa/bin/qa script/* script/*/*
perl -p -i -e "s|BUNDLER_REPLACE|$(rpm -ql %{rb_suffix}-rubygem-bundler-1 | grep 'bin.*bundler.*%{rb_suffix}-')|g" discourse-puma.service discourse-sidekiq.service discourse-update

#RAILS_ENV="production" \
#DATABASE_URL=postgresql://none:none@ \
#./bin/bundle exec ./bin/rake assets:clean assets:precompile
cp -v config/database.yml{,.example}

mkdir -p tmp/{sockets,pids} public/uploads/ public/plugins/ public/backups/default/
chmod -R u=rwX,g=rX,o= .
chmod -R o+rX public/
chmod -R go=X public/backups/
chmod go+X .
chmod -R go+X tmp/
chmod go+X plugins/ plugins/*/
chmod -R go+rX plugins/*/public/

if [[ -e .gitattributes ]] ; then
  echo "Error: .gitattributes still exists"
  rm -rv .gitattributes

#find -name \*.swp -print -delete
find -type f \( -name .gitkeep -o -name .gitignore \) -print -delete

chmod a-x                                 \
  bin/docker/                    \
  script/import_scripts/json_generic.rb   \
rm -rv tmp/cache/bootsnap-*

install -D -d -m 0751 %{buildroot}%{app_dir}/
rsync -a $PWD/ %{buildroot}%{app_dir}/
install -D -m 0755 %{S:2} %{buildroot}%{_sbindir}/%{name}-update
install -D -m 0644 %{S:3} %{buildroot}%{_unitdir}/%{name}-puma.service
install -D -m 0644 %{S:4} %{buildroot}%{_unitdir}/%{name}-sidekiq.service
install -D -m 0644 %{S:7} %{buildroot}%{_unitdir}/%{name}-update.service
install -D -m 0644 %{S:5} %{buildroot}%{_unitdir}/%{name}.target
grep -h -r 'CREATE EXT' db/migrate/* | sed -e 's|.*"\(.*\)".*|\1;|g' | tee discourse.setup.extensions.sql

for i in puma sidekiq update ; do
  ln -s /sbin/service %{buildroot}%{_sbindir}/rc%{name}-$i

/usr/sbin/groupadd -r %{name} &>/dev/null || :
/usr/sbin/useradd  -g %{name} -s /bin/false -r -c "Discourse" -d %{home_dir} %{name} &>/dev/null || :
%service_add_pre %{name}-update.service %{name}-puma.service %{name}-sidekiq.service

%service_add_post %{name}-update.service %{name}-puma.service %{name}-sidekiq.service

%service_del_preun %{name}-update.service %{name}-puma.service %{name}-sidekiq.service

touch %{app_dir}/tmp/rebuild.txt
%service_del_postun %{name}-update.service %{name}-puma.service %{name}-sidekiq.service

%doc discourse.setup.extensions.sql
%dir %{vhosts_dir}
%dir %{app_dir}/
%dir %{app_dir}/public
%config(noreplace) %{app_dir}/config/