Initial commit
This commit is contained in:
3
bin/bundle
Normal file
3
bin/bundle
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env ruby
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
||||
load Gem.bin_path('bundler', 'bundle')
|
||||
26
bin/cloudflare
Normal file
26
bin/cloudflare
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'erb'
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
# Open Source license key provided by Openware has some download rate and amount limits
|
||||
# We strongly suggest you to create your oun key and pass via --build-arg MAXMINDDB_LICENSE_KEY
|
||||
# All the guidance on how to create license key you can find here - https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases/
|
||||
MAXMINDDB_LICENSE_KEY='T6ElPBlyOOuCyjzw'.freeze
|
||||
MAXMINDDB_LINK="https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&suffix=tar.gz&license_key=#{MAXMINDDB_LICENSE_KEY}"
|
||||
|
||||
root = Pathname.new(File.expand_path('../../', __FILE__))
|
||||
# Download MaxMind Country DB
|
||||
system "mkdir -p #{root}/geolite;
|
||||
wget -O #{root}/geolite.tar.gz \"#{MAXMINDDB_LINK}\";
|
||||
tar xzf #{root}/geolite.tar.gz -C #{root}/geolite --strip-components 1;
|
||||
rm -rf #{root}/geolite.tar.gz"
|
||||
|
||||
# Download list of Cloudflare IP Ranges (v4 and v6)
|
||||
system "curl https://www.cloudflare.com/ips-v4 >> #{root}/config/cloudflare_ips.yml;
|
||||
echo '\n' >> #{root}/config/cloudflare_ips.yml;
|
||||
curl https://www.cloudflare.com/ips-v6 >> #{root}/config/cloudflare_ips.yml"
|
||||
|
||||
|
||||
system 'nohup ./bin/mailer --config=config/mailer.yml run >/dev/null 2>&1 &'
|
||||
|
||||
system 'echo @@@ Geolite and Cloadfalre and Mailer finished @@@'
|
||||
57
bin/gendocs
Normal file
57
bin/gendocs
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
RAILS_ENV=development
|
||||
|
||||
if [ -f tmp/pids/server.pid ]; then
|
||||
kill $(cat tmp/pids/server.pid)
|
||||
fi
|
||||
|
||||
if [ -n "${V}" ]; then
|
||||
cat > config/initializers/versioning.rb << EOF
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
# This file is auto-generated from the current state of VCS.
|
||||
# Instead of editing this file, please use bin/gendocs.
|
||||
module Barong
|
||||
class Application
|
||||
GIT_TAG = '${V}'
|
||||
GIT_SHA = '$(git rev-parse --short HEAD)'
|
||||
BUILD_DATE = '$(date --rfc-3339=seconds)'
|
||||
VERSION = GIT_TAG
|
||||
end
|
||||
end
|
||||
EOF
|
||||
fi
|
||||
|
||||
bundle install
|
||||
bin/init_config
|
||||
bundle exec rake db:drop db:create db:migrate db:seed
|
||||
npm i -g swagger-markdown
|
||||
npm i -g prettyjson-cli
|
||||
bundle exec rails s -d
|
||||
while [ ! -f tmp/pids/server.pid ]
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
sleep 5 # Wait additional time until Rails starts listen port.
|
||||
|
||||
curl http://localhost:3000/api/v2/swagger > tmp/user_api_v2_swagger.json
|
||||
curl http://localhost:3000/api/v2/management/swagger > tmp/management_api_v2_swagger.json
|
||||
curl http://localhost:3000/api/v2/admin/swagger > tmp/admin_api_v2_swagger.json
|
||||
|
||||
mkdir -p docs/api/swagger
|
||||
|
||||
swagger-markdown -i tmp/user_api_v2_swagger.json -o ./docs/api/barong_user_api_v2.md
|
||||
swagger-markdown -i tmp/management_api_v2_swagger.json -o ./docs/api/barong_management_api_v2.md
|
||||
swagger-markdown -i tmp/admin_api_v2_swagger.json -o ./docs/api/barong_admin_api_v2.md
|
||||
|
||||
ruby -r json -e "puts JSON.pretty_generate(JSON.parse(File.read('tmp/user_api_v2_swagger.json')))" \
|
||||
> docs/api/swagger/user_api.json
|
||||
ruby -r json -e "puts JSON.pretty_generate(JSON.parse(File.read('tmp/management_api_v2_swagger.json')))" \
|
||||
> docs/api/swagger/management_api.json
|
||||
ruby -r json -e "puts JSON.pretty_generate(JSON.parse(File.read('tmp/admin_api_v2_swagger.json')))" \
|
||||
> docs/api/swagger/admin_api.json
|
||||
|
||||
kill $(cat tmp/pids/server.pid)
|
||||
15
bin/init_config
Normal file
15
bin/init_config
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'erb'
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
|
||||
src_root = Pathname.new(File.expand_path('../../config/templates', __FILE__))
|
||||
dest_root = Pathname.new(File.expand_path('../../config', __FILE__))
|
||||
|
||||
Dir[src_root.join('**/*.erb').to_s].each do |f|
|
||||
dest = dest_root.join(Pathname.new(f).relative_path_from(src_root)).sub(/\.erb\z/, '')
|
||||
FileUtils.mkpath(dest.dirname)
|
||||
puts "Copy #{f} -> #{dest}"
|
||||
File.write(dest, ERB.new(File.read(f)).result)
|
||||
end
|
||||
7
bin/init_vault
Normal file
7
bin/init_vault
Normal file
@@ -0,0 +1,7 @@
|
||||
DOCKER_VAULT_ID=`docker ps | grep vault | awk '{ print $1 }'`
|
||||
|
||||
docker exec ${DOCKER_VAULT_ID} sh -c \
|
||||
"vault secrets disable secret \
|
||||
&& vault secrets enable -path=secret -version=1 kv \
|
||||
&& vault secrets enable totp"
|
||||
|
||||
18
bin/install_plugins
Normal file
18
bin/install_plugins
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'fileutils'
|
||||
require 'yaml'
|
||||
|
||||
Dir['vendor/plugins/*'].each { |d| FileUtils.rm_rf(d) }
|
||||
|
||||
plugins = YAML.load_file('config/plugins.yml').yield_self { |ary| ary || [] }.map do |plugin|
|
||||
[ %[git clone #{plugin.fetch('git')} vendor/plugins/#{plugin.fetch('name')}],
|
||||
%[cd vendor/plugins/#{plugin.fetch('name')} && git checkout #{plugin.fetch('commit')}],
|
||||
].each do |command|
|
||||
Kernel.system(command)
|
||||
Kernel.exit(false) unless $?.success?
|
||||
end
|
||||
plugin
|
||||
end
|
||||
|
||||
Kernel.puts "\n#{plugins.count} plugin(s) installed to vendor/plugins."
|
||||
15
bin/link_config
Normal file
15
bin/link_config
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
|
||||
src_root = Pathname.new('/opt/barong/config')
|
||||
dest_root = Pathname.new(File.expand_path('../../config', __FILE__))
|
||||
|
||||
Dir[src_root.join('**/*.yml').to_s].each do |f|
|
||||
dest = dest_root.join(Pathname.new(f).relative_path_from(src_root))
|
||||
Kernel.puts "Link #{f} -> #{dest}"
|
||||
FileUtils.ln_s(f, dest, force: true)
|
||||
end
|
||||
28
bin/mailer
Normal file
28
bin/mailer
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require File.expand_path('../../config/environment', __FILE__)
|
||||
|
||||
class Mailer
|
||||
extend GLI::App
|
||||
|
||||
program_desc 'Notification Hub'
|
||||
|
||||
flag :config, desc: 'Path to mailer config file', default_value: 'config/mailer.yml'
|
||||
|
||||
command :stop do |c|
|
||||
c.action do
|
||||
end
|
||||
end
|
||||
|
||||
command :run do |c|
|
||||
c.desc 'Run processing email events'
|
||||
c.action do |global_options, _options, _args|
|
||||
config = YAML.load_file(global_options[:config]).deep_symbolize_keys
|
||||
EventMailer.call(config[:events], config[:exchanges], config[:keychain])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
exit Mailer.run(ARGV)
|
||||
9
bin/rails
Normal file
9
bin/rails
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env ruby
|
||||
begin
|
||||
load File.expand_path('../spring', __FILE__)
|
||||
rescue LoadError => e
|
||||
raise unless e.message.include?('spring')
|
||||
end
|
||||
APP_PATH = File.expand_path('../config/application', __dir__)
|
||||
require_relative '../config/boot'
|
||||
require 'rails/commands'
|
||||
9
bin/rake
Normal file
9
bin/rake
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env ruby
|
||||
begin
|
||||
load File.expand_path('../spring', __FILE__)
|
||||
rescue LoadError => e
|
||||
raise unless e.message.include?('spring')
|
||||
end
|
||||
require_relative '../config/boot'
|
||||
require 'rake'
|
||||
Rake.application.run
|
||||
36
bin/setup
Normal file
36
bin/setup
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'fileutils'
|
||||
include FileUtils
|
||||
|
||||
# path to your application root.
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
|
||||
def system!(*args)
|
||||
system(*args) || abort("\n== Command #{args} failed ==")
|
||||
end
|
||||
|
||||
chdir APP_ROOT do
|
||||
# This script is a starting point to setup your application.
|
||||
# Add necessary setup steps to this file.
|
||||
|
||||
puts '== Installing dependencies =='
|
||||
system! 'gem install bundler --conservative'
|
||||
system('bundle check') || system!('bundle install')
|
||||
|
||||
# Install JavaScript dependencies if using Yarn
|
||||
# system('bin/yarn')
|
||||
|
||||
# puts "\n== Copying sample files =="
|
||||
# unless File.exist?('config/database.yml')
|
||||
# cp 'config/database.yml.sample', 'config/database.yml'
|
||||
# end
|
||||
|
||||
puts "\n== Preparing database =="
|
||||
system! 'bin/rails db:setup'
|
||||
|
||||
puts "\n== Removing old logs and tempfiles =="
|
||||
system! 'bin/rails log:clear tmp:clear'
|
||||
|
||||
puts "\n== Restarting application server =="
|
||||
system! 'bin/rails restart'
|
||||
end
|
||||
31
bin/update
Normal file
31
bin/update
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'fileutils'
|
||||
include FileUtils
|
||||
|
||||
# path to your application root.
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
|
||||
def system!(*args)
|
||||
system(*args) || abort("\n== Command #{args} failed ==")
|
||||
end
|
||||
|
||||
chdir APP_ROOT do
|
||||
# This script is a way to update your development environment automatically.
|
||||
# Add necessary update steps to this file.
|
||||
|
||||
puts '== Installing dependencies =='
|
||||
system! 'gem install bundler --conservative'
|
||||
system('bundle check') || system!('bundle install')
|
||||
|
||||
# Install JavaScript dependencies if using Yarn
|
||||
# system('bin/yarn')
|
||||
|
||||
puts "\n== Updating database =="
|
||||
system! 'bin/rails db:migrate'
|
||||
|
||||
puts "\n== Removing old logs and tempfiles =="
|
||||
system! 'bin/rails log:clear tmp:clear'
|
||||
|
||||
puts "\n== Restarting application server =="
|
||||
system! 'bin/rails restart'
|
||||
end
|
||||
Reference in New Issue
Block a user