Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails: 6.1 support #51

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 113 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.3.10.0'
docker-compose-file: 'docker-compose.ci-tomcat.mysql.yml'
- ruby-version: 'jruby-9.3.10.0'
docker-compose-file: 'docker-compose.ci-tomcat.postgresql.yml'
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -162,8 +169,112 @@ 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 -s -o /dev/null -w "%{redirect_url}" http://127.0.0.1:9090/)
if [[ "$location" == "http://127.0.0.1:9090/users/sign_in" ]]; then
echo Success
# Always print logs for visual inspection
echo "[DEBUG] kaui logs"
docker logs -t --details it_kaui_1 || true
else
echo $location
curl --connect-timeout 10 --max-time 30 -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
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ env:

jobs:
release:
runs-on: ubuntu-latest
# Match killbill/kaui (same libc)
runs-on: ubuntu-20.04
steps:
- name: Checkout code
if: github.event.inputs.perform_version == ''
Expand All @@ -41,7 +42,8 @@ jobs:
- name: Configure Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 'jruby-9.4.2.0'
# JRuby 9.4 not yet supported by warbler
ruby-version: 'jruby-9.3.10.0'
bundler-cache: false
- name: Configure Sonatype mirror
uses: s4u/maven-settings-action@v2.3.0
Expand Down
39 changes: 20 additions & 19 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@ source 'https://rubygems.org'

gem 'jquery-rails', '~> 4.5.1'
gem 'mustache-js-rails', '~> 0.0.7'
gem 'rails', '~> 7.0'
# Staying on Rails 6.x as JRuby 9.4 is not yet supported with Warbler (https://github.com/jruby/warbler/issues/539)
gem 'rails', '~> 6.1'
gem 'sprockets-rails'

gem 'jruby-jars', '~> 9.4.2'

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', '~> 2.2.0'
# gem 'kanaui', :path => '../killbill-analytics-ui'
# gem 'kanaui', github: 'killbill/killbill-analytics-ui', ref: 'master'

gem 'killbill-avatax'
gem 'killbill-avatax', '~> 2.2.0'
# 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', '~> 2.1.0'
# 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', '~> 2.1.0'
# 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', '~> 0.1.0'
# gem 'killbill-deposit', :path => '../killbill-deposit-ui'
# gem 'killbill-deposit', github: 'killbill/killbill-deposit-ui', ref: 'main'

Expand All @@ -45,20 +44,21 @@ gem 'i18n'
gem 'tzinfo-data'

if defined?(JRUBY_VERSION)
# See https://github.com/jruby/warbler/issues/508
gem 'warbler', github: 'jruby/warbler', branch: 'master'
# JRuby jars ending up in the war
# JRuby 9.4 not yet supported: https://github.com/jruby/warbler/issues/539
gem 'jruby-jars', '~> 9.3.10.0'

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 @@ -75,6 +75,7 @@ group :development do
gem 'listen'
gem 'puma'
gem 'rubocop'
gem 'warbler', github: 'jruby/warbler', ref: 'master' if defined?(JRUBY_VERSION)
end

group :test do
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class ApplicationController < ActionController::Base
after_action :clear_mdc_context

def check_for_redirect_to_tenant_screen
unless Kaui.is_user_assigned_valid_tenant?(current_user, session)

unless Kaui.user_assigned_valid_tenant?(current_user, session)
if params[:format] == 'json'
# While technically true, the :bad_request status would display a flash error, which can be confusing for the user
# render :json => { :error => 'No tenant selected' }, :status => :bad_request
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
5 changes: 4 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

require_relative 'boot'

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

require 'rails/all'

require 'avatax'
Expand Down Expand Up @@ -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 Down
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
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' %>
3 changes: 0 additions & 3 deletions config/warble.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
config.gem_excludes = [%r{^(tests?|spec)/}, # Careful not to ignore things like rack-test (required by actionpack)
%r{^(examples?|doc-api|guides?)/}]

# See https://github.com/jruby/warbler/issues/266
config.includes = FileList['init.rb', 'version.yml']

config.java_classes = FileList['logback.xml']

config.webxml.jruby.rack.logging = 'slf4j'
Expand Down
6 changes: 6 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 8.5.x -> matches our docs
# jdk11-temurin -> matches our CI
# focal -> matches killbill/base
FROM tomcat:8.5.90-jdk11-temurin-focal

COPY killbill-admin-ui-standalone.war /usr/local/tomcat/webapps/ROOT.war
32 changes: 32 additions & 0 deletions docker/docker-compose.ci-tomcat.mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'

services:
kaui:
build:
context: ../
dockerfile: ./docker/Dockerfile
ports:
- "9090:8080"
environment:
- KAUI_CONFIG_DAO_URL=jdbc:mysql://db:3306/kaui
- KAUI_CONFIG_DAO_USER=root
- KAUI_CONFIG_DAO_PASSWORD=killbill
- KAUI_KILLBILL_URL=http://killbill:8080
killbill:
network_mode: host
image: killbill/killbill:0.24.3
environment:
- KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
- KILLBILL_DAO_URL=jdbc:mysql://127.0.0.1:3306/killbill
- KILLBILL_DAO_USER=root
- KILLBILL_DAO_PASSWORD=root
- KILLBILL_SERVER_TEST_MODE=true
- KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
- KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
depends_on:
- db
db:
network_mode: host
image: killbill/mariadb:0.24
environment:
- MYSQL_ROOT_PASSWORD=root
Loading
Loading