Rakefile in sidekiq-prometheus-exporter-0.1.17 vs Rakefile in sidekiq-prometheus-exporter-0.2.0

- old
+ new

@@ -10,10 +10,11 @@ require 'English' require 'fileutils' require_relative 'lib/sidekiq/prometheus/exporter/version' VERSION = Sidekiq::Prometheus::Exporter::VERSION +DOCKER_PATCH_VERSION = Sidekiq::Prometheus::Exporter::DOCKER_PATCH_VERSION def execute(command) output = `#{command}` unless $CHILD_STATUS.success? @@ -22,32 +23,37 @@ end output end +def docker_version + patch = DOCKER_PATCH_VERSION unless DOCKER_PATCH_VERSION.to_i.zero? + [VERSION, patch].compact.join('-') +end + namespace :docker do - desc "Release new Docker image strech/sidekiq-prometheus-exporter:#{VERSION} (latest)" - task :release, %i(patch) do |_, args| - version = [VERSION, args.patch].compact.join('-') + desc "Release new Docker image strech/sidekiq-prometheus-exporter:#{docker_version} (latest)" + task :release, %i(version) do |_, args| + version = args.fetch(:version, docker_version) Rake::Task['docker:build'].invoke(version) Rake::Task['docker:push'].invoke(version) end task :build, %i(version) do |_, args| - args.with_defaults(version: VERSION) + args.with_defaults(version: docker_version) image = 'strech/sidekiq-prometheus-exporter' Dir.chdir(File.expand_path('./docker')) do execute("docker build -t #{image}:#{args.version} -t #{image}:latest .") end puts "Successfully built strech/sidekiq-prometheus-exporter and tagged #{args.version} (latest)" end task :push, %i(version) do |_, args| - args.with_defaults(version: VERSION) + args.with_defaults(version: docker_version) image = 'strech/sidekiq-prometheus-exporter' execute("docker push #{image}:#{args.version}") execute("docker push #{image}:latest") @@ -55,16 +61,16 @@ end end namespace :helm do desc 'Generate new Helm repo index' - task :generate, %i(patch) do |_, args| - version = [VERSION, args.patch].compact.join('-') + task :generate, %i(version) do |_, args| + args.with_defaults(version: docker_version) archive_dir = File.expand_path("./tmp/archive-#{Time.now.to_i}") Rake::Task['helm:package'].invoke(archive_dir) - Rake::Task['helm:index'].invoke(archive_dir, version) + Rake::Task['helm:index'].invoke(archive_dir, args.version) puts "New index generated: #{File.join(archive_dir, 'index.yaml')}" end task :package, %i(directory) do |_, args| @@ -75,10 +81,10 @@ execute("helm package #{chart_dir} -d #{archive_dir}") end task :index, %i(directory version) do |_, args| - args.with_defaults(version: VERSION) + args.with_defaults(version: docker_version) Dir.chdir(args.fetch(:directory)) do url = "https://github.com/Strech/sidekiq-prometheus-exporter/releases/download/v#{args.version}" execute('git show gh-pages:index.yaml > existing-index.yaml')