From a0fc569eaac6488ae32a14d0464275c9a0a27e70 Mon Sep 17 00:00:00 2001 From: Daniel Lewis Date: Mon, 13 Feb 2023 12:56:24 +0000 Subject: [PATCH] add version and update workflow --- .Dockerfile.swp | Bin 12288 -> 0 bytes .github/workflows/main.yml | 46 +++++++------------------- .gitignore | 2 ++ .ruby-version | 2 +- CHANGELOG.md | 6 ++++ Dockerfile | 4 +-- Gemfile | 4 +-- Gemfile.lock | 64 ++++++++++++++++++++++--------------- app.rb | 5 +++ config/newrelic.yml | 17 ++++++++++ lib/version.rb | 3 ++ spec/app_spec.rb | 36 +++++++++++++-------- spec/version_spec.rb | 13 ++++++++ 13 files changed, 125 insertions(+), 77 deletions(-) delete mode 100644 .Dockerfile.swp create mode 100644 config/newrelic.yml create mode 100644 lib/version.rb create mode 100644 spec/version_spec.rb diff --git a/.Dockerfile.swp b/.Dockerfile.swp deleted file mode 100644 index 139f124c184774ad396039e4b3b8358a2434a7a3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2%Wl&^6hNm)2o^0Mps)dPait0(#!j13T0|F7l2%olrgEE-LMt?}C#e;`sN=YDztPl32FSpn4WvnjPYtos_*nK+AJMMDxwFkfUycTn0Wv@a z$N(8217v^ru zV3sQj4{&EDi~>8g5-0H4-G;ePoj0=yFg9y8>e&=;m-KPH$b}m^zAWiu=y2qJTRx|b zGLhLl{uXZShU2VMEh7(j)Y*Fnqkx~>V;-2x2gi>S;ktcE zUFq%i 1.30.1) - rubocop-rspec (~> 2.11.1) + rubocop (~> 1.45) + rubocop-rails (~> 2.17) + rubocop-rspec (~> 2.18) GEM remote: https://rubygems.org/ specs: + activesupport (7.0.4.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) ast (2.4.2) + concurrent-ruby (1.2.0) debug (1.7.1) - irb (>= 1.5.0) - reline (>= 0.3.1) diff-lcs (1.5.0) ffi (1.15.5) + i18n (1.12.0) + concurrent-ruby (~> 1.0) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - io-console (0.6.0) - irb (1.6.2) - reline (>= 0.3.0) + json (2.6.3) mini_magick (4.12.0) + minitest (5.17.0) multi_json (1.15.0) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) - newrelic_rpm (8.15.0) + newrelic_rpm (8.16.0) nio4r (2.5.8) nokogiri (1.14.1-aarch64-linux) racc (~> 1.4) @@ -37,9 +43,9 @@ GEM nokogiri (1.14.1-x86_64-linux) racc (~> 1.4) parallel (1.22.1) - parser (3.2.0.0) + parser (3.2.1.0) ast (~> 2.4.1) - puma (6.0.2) + puma (6.1.0) nio4r (~> 2.0) racc (1.6.2) rack (2.2.6.2) @@ -48,9 +54,7 @@ GEM rack-test (2.0.2) rack (>= 1.3) rainbow (3.1.1) - regexp_parser (2.6.2) - reline (0.3.2) - io-console (~> 0.5) + regexp_parser (2.7.0) rexml (3.2.5) rspec (3.12.0) rspec-core (~> 3.12.0) @@ -65,19 +69,27 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) - rubocop (1.30.1) + rubocop (1.45.1) + json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.18.0, < 2.0) + rubocop-ast (>= 1.24.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - rubocop-rspec (2.11.1) - rubocop (~> 1.19) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.26.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.17.0) + rubocop (~> 1.41) + rubocop-rails (2.17.4) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-rspec (2.18.1) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) ruby-progressbar (1.11.0) ruby-vips (2.1.4) ffi (~> 1.12) @@ -96,6 +108,8 @@ GEM svg_optimizer (0.2.6) nokogiri tilt (2.0.11) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unicode-display_width (2.4.2) PLATFORMS @@ -117,7 +131,7 @@ DEPENDENCIES svg_optimizer RUBY VERSION - ruby 3.2.0p0 + ruby 3.2.1p31 BUNDLED WITH - 2.4.5 + 2.4.6 diff --git a/app.rb b/app.rb index f09e549..f34396d 100644 --- a/app.rb +++ b/app.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require_relative "lib/version" require_relative "lib/image_resize_service" require "sinatra" require "newrelic_rpm" @@ -10,6 +11,10 @@ body "Image Resizer service is running" end +get "/version" do + VERSION +end + post "/image" do image_file = params[:image_file]&.[](:tempfile) halt 400, "no image file was provided" unless image_file.is_a?(Tempfile) diff --git a/config/newrelic.yml b/config/newrelic.yml new file mode 100644 index 0000000..f375d5b --- /dev/null +++ b/config/newrelic.yml @@ -0,0 +1,17 @@ +# https://docs.newrelic.com/docs/agents/ruby-agent/installation-configuration/ruby-agent-configuration +common: &default_settings + app_name: Image resizer + agent_enabled: <%= ENV["NEW_RELIC_LICENSE_KEY"].to_s.strip.empty? ? false : true %> + browser_monitoring: + auto_instrument: false + +development: + <<: *default_settings + agent_enabled: false + +test: + <<: *default_settings + monitor_mode: false + +production: + <<: *default_settings diff --git a/lib/version.rb b/lib/version.rb new file mode 100644 index 0000000..4cbe73c --- /dev/null +++ b/lib/version.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +VERSION = "2.2.0" diff --git a/spec/app_spec.rb b/spec/app_spec.rb index eae682d..02424e9 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../lib/version" + describe "image resizer app", type: :feature do let(:image_file) { Rack::Test::UploadedFile.new("spec/fixtures/image_files/#{test_image_file_name}") } let(:test_image_file_name) { "test-png-small-314x580px.png" } @@ -18,6 +20,14 @@ end end + describe "get /version" do + it "returns the version" do + get "/version" + expect(last_response.status).to eq 200 + expect(last_response.body).to eq VERSION + end + end + describe "post /image" do context "with missing image" do it "returns 400 status" do @@ -30,7 +40,7 @@ context "with invalid width" do it "returns 400 status" do - post "/image", image_file: image_file, width: 0 + post "/image", image_file:, width: 0 expect(last_response.status).to eq 400 expect(last_response.body).to eq "invalid width" @@ -39,7 +49,7 @@ context "with invalid height" do it "returns 400 status" do - post "/image", image_file: image_file, height: 0 + post "/image", image_file:, height: 0 expect(last_response.status).to eq 400 expect(last_response.body).to eq "invalid height" @@ -50,7 +60,7 @@ let(:test_image_file_name) { "test_csv.csv" } it "returns 500 status" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 500 expect(last_response.body).to include "magick convert" @@ -61,7 +71,7 @@ let(:test_image_file_name) { "test-png-small-314x580px.png" } it "returns the PNG image at its original size" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 200 expect(resized_image.type).to eq "PNG" @@ -73,7 +83,7 @@ let(:test_image_file_name) { "test-png-1102x1287px.png" } it "returns the PNG image resized to maximum dimensions of 800px" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 200 expect(resized_image.type).to eq "PNG" @@ -85,7 +95,7 @@ let(:test_image_file_name) { "test-jpg-1102x1287px.jpg" } it "returns the JPEG image resized to maximum dimensions of 800px" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 200 expect(resized_image.type).to eq "JPEG" @@ -97,7 +107,7 @@ let(:test_image_file_name) { "test-gif-1102x1287px.gif" } it "returns the GIF image resized to maximum dimensions of 800px" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 200 expect(resized_image.type).to eq "GIF" @@ -109,7 +119,7 @@ let(:test_image_file_name) { "test-bad-tif-800x1000px.tif" } it "returns the image converted to PNG and resized to maximum dimensions of 800px" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 200 expect(resized_image.type).to eq "PNG" @@ -121,7 +131,7 @@ let(:test_image_file_name) { "test-bmp.bmp" } it "returns the image converted to PNG and resized to maximum dimensions of 800px" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 200 expect(resized_image.type).to eq "PNG" @@ -133,7 +143,7 @@ let(:test_image_file_name) { "test-webp.webp" } it "returns the image converted to PNG and resized to maximum dimensions of 800px" do - post "/image", image_file: image_file + post("/image", image_file:) expect(last_response.status).to eq 200 expect(resized_image.type).to eq "PNG" @@ -145,7 +155,7 @@ let(:test_image_file_name) { "test-png-1102x1287px.png" } it "resizes to the custom width" do - post "/image", image_file: image_file, width: 200 + post "/image", image_file:, width: 200 expect(last_response.status).to eq 200 expect(resized_image.type).to eq "PNG" @@ -157,7 +167,7 @@ let(:test_image_file_name) { "test-png-1102x1287px.png" } it "resizes to the custom height" do - post "/image", image_file: image_file, height: 200 + post "/image", image_file:, height: 200 expect(last_response.status).to eq 200 expect(resized_image.type).to eq "PNG" @@ -169,7 +179,7 @@ let(:test_image_file_name) { "test-svg.svg" } it "optimises the image" do - post "/image", image_file: image_file + post("/image", image_file:) expect(`file --brief --mime-type #{resized_image_path}`.chomp).to eq "image/svg+xml" expect(last_response.body.size.to_f / File.open(image_file).size).to be_between(0.6, 0.8) diff --git a/spec/version_spec.rb b/spec/version_spec.rb new file mode 100644 index 0000000..32d9120 --- /dev/null +++ b/spec/version_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require_relative "../lib/version" + +describe VERSION do + it "matches the branch" do + # Only really works locally. Just to enforce updating the branch + branch = `git branch --show-current`.chomp + expect(VERSION).to eq branch.sub(/^v/, "") if branch.match?(/^v?\d+\.\d+\.\d+/) # rubocop:disable RSpec/DescribedClass + rescue Errno::ENOENT + # ignore + end +end