From 1b5f68b41d118fc9f77f33b880e12089957b6296 Mon Sep 17 00:00:00 2001 From: Kyle Le Date: Sun, 28 Apr 2024 23:19:41 +0700 Subject: [PATCH 1/3] Issue 66 Add health check --- app/controllers/health_check_controller.rb | 6 ++++++ config/routes.rb | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 app/controllers/health_check_controller.rb diff --git a/app/controllers/health_check_controller.rb b/app/controllers/health_check_controller.rb new file mode 100644 index 0000000..b7b96ac --- /dev/null +++ b/app/controllers/health_check_controller.rb @@ -0,0 +1,6 @@ +class HealthCheckController < ActionController::Base + def health + response = {version: Kaui.version, status: 'UP'} + render json: response, status: 200 + end +end diff --git a/config/routes.rb b/config/routes.rb index c0b5d41..33b6403 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,8 @@ Rails.application.routes.draw do root to: (ENV['KAUI_ROOT'].present? ? ENV['KAUI_ROOT'] : 'kaui/home#index') + get '/health', to: 'health_check#health' + # We mount KAUI as root, since this is the primary engine mount Kaui::Engine => '/', :as => 'kaui_engine' From a2d18338a6c47a664923018559b598930610d892 Mon Sep 17 00:00:00 2001 From: Kyle Le Date: Sun, 28 Apr 2024 23:29:34 +0700 Subject: [PATCH 2/3] Fix rubocop --- app/controllers/health_check_controller.rb | 6 ++++-- config/initializers/application_controller_renderer.rb | 1 + config/initializers/assets.rb | 1 + config/initializers/backtrace_silencers.rb | 1 + config/initializers/content_security_policy.rb | 1 + config/initializers/inflections.rb | 1 + config/initializers/mime_types.rb | 1 + config/initializers/new_framework_defaults_7_0.rb | 1 + config/initializers/permissions_policy.rb | 1 + db/seeds.rb | 1 + test/performance/browsing_test.rb | 1 + 11 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/health_check_controller.rb b/app/controllers/health_check_controller.rb index b7b96ac..0e57d1a 100644 --- a/app/controllers/health_check_controller.rb +++ b/app/controllers/health_check_controller.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class HealthCheckController < ActionController::Base def health - response = {version: Kaui.version, status: 'UP'} - render json: response, status: 200 + response = { version: Kaui.version, status: 'UP' } + render json: response, status: 200 end end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 315ac48..6e2d5d2 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # ApplicationController.renderer.defaults.merge!( diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index cc3a318..b52d902 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index d0f0d3b..4b63f28 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 691cfa1..53538c1 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide content security policy. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 6c78420..9e049dc 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 6e1d16f..be6fedc 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/new_framework_defaults_7_0.rb b/config/initializers/new_framework_defaults_7_0.rb index 5aefca5..eb40de8 100644 --- a/config/initializers/new_framework_defaults_7_0.rb +++ b/config/initializers/new_framework_defaults_7_0.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # # This file eases your Rails 7.0 framework defaults upgrade. diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 50bcf4e..810aade 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Define an application-wide HTTP permissions policy. For further # information see https://developers.google.com/web/updates/2018/06/feature-policy # diff --git a/db/seeds.rb b/db/seeds.rb index c8774b7..1e7cc80 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb index c2645f7..3e00517 100644 --- a/test/performance/browsing_test.rb +++ b/test/performance/browsing_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # require 'test_helper' # require 'rails/performance_test_help' # From 384b5a25e8228997ade9cb6fafbdc1cf992531d6 Mon Sep 17 00:00:00 2001 From: Kyle Le Date: Sat, 4 May 2024 22:26:18 +0700 Subject: [PATCH 3/3] Use release workflow to set version --- .github/workflows/release.yml | 3 +++ Gemfile | 1 + app/controllers/health_check_controller.rb | 2 +- config/application.rb | 1 + lib/kaui_standalone/version.rb | 5 +++++ test/integration/homepage_test.rb | 7 +++++++ 6 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/kaui_standalone/version.rb diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2111467..5c7dd86 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,9 @@ jobs: with: ruby-version: 'jruby-9.4.2.0' bundler-cache: false + - name: Tag repository + run: | + bundle exec gem bump -c -p -t -v ${{ github.event.inputs.perform_version }} - name: Configure Sonatype mirror uses: s4u/maven-settings-action@v2.3.0 # Go to Sonatype directly to avoid delay syncs (could get rid of this if actions/setup-java were to support mirrors). diff --git a/Gemfile b/Gemfile index 36440a3..8ad99ff 100644 --- a/Gemfile +++ b/Gemfile @@ -74,6 +74,7 @@ group :assets do end group :development do + gem 'gem-release' gem 'listen' gem 'puma' gem 'rubocop' diff --git a/app/controllers/health_check_controller.rb b/app/controllers/health_check_controller.rb index 0e57d1a..b012082 100644 --- a/app/controllers/health_check_controller.rb +++ b/app/controllers/health_check_controller.rb @@ -2,7 +2,7 @@ class HealthCheckController < ActionController::Base def health - response = { version: Kaui.version, status: 'UP' } + response = { version: KauiStandalone::VERSION, status: 'UP' } render json: response, status: 200 end end diff --git a/config/application.rb b/config/application.rb index 8826bc2..9979df3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,6 +6,7 @@ # The original function requires permission [100600 100400] which did not work with the Windows system # See this PR: https://github.com/killbill/killbill-admin-ui-standalone/pull/72 require_relative 'initializers/symmetric_file_permission_override' +require_relative '../lib/kaui_standalone/version' require 'rails/all' require 'avatax' require 'kanaui' diff --git a/lib/kaui_standalone/version.rb b/lib/kaui_standalone/version.rb new file mode 100644 index 0000000..d67e351 --- /dev/null +++ b/lib/kaui_standalone/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module KauiStandalone + VERSION = '3.0.7' +end diff --git a/test/integration/homepage_test.rb b/test/integration/homepage_test.rb index 255916b..ebe9513 100644 --- a/test/integration/homepage_test.rb +++ b/test/integration/homepage_test.rb @@ -23,4 +23,11 @@ class HomepageTest < ActionDispatch::IntegrationTest assert_redirected_to SIGN_IN_PATH assert_equal 'You need to sign in before continuing.', flash[:alert] end + + test 'Healthcheck' do + get "#{BASE_PATH}/health" + json_response = JSON.parse(response.body) + assert_equal 'UP', json_response['status'] + assert_response :success + end end