Initial commit
This commit is contained in:
7
bin/bundle
Normal file
7
bin/bundle
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
||||
load Gem.bin_path('bundler', 'bundle')
|
||||
17
bin/daemons
Normal file
17
bin/daemons
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
|
||||
def daemons
|
||||
system 'nohup bundle exec ruby lib/daemons/amqp_daemon.rb matching >/dev/null 2>&1 &'
|
||||
system 'nohup bundle exec ruby lib/daemons/amqp_daemon.rb trade_executor >/dev/null 2>&1 &'
|
||||
system 'nohup bundle exec ruby lib/daemons/amqp_daemon.rb order_processor >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
Dir.chdir APP_ROOT do
|
||||
daemons
|
||||
end
|
||||
|
||||
49
bin/gendocs
Normal file
49
bin/gendocs
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
RAILS_ENV=development
|
||||
|
||||
if [ -f tmp/pids/server.pid ]; then
|
||||
kill $(cat tmp/pids/server.pid)
|
||||
fi
|
||||
|
||||
bundle install
|
||||
# Generate seed files.
|
||||
bin/init_config
|
||||
# Drop and create peatio_development and peatio_test databases.
|
||||
bundle exec rails db:drop db:create
|
||||
# Set the current RAILS_ENV environment in the ar_internal_metadata table.
|
||||
# (Used as part of the protected environment check.)
|
||||
bin/rails db:environment:set RAILS_ENV=$RAILS_ENV
|
||||
# Runs migrations for the current environment that have not run yet.
|
||||
bundle exec rails db:migrate
|
||||
# Runs the db/seeds.rb file.
|
||||
bundle exec rails db:seed
|
||||
|
||||
npm i -g swagger-markdown
|
||||
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/peatio_user_api_v2.md
|
||||
swagger-markdown -i tmp/management_api_v2_swagger.json -o ./docs/api/peatio_management_api_v2.md
|
||||
swagger-markdown -i tmp/admin_api_v2_swagger.json -o ./docs/api/peatio_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)
|
||||
22
bin/genversion
Normal file
22
bin/genversion
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
test -f .tags
|
||||
VERSION=$(<.tags)
|
||||
|
||||
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 Peatio
|
||||
class Application
|
||||
GIT_TAG = '${VERSION}'
|
||||
GIT_SHA = '$(git rev-parse --short HEAD)'
|
||||
BUILD_DATE = '$(date -u +"%Y-%m-%d %T")'
|
||||
VERSION = GIT_TAG
|
||||
end
|
||||
end
|
||||
EOF
|
||||
18
bin/init_config
Normal file
18
bin/init_config
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
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.strip)
|
||||
end
|
||||
22
bin/init_vault
Normal file
22
bin/init_vault
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env sh
|
||||
DOCKER_VAULT_ID=`docker ps | grep vault | awk '{ print $1 }'`
|
||||
|
||||
if [ -z "${DOCKER_VAULT_ID}" ]; then
|
||||
echo "Vault container not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${VAULT_TOKEN}" ]; then
|
||||
VAULT_TOKEN='changeme'
|
||||
else
|
||||
VAULT_TOKEN=${VAULT_TOKEN}
|
||||
fi
|
||||
|
||||
echo $VAULT_TOKEN
|
||||
|
||||
docker exec -e "VAULT_TOKEN=${VAULT_TOKEN}" ${DOCKER_VAULT_ID} sh -c \
|
||||
"vault secrets disable secret \
|
||||
&& vault secrets enable -path=secret -version=1 kv \
|
||||
&& vault secrets enable transit \
|
||||
&& vault secrets enable totp"
|
||||
|
||||
16
bin/link_config
Normal file
16
bin/link_config
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
|
||||
src_root = Pathname.new('/opt/peatio/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
|
||||
5
bin/logger
Normal file
5
bin/logger
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
while IFS= read -r line; do
|
||||
echo "[$1 at $(date -u "+%Y-%m-%d %H:%M:%S")] ${line}" >> /proc/1/fd/1
|
||||
done < /dev/stdin
|
||||
8
bin/rails
Normal file
8
bin/rails
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
APP_PATH = File.expand_path('../config/application', __dir__)
|
||||
require_relative '../config/boot'
|
||||
require 'rails/commands'
|
||||
8
bin/rake
Normal file
8
bin/rake
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../config/boot'
|
||||
require 'rake'
|
||||
Rake.application.run
|
||||
23
bin/rspec
Normal file
23
bin/rspec
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# This file was generated by Bundler.
|
||||
#
|
||||
# The application 'rspec' is installed as part of a gem, and
|
||||
# this file is here to facilitate running it.
|
||||
#
|
||||
|
||||
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
||||
load(bundle_binstub) if File.file?(bundle_binstub)
|
||||
|
||||
require "pathname"
|
||||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
||||
Pathname.new(__FILE__).realpath)
|
||||
|
||||
require "rubygems"
|
||||
require "bundler/setup"
|
||||
|
||||
load Gem.bin_path("rspec-core", "rspec")
|
||||
43
bin/setup
Normal file
43
bin/setup
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
# path to your application root
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
VAULT_TOKEN = ENV.fetch('VAULT_TOKEN', 'changeme')
|
||||
|
||||
Dir.chdir APP_ROOT do
|
||||
puts "\n=== Copying config files ==="
|
||||
system 'bin/init_config'
|
||||
|
||||
puts "\n=== Removing old logs and tempfiles ==="
|
||||
system 'rm -f log/* log/daemons/*'
|
||||
system 'bin/rake tmp:clear tmp:create'
|
||||
|
||||
if ENV['JWT_PUBLIC_KEY'].nil?
|
||||
puts "\n=== Creating secrets"
|
||||
system 'bundle exec peatio security keygen --path=config/secrets'
|
||||
end
|
||||
# just done init in alvand project
|
||||
#
|
||||
# puts "\n=== Creting backend ==="
|
||||
# { 'VAULT_TOKEN' => VAULT_TOKEN }.tap do |env|
|
||||
# system(env, 'docker-compose -f config/backend.yml up -Vd')
|
||||
# end
|
||||
# sleep 5
|
||||
# puts "\n=== Initialize InfluxDB ==="
|
||||
# system 'docker-compose -f config/backend.yml exec influxdb bash -c "cat influxdb.sql | influx"'
|
||||
#
|
||||
# puts "\n=== Setup Vault"
|
||||
# system "bin/init_vault"
|
||||
|
||||
# in production we run db:setup as k8s jobs
|
||||
if ENV['RAILS_ENV'] == 'production'
|
||||
puts "\n=== Preparing database schema ==="
|
||||
system 'bin/rake db:schema:dump'
|
||||
else
|
||||
puts "\n=== Setup database ==="
|
||||
system 'bin/rake db:create db:migrate; bin/rake db:seed'
|
||||
end
|
||||
end
|
||||
33
bin/update
Normal file
33
bin/update
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
include FileUtils
|
||||
|
||||
# path to your application root.
|
||||
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
||||
|
||||
def system!(*args)
|
||||
system(*args) || abort("\n== Command #{args} failed ==")
|
||||
end
|
||||
|
||||
# TODO: Add Peatio specific updates.
|
||||
puts ' == This script is not implemented yet =='
|
||||
exit(1)
|
||||
|
||||
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')
|
||||
|
||||
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