File routenbuch.spec of Package routenbuch

%define rb_build_versions ruby34
%define rb_build_abi      ruby:3.4.0
%define rb_suffix         ruby3.4

%define nodejs_min_version 22
%global nodejs_includedir %{_includedir}/node%{nodejs_req_min_version}

%global webapps_dir /srv/www/webapps
%global app_dir     %{webapps_dir}/%{name}

Name:           routenbuch
Version:        0
Release:        0%{?dist}
Summary:        A climbing management application
#
License:        GPL-3.0+
URL:            https://gitlab.com/routenbuch/routenbuch
Source0:        %{name}-%{version}.tar.xz
#
Source1:        routenbuch-node-modules.tar.zst
#
Source10:       routenbuch-puma.service
Source11:       routenbuch-sidekiq.service
Source12:       routenbuch-update.sh
Source13:       routenbuch-update.service
Source14:       routenbuch.target
Source15:       routenbuch.sh
#
Source20:       routenbuch.logrotate
#
Patch1:         routenbuch-fix-deps.patch
#
BuildArch:      noarch
#
BuildRequires:  rsync
BuildRequires:  fdupes
BuildRequires:  zstd
#
BuildRequires:  gcc-c++
#
BuildRequires:  ruby-common-rails >= 3.2
BuildRequires:  npm%{nodejs_min_version}
BuildRequires:  nodejs%{nodejs_min_version}-devel
#
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
BuildRequires:  timezone
Requires:       timezone
BuildRequires:  brotli
Requires:       brotli
BuildRequires:  pnpm >= 9
#
# for a better rails console
Recommends:     %{rubygem php-serialize}

BuildRequires:  %{rubygem pry-rails}
BuildRequires:  %{rubygem rake >= 12.0}
BuildRequires:  %{rubygem active_storage_validations}
BuildRequires:  %{rubygem bcrypt}
BuildRequires:  %{rubygem bootsnap}
BuildRequires:  %{rubygem cancancan}
BuildRequires:  %{rubygem devise-i18n}
BuildRequires:  %{rubygem devise}
BuildRequires:  %{rubygem diff-lcs}
BuildRequires:  %{rubygem geokit-rails}
BuildRequires:  %{rubygem gettext_i18n_rails}
BuildRequires:  %{rubygem health_check}
BuildRequires:  %{rubygem image_processing}
BuildRequires:  %{rubygem jsonapi-serializer}
BuildRequires:  %{rubygem jsonb_accessor}
BuildRequires:  %{rubygem kaminari}
BuildRequires:  %{rubygem lograge}
BuildRequires:  %{rubygem paper_trail}
BuildRequires:  %{rubygem pg_search}
BuildRequires:  %{rubygem pg}
BuildRequires:  %{rubygem puma}
BuildRequires:  %{rubygem rack-session >= 2.0}
BuildRequires:  %{rubygem rails:8.1 >= 8.1.0}
BuildRequires:  %{rubygem ransack >= 4.1.1}
BuildRequires:  %{rubygem redcarpet}
BuildRequires:  %{rubygem redis}
BuildRequires:  %{rubygem rexml}
BuildRequires:  %{rubygem rqrcode}
BuildRequires:  %{rubygem rswag-api}
BuildRequires:  %{rubygem rswag-ui}
BuildRequires:  %{rubygem rubyzip}
BuildRequires:  %{rubygem sassc-rails}
BuildRequires:  %{rubygem seedbank}
BuildRequires:  %{rubygem settingslogic}
BuildRequires:  %{rubygem shakapacker}
BuildRequires:  %{rubygem sidekiq-cron}
BuildRequires:  %{rubygem sidekiq}
BuildRequires:  %{rubygem simple-navigation}
BuildRequires:  %{rubygem simple_form}
BuildRequires:  %{rubygem simple_navigation_bootstrap}
BuildRequires:  %{rubygem soft_deletion}
BuildRequires:  %{rubygem sprockets >= 4.1.1}
BuildRequires:  %{rubygem strong_password}

Suggests:       logrotate

%description
Routenbuch climbing management application. A ticklist app written in Ruby
rails.

%prep
%autosetup -p1 -a1
%rails_save_gemfile

%build
# Set include path till nodejs-devel is fixed
# https://bugzilla.opensuse.org/show_bug.cgi?id=1195164
export CFLAGS="%{optflags} -I%{nodejs_includedir}"
export CXXFLAGS="%{optflags} -I%{nodejs_includedir}"

%rails_fix_ruby_shebang bin/*
%rails_regen_gemfile_lock
%rails_fix_ruby_suffix
%rails_write_appinfo

for S in $(grep -r -l '@BUNDLER_REPLACE@' ${RPM_SOURCE_DIR}/ | grep -v '.spec$'); do
    SB="${S}.backup"
    cp ${S} ${SB}
    perl -p -i -e "s|\@BUNDLER_REPLACE\@|$(readlink -f %{_bindir}/bundler.%{rb_suffix})|g" ${S}
    diff -urN ${SB} ${S} || :
    rm ${SB}
done

### Rebuild node modules from source (node-sass)
export PATH="${PATH}:$(pwd)/node_modules/.bin"
export npm_config_nodedir="%{nodejs_includedir}"
export npm_config_build_from_source=true

rm -rf node_modules/
pnpm install --offline --frozen-lockfile --store-dir="$(pwd)/.pnpm-store"

RAILS_ENV=production \
SECRET_KEY_BASE=0 \
    ./bin/rake %{?_smp_mflags} assets:precompile --trace
RAILS_ENV=production \
    ./bin/rake tmp:clear

rm -f tmp/shakapacker.lock

%install
install -d -m 0755 \
    %{buildroot}%{webapps_dir} \
    %{buildroot}%{app_dir} \
    %{buildroot}%{app_dir}/public \
    %{buildroot}%{app_dir}/public/uploads \
    %{buildroot}%{app_dir}/storage

rsync -av $(pwd)/public/packs %{buildroot}%{app_dir}/public/
rsync -av --exclude=.pnpm-store --exclude=node_modules --exclude=node_headers $(pwd)/ %{buildroot}%{app_dir}/

find %{buildroot}%{app_dir} -name .keep -delete
find %{buildroot}%{app_dir} -name .gitignore -delete
for f in .dockerignore \
         .gitlab-ci.yml \
         .rspec \
         Containerfile \
         Dockerfile \
         compose.yml \
         log/production.log \
         ; do \
    rm -f %{buildroot}%{app_dir}/$f
done
rm -rf find %{buildroot}%{app_dir}/container

%fdupes -s %{buildroot}%{app_dir}

install -d -m 0755 %{buildroot}%{_sysconfdir}/logrotate.d
install -m 0644 %{SOURCE20} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

install -d -m 0755 %{buildroot}%{_unitdir}
install -m 0644 %{SOURCE10} %{buildroot}%{_unitdir}
install -m 0644 %{SOURCE11} %{buildroot}%{_unitdir}

install -d -m 0755 %{buildroot}%{_sbindir}
install -m 0750 %{SOURCE12} %{buildroot}%{_sbindir}/%{name}-update
install -m 0750 %{SOURCE15} %{buildroot}%{_sbindir}/%{name}

install -m 0644 %{SOURCE13} %{buildroot}%{_unitdir}
install -m 0644 %{SOURCE14} %{buildroot}%{_unitdir}

# Create suse rc service symlinks
for i in puma sidekiq update ; do
  ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-$i
done

# Remove tmp/cache/bootsnap/compile-cache-iseq/31/4ae89fe0e16f67
rm -rf %{buildroot}%{app_dir}/tmp/cache/
# Remove executable bit from Gemfile
chmod -x %{buildroot}%{app_dir}/Gemfile.lock.upstream

# Remove unneded files
rm -f %{buildroot}%{app_dir}/.prettierrc.yml
rm -f %{buildroot}%{app_dir}/tsconfig.json
rm -f %{buildroot}%{app_dir}/vitest.config.js

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

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

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

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


%files
%defattr(-,root,root)
%license LICENSE
%doc INSTALL.md README.md
%dir %{_sysconfdir}/logrotate.d
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}

%{_sbindir}/%{name}
%{_sbindir}/%{name}-update
%{_sbindir}/rc%{name}-puma
%{_sbindir}/rc%{name}-sidekiq
%{_sbindir}/rc%{name}-update
%{_unitdir}/%{name}-puma.service
%{_unitdir}/%{name}-sidekiq.service
%{_unitdir}/%{name}-update.service
%{_unitdir}/%{name}.target

%dir /srv/www
%dir %{webapps_dir}

%defattr(-,root,%{name})
%dir %{app_dir}

%dir %{app_dir}/app
%{app_dir}/app/assets/
%{app_dir}/app/controllers/
%{app_dir}/app/helpers/
%{app_dir}/app/inputs/
%{app_dir}/app/javascript/
%{app_dir}/app/jobs/
%{app_dir}/app/mailers/
%{app_dir}/app/models/
%{app_dir}/app/presenters/
%{app_dir}/app/serializers/
%{app_dir}/app/services/
%{app_dir}/app/types/
%{app_dir}/app/validators/
%{app_dir}/app/views/

%{app_dir}/bin

%config(noreplace) %{app_dir}/config/

%{app_dir}/db/
%{app_dir}/doc/
%{app_dir}/help/
%{app_dir}/lib/
%{app_dir}/locale/
%dir %{app_dir}/public
%{app_dir}/public/assets
%{app_dir}/public/packs

%config(noreplace) %{app_dir}/public/favicon.ico
%{app_dir}/public/*.html
%{app_dir}/public/icon.png
%{app_dir}/public/icon.svg
%{app_dir}/public/robots.txt

%exclude %{app_dir}/spec
%{app_dir}/openapi/

%dir %{app_dir}/vendor
%{app_dir}/vendor/assets

%{app_dir}/.appinfo.yml
%{app_dir}/.solargraph.yml
%{app_dir}/Gemfile
%{app_dir}/Gemfile.lock
%{app_dir}/Gemfile.lock.upstream
%{app_dir}/Gemfile.upstream
%{app_dir}/INSTALL.md
%{app_dir}/LICENSE
%{app_dir}/MAINTENANCE.md
%{app_dir}/README.md
%{app_dir}/Rakefile
%{app_dir}/config.ru
%{app_dir}/package.json
%{app_dir}/postcss.config.js
%{app_dir}/rails.env
%{app_dir}/pnpm-lock.yaml


%defattr(-,%{name},%{name})
%dir %{app_dir}/public/uploads
%dir %{app_dir}/tmp
%{app_dir}/tmp/shakapacker

%dir %attr(750,%{name},%{name}) %{app_dir}/log
%dir %attr(750,%{name},%{name}) %{app_dir}/storage

%changelog
openSUSE Build Service is sponsored by