diff --git a/lib/tasks/rake_helper.rb b/lib/tasks/rake_helper.rb index 8d1b3787d0..eac2b56358 100644 --- a/lib/tasks/rake_helper.rb +++ b/lib/tasks/rake_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'pathname' require 'erb' require 'dotenv' @@ -14,7 +15,7 @@ def infrastructure 'mod_ood_proxy', 'nginx_stage', 'ood_auth_map', - 'ood-portal-generator', + 'ood-portal-generator' ].map { |d| Component.new(d) } end @@ -35,8 +36,7 @@ def yarn_app?(path) end class Component - attr_reader :name - attr_reader :path + attr_reader :name, :path def initialize(app) @name = File.basename(app) @@ -63,45 +63,45 @@ def gemfile? def infrastructure_files @infrastructure_files ||= [ { - src: 'apache-systemd.ood-portal.conf.erb', + src: 'apache-systemd.ood-portal.conf.erb', dest: File.join(DESTDIR, "etc/systemd/system/#{apache_service}.service.d/ood-portal.conf"), - mode: 0444, + mode: 0o444 }, { - src: 'apache-systemd.ood.conf', + src: 'apache-systemd.ood.conf', dest: File.join(DESTDIR, "etc/systemd/system/#{apache_service}.service.d/ood.conf"), - mode: 0444, + mode: 0o444 }, { - src: 'crontab', + src: 'crontab', dest: File.join(DESTDIR, 'etc/cron.d/ood'), - mode: 0644, + mode: 0o644 }, { - src: 'favicon.ico', + src: 'favicon.ico', dest: File.join(DESTDIR, 'var/www/ood/public/favicon.ico'), - mode: 0644, + mode: 0o644 }, { - src: 'logo.png', + src: 'logo.png', dest: File.join(DESTDIR, 'var/www/ood/public/logo.png'), - mode: 0644, + mode: 0o644 }, { - src: 'logrotate', + src: 'logrotate', dest: File.join(DESTDIR, 'etc/logrotate.d/ood'), - mode: 0644, + mode: 0o644 }, { - src: 'ondemand-nginx-tmpfiles', + src: 'ondemand-nginx-tmpfiles', dest: File.join(DESTDIR, 'usr/lib/tmpfiles.d/ondemand-nginx.conf'), - mode: 0644, + mode: 0o644 }, { - src: 'sudo.erb', + src: 'sudo.erb', dest: File.join(DESTDIR, 'etc/sudoers.d/ood'), - mode: 0440, - }, + mode: 0o440 + } ] end @@ -128,20 +128,19 @@ def ood_version end def ood_package_version - @ood_package_version ||= begin - if ENV['VERSION'] - ENV['VERSION'].to_s - elsif ENV['CI_COMMIT_TAG'] - ENV['CI_COMMIT_TAG'].to_s - else - tag? ? git_tag : "#{git_tag}.#{build_timestamp}-#{git_hash}" - end - end + @ood_package_version ||= if ENV['VERSION'] + ENV['VERSION'].to_s + elsif ENV['CI_COMMIT_TAG'] + ENV['CI_COMMIT_TAG'].to_s + else + tag? ? git_tag : "#{git_tag}.#{build_timestamp}-#{git_hash}" + end + @ood_package_version.gsub(/^v/, '') end def build_timestamp - @build_timestamp ||= Time.now.strftime("%s") + @build_timestamp ||= Time.now.strftime('%s') end def git_hash @@ -154,13 +153,13 @@ def git_tag def nightly_version version_major, version_minor, version_patch = git_tag.gsub(/^v/, '').split('.', 3) - date = Time.now.strftime("%Y%m%d") - id = ENV['CI_PIPELINE_ID'] || Time.now.strftime("%H%M%S") + date = Time.now.strftime('%Y%m%d') + id = ENV['CI_PIPELINE_ID'] || Time.now.strftime('%H%M%S') "#{version_major}.#{version_minor}.#{date}-#{id}.#{git_hash}.nightly" end def today - Time.now.strftime("%Y%m%d") + Time.now.strftime('%Y%m%d') end def numeric_tag @@ -168,23 +167,23 @@ def numeric_tag end def tag? - @tag ||= `git describe --exact-match --tags HEAD 2>/dev/null`.to_s != "" + @tag ||= `git describe --exact-match --tags HEAD 2>/dev/null`.to_s != '' end def podman_runtime? - @podman_runtime ||= ENV['CONTAINER_RT'] == "podman" + @podman_runtime ||= ENV['CONTAINER_RT'] == 'podman' end def container_runtime - podman_runtime? ? "podman" : "docker" + podman_runtime? ? 'podman' : 'docker' end def dev_image_name - "ood-dev" + 'ood-dev' end def image_name - "ood" + 'ood' end def user @@ -193,10 +192,10 @@ def user def image_names @image_names ||= - { - ood: "ood", - dev: "ood-dev" - }.freeze + { + ood: 'ood', + dev: 'ood-dev' + }.freeze end def image_exists?(image_name) @@ -204,16 +203,16 @@ def image_exists?(image_name) end def buildah_build_cmd(docker_file, image_name, image_tag: ood_image_tag, extra_args: []) - args = ["bud", "--build-arg", "VERSION=#{ood_version}"] - args.concat ["-t", "#{image_name}:#{image_tag}", "-f", docker_file] + args = ['bud', '--build-arg', "VERSION=#{ood_version}"] + args.concat ['-t', "#{image_name}:#{image_tag}", '-f', docker_file] args.concat extra_args "buildah #{args.join(' ')}" end def docker_build_cmd(docker_file, image_name, image_tag: ood_image_tag, extra_args: []) - args = ["build", "--build-arg", "VERSION=#{ood_version}"] - args.concat ["-t", "#{image_name}:#{image_tag}", "-f", docker_file, "."] + args = ['build', '--build-arg', "VERSION=#{ood_version}"] + args.concat ['-t', "#{image_name}:#{image_tag}", '-f', docker_file, '.'] args.concat extra_args "docker #{args.join(' ')}" @@ -248,53 +247,59 @@ def rt_specific_flags end def container_userns_flag - return ["--userns", "keep-id"] if container_runtime == "podman" + return ['--userns', 'keep-id'] if container_runtime == 'podman' + [] end def os_release - @os_release ||= begin - if File.exist?('/etc/os-release') - Dotenv.parse('/etc/os-release') - else - {} - end - end + @os_release ||= if File.exist?('/etc/os-release') + Dotenv.parse('/etc/os-release') + else + {} + end end def scl_apache? - return true if (el? && os_release['VERSION_ID'] =~ /^7/) + return true if el? && os_release['VERSION_ID'] =~ /^7/ + false end def el? return true if "#{os_release['ID']} #{os_release['ID_LIKE']}" =~ /(rhel|fedora)/ + false end def debian? - return true if (os_release['ID'] =~ /(ubuntu|debian)/ or os_release['ID_LIKE'] == 'debian') + return true if os_release['ID'] =~ (/(ubuntu|debian)/) || (os_release['ID_LIKE'] == 'debian') + false end def apache_daemon return '/opt/rh/httpd24/root/usr/sbin/httpd-scl-wrapper' if scl_apache? + "/usr/sbin/#{apache_service}" end def apache_reload return '/usr/sbin/apachectl graceful' if debian? + "#{apache_daemon} $OPTIONS -k graceful" end def apache_user return 'www-data' if debian? + 'apache' end def apache_service return 'apache2' if debian? return 'httpd24-httpd' if scl_apache? + 'httpd' end end