Skip to content

Commit

Permalink
lint a random file (#3125)
Browse files Browse the repository at this point in the history
  • Loading branch information
osc-bot authored Oct 13, 2023
1 parent 7802f8e commit 5235ace
Showing 1 changed file with 61 additions and 56 deletions.
117 changes: 61 additions & 56 deletions lib/tasks/rake_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'pathname'
require 'erb'
require 'dotenv'
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand All @@ -154,37 +153,37 @@ 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
@numeric_tag ||= git_tag.delete_prefix('v')
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
Expand All @@ -193,27 +192,27 @@ 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)
`#{container_runtime} inspect --type image --format exists #{image_name} || true`.chomp.eql?('exists')
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(' ')}"
Expand Down Expand Up @@ -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

0 comments on commit 5235ace

Please sign in to comment.