Skip to content

Commit

Permalink
war: fix various issues
Browse files Browse the repository at this point in the history
* Stick to Rails 6.1 for now, due to warbler compatibility issues with JRuby 9.4
  (jruby/warbler#539)
* Don't use git:// protocol in Gemfile, it won't work in the war
* Upgrade MariaDB driver
* Remove unecessary files from war
* Fix dummy_production.key permission at runtime
* Set a default secret key value
* ci: add Tomcat tests

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
  • Loading branch information
pierre committed Jun 25, 2023
1 parent 86dcfdc commit 9a00ed4
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 71 deletions.
113 changes: 111 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ jobs:
build-war:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- ruby-version: 'jruby-9.4.2.0'
docker-compose-file: 'docker-compose.ci-tomcat.mysql.yml'
- ruby-version: 'jruby-9.4.2.0'
docker-compose-file: 'docker-compose.ci-tomcat.postgresql.yml'
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -162,8 +169,110 @@ jobs:
- name: Configure Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 'jruby-9.4.2.0'
bundler-cache: false
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Build war
run: |
mvn package
- name: Start stack
run: |
cd docker
docker-compose -p it -f ${{ matrix.docker-compose-file }} up --no-start --build
docker start it_db_1
- name: Wait for MySQL
if: ${{ matrix.docker-compose-file == 'docker-compose.ci-tomcat.mysql.yml' }}
run: |
set +e
count=0
until mysqladmin ping -h 127.0.0.1 -u root --password=root --silent; do
if [[ "$count" == "25" ]]; then
exit 1
fi
(( count++ ))
printf '.'
sleep 5
done
set -e
- name: Wait for PostgreSQL
if: ${{ matrix.docker-compose-file == 'docker-compose.ci-tomcat.postgresql.yml' }}
run: |
set +e
count=0
until $(psql -h 127.0.0.1 -U postgres -p 5432 -l > /dev/null); do
if [[ "$count" == "25" ]]; then
exit 1
fi
(( count++ ))
printf '.'
sleep 5
done
set -e
- name: Start Kaui
run: |
# Don't wait for it, Kill Bill will take a while to start
docker start it_kaui_1
- name: Start Kill Bill
# Sometimes it gets stuck (if Kill Bill starts when the DB isn't ready?)
timeout-minutes: 4
run: |
docker start it_killbill_1
count=0
until $(curl --connect-timeout 10 --max-time 30 --output /dev/null --silent --fail http://${KB_ADDRESS}:${KB_PORT}/1.0/healthcheck); do
if [[ "$count" == "180" ]]; then
exit 64
fi
count=$(( count + 1 ))
sleep 1
done
curl --connect-timeout 10 --max-time 30 -v \
-X POST \
-u admin:password \
-H 'Content-Type: application/json' \
-H 'X-Killbill-CreatedBy: GitHub' \
-d '{"apiKey": "bob", "apiSecret": "lazar"}' \
"http://${KB_ADDRESS}:${KB_PORT}/1.0/kb/tenants"
- name: Run tests
run: |
count=0
until $(curl --connect-timeout 10 --max-time 30 --output /dev/null --silent --fail http://127.0.0.1:9090/); do
if [[ "$count" == "90" ]]; then
echo "$(curl -v http://127.0.0.1:9090/)"
exit 64
fi
count=$(( count + 1 ))
sleep 1
done
location=$(curl -sS -D - http://127.0.0.1:9090/ -o /dev/null | grep Location)
if [[ "$location" == "Location: http://127.0.0.1:9090/users/sign_in" ]]; then
echo Success
else
echo $location
echo "Location: http://127.0.0.1:9090/users/sign_in"
echo "$(curl -v http://127.0.0.1:9090/)"
exit 70
fi
- name: Debugging after failure
if: failure()
run: |
echo "[DEBUG] killbill healthcheck"
curl --connect-timeout 10 --max-time 30 -v http://${KB_ADDRESS}:${KB_PORT}/1.0/healthcheck || true
echo "[DEBUG] hostname"
hostname
echo "[DEBUG] netstat -tulpn"
sudo netstat -tulpn
echo "[DEBUG] docker network ls"
docker network ls
echo "[DEBUG] docker ps -a"
docker ps -a
echo "[DEBUG] killbill env"
docker exec it_killbill_1 env || true
echo "[DEBUG] db env"
docker exec it_db_1 env || true
echo "[DEBUG] killbill logs"
docker logs -t --details it_killbill_1 || true
echo "[DEBUG] db logs"
docker logs -t --details it_db_1 || true
echo "[DEBUG] kaui env"
docker exec it_kaui_1 env || true
echo "[DEBUG] kaui logs"
docker logs -t --details it_kaui_1 || true
43 changes: 23 additions & 20 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,60 @@ source 'https://rubygems.org'

gem 'jquery-rails', '~> 4.5.1'
gem 'mustache-js-rails', '~> 0.0.7'
gem 'rails', '~> 7.0'
gem 'rails', '~> 6.1'
gem 'sprockets-rails'

gem 'jruby-jars', '~> 9.4.2'
# End up in the war
# JRuby 9.4 not yet supported: https://github.com/jruby/warbler/issues/539
gem 'jruby-jars', '~> 9.3.2.0'

gem 'kaui'
gem 'kaui', '~> 2.2.0'
# gem 'kaui', path: '../killbill-admin-ui'
# gem 'kaui', github: 'killbill/killbill-admin-ui', ref: 'master'

gem 'kanaui'
# gem 'kanaui'
# gem 'kanaui', :path => '../killbill-analytics-ui'
# gem 'kanaui', github: 'killbill/killbill-analytics-ui', ref: 'master'

gem 'killbill-avatax'
# gem 'killbill-avatax'
# gem 'killbill-avatax', :path => '../killbill-avatax-ui'
# gem 'killbill-avatax', github: 'killbill/killbill-avatax-ui', ref: 'master'

gem 'killbill-kpm-ui'
# gem 'killbill-kpm-ui'
# gem 'killbill-kpm-ui', :path => '../killbill-kpm-ui'
# gem 'killbill-kpm-ui', github: 'killbill/killbill-kpm-ui', ref: 'master'

gem 'killbill-payment-test-ui'
# gem 'killbill-payment-test-ui'
# gem 'killbill-payment-test-ui', :path => '../killbill-payment-test-ui'
# gem 'killbill-payment-test-ui', github: 'killbill/killbill-payment-test-ui', ref: 'master'

gem 'kenui'
gem 'kenui', '~> 2.1.0'
# gem 'kenui', :path => '../killbill-email-notifications-ui'
# gem 'kenui', github: 'killbill/killbill-email-notifications-ui', ref: 'master'

gem 'killbill-deposit'
# gem 'killbill-deposit'
# gem 'killbill-deposit', :path => '../killbill-deposit-ui'
# gem 'killbill-deposit', github: 'killbill/killbill-deposit-ui', ref: 'main'

gem 'killbill-client'
# gem 'killbill-client'
# gem 'killbill-client', :path => '../killbill-client-ruby'
# gem 'killbill-client', github: 'killbill/killbill-client-ruby', ref: 'master'

gem 'i18n'
gem 'tzinfo-data'

if defined?(JRUBY_VERSION)
# See https://github.com/jruby/warbler/issues/508
gem 'warbler', github: 'jruby/warbler', branch: 'master'

gem 'therubyrhino'

gem 'nio4r', '2.5.2', platforms: :jruby

git 'https://github.com/jruby/activerecord-jdbc-adapter', branch: 'master' do
gem 'activerecord-jdbc-adapter'
# Add the drivers
gem 'jdbc-mariadb'
gem 'jdbc-postgres'
gem 'jdbc-sqlite3'
end
# Unlike other repos, we cannot rely on git:// here (won't work in the war, see https://github.com/jruby/warbler/issues/537)
gem 'activerecord-jdbc-adapter'
# Add the drivers
gem 'jdbc-postgres'
gem 'jdbc-sqlite3'
# Too old, driver is checked-in
# gem 'jdbc-mariadb'
else
gem 'mysql2'
gem 'pg'
Expand All @@ -72,6 +71,10 @@ group :assets do
end

group :development do
if defined?(JRUBY_VERSION)
# See https://github.com/jruby/warbler/issues/508
gem 'warbler', github: 'jruby/warbler', ref: 'master'
end
gem 'listen'
gem 'puma'
gem 'rubocop'
Expand Down
16 changes: 5 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@ else
exit 1
fi

# Get the version from the pom and then store it on a file on the root
VERSION=`grep -E '<version>([0-9]+\.[0-9]+\.[0-9]+)</version>' pom.xml | sed 's/[\t \n]*<version>\(.*\)<\/version>[\t \n]*/\1/'`
echo 'version: '$VERSION > version.yml

export RAILS_ENV=production
export SECRET_KEY_BASE=$(head -c 1024 /dev/urandom | base64 | tr -cd "[:upper:][:digit:]" | head -c 129)
chmod 600 config/keys/dummy_production.key

# 2.3.25 shipped with JRuby won't work
gem update bundler
bundle install
# 2.3.25 shipped with JRuby won't work (see https://github.com/jruby/warbler/issues/536)
gem install bundler --version=2.4.14

BUNDLE="bundle exec"
BUNDLE="bundle _2.4.14_"
RAILS="./bin/rails"

$BUNDLE install
$RAILS assets:clobber log:clear tmp:clear

# We cannot pre-compile assets unfortunately as it breaks Tomcat deployments in sub-directories
# $RAILS assets:precompile

$BUNDLE warble
$BUNDLE exec warble

# For quick testing:
#$BUNDLE warble executable war
Expand Down
55 changes: 29 additions & 26 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

require_relative 'boot'

# Ensure 600 permission (not maintained in the war)
File.chmod(0o600, './config/keys/dummy_production.key')

require 'rails/all'

require 'avatax'
require 'kanaui'
# require 'avatax'
# require 'kanaui'
require 'kenui'
require 'deposit'
require 'kpm'
require 'payment_test'
# require 'deposit'
# require 'kpm'
# require 'payment_test'

ENV['KAUI_ADDITIONAL_ENGINES'].split(',').each { |e| require e } if ENV['KAUI_ADDITIONAL_ENGINES'].present?

Expand All @@ -29,7 +32,7 @@ module KauiStandalone
end

class Application < Rails::Application
config.load_defaults 7.0
config.load_defaults 6.1

# Configuration for the application, engines, and railties goes here.
#
Expand All @@ -43,35 +46,35 @@ class Application < Rails::Application
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.after_initialize do
Kanaui.current_tenant_user = lambda do |session, user|
Kaui.current_tenant_user_options(user, session)
end
Kanaui.layout = Kaui.config[:layout]
# Kanaui.current_tenant_user = lambda do |session, user|
# Kaui.current_tenant_user_options(user, session)
# end
# Kanaui.layout = Kaui.config[:layout]

Avatax.current_tenant_user = lambda do |session, user|
Kaui.current_tenant_user_options(user, session)
end
Avatax.layout = Kaui.config[:layout]
# Avatax.current_tenant_user = lambda do |session, user|
# Kaui.current_tenant_user_options(user, session)
# end
# Avatax.layout = Kaui.config[:layout]

KPM.current_tenant_user = lambda do |session, user|
Kaui.current_tenant_user_options(user, session)
end
KPM.layout = Kaui.config[:layout]
# KPM.current_tenant_user = lambda do |session, user|
# Kaui.current_tenant_user_options(user, session)
# end
# KPM.layout = Kaui.config[:layout]

PaymentTest.current_tenant_user = lambda do |session, user|
Kaui.current_tenant_user_options(user, session)
end
PaymentTest.layout = Kaui.config[:layout]
# PaymentTest.current_tenant_user = lambda do |session, user|
# Kaui.current_tenant_user_options(user, session)
# end
# PaymentTest.layout = Kaui.config[:layout]

Kenui.current_tenant_user = lambda do |session, user|
Kaui.current_tenant_user_options(user, session)
end
Kenui.layout = Kaui.config[:layout]

Deposit.current_tenant_user = lambda do |session, user|
Kaui.current_tenant_user_options(user, session)
end
Deposit.layout = Kaui.config[:layout]
# Deposit.current_tenant_user = lambda do |session, user|
# Kaui.current_tenant_user_options(user, session)
# end
# Deposit.layout = Kaui.config[:layout]
end
end
end
27 changes: 27 additions & 0 deletions config/initializers/mariadb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Jdbc
module MariaDB
DRIVER_VERSION = '3.0.4'

def self.driver_jar
File.expand_path("../../lib/mariadb-java-client-#{DRIVER_VERSION}.jar", __dir__)
end

def self.load_driver(method = :load)
send method, driver_jar
end

def self.driver_name
'org.mariadb.jdbc.Driver'
end

if defined?(JRUBY_VERSION) && # enable backwards-compat behavior :
(Java::JavaLang::Boolean.get_boolean('jdbc.driver.autoload') ||
Java::JavaLang::Boolean.get_boolean('jdbc.mariadb.autoload') ||
java.lang.System.getProperty('kaui.db.adapter', ENV.fetch('KAUI_DB_ADAPTER', 'mariadb')) == 'mariadb')
warn "autoloading JDBC driver on require 'jdbc/mariadb'" if $VERBOSE
load_driver :require
end
end
end
10 changes: 5 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# We mount KAUI as root, since this is the primary engine
mount Kaui::Engine => '/', :as => 'kaui_engine'

mount Kanaui::Engine => '/analytics', :as => 'kanaui_engine'
mount Avatax::Engine => '/avatax', :as => 'avatax_engine'
mount KPM::Engine => '/kpm', :as => 'kpm_engine'
mount PaymentTest::Engine => '/payment_test', :as => 'payment_test_engine'
# mount Kanaui::Engine => '/analytics', :as => 'kanaui_engine'
# mount Avatax::Engine => '/avatax', :as => 'avatax_engine'
# mount KPM::Engine => '/kpm', :as => 'kpm_engine'
# mount PaymentTest::Engine => '/payment_test', :as => 'payment_test_engine'
mount Kenui::Engine => '/kenui', :as => 'kenui_engine'
mount Deposit::Engine => '/deposit', :as => 'deposit_engine'
# mount Deposit::Engine => '/deposit', :as => 'deposit_engine'

scope '/main' do
match '/available_engines' => 'main#available_engines', :via => :get, :as => 'available_engines'
Expand Down
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ test:
# and move the `production:` environment over there.

production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_key_base: <%= ENV["SECRET_KEY_BASE"] || 'changeme' %>
Loading

0 comments on commit 9a00ed4

Please sign in to comment.