fix bundle update error by this module

This commit is contained in:
chiu 2020-02-14 22:31:52 +08:00
parent 9831147c79
commit b63edd5e8c
4 changed files with 362 additions and 1 deletions

View File

@ -2,7 +2,80 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "announcement/version"
app_path = File.expand_path(__dir__)
template_path = ENV['PWD'] + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
puts 'editing files for sassc'
new_gemfile_text = File.read(app_path+'/temp_file/Gemfile')
old_gemfile_text = File.read(ENV['PWD']+'/Gemfile')
check_texts = ['@import "../../bootstrap/variables";',".response-content {\n position: relative;\n\n @media (min-width: $screen-sm) {\n width: 100%;\n }\n\n @media (min-width: $screen-md) {\n width: 970px;\n }\n\n @media (min-width: $screen-lg) {\n width: 1100px;\n }\n}\n"]
all_template.each do |folder|
if !folder.include?('mobile')
begin
if folder.split('/')[-1] != 'mobile'
@filename = folder+'assets/stylesheets/template/base/_variables.scss'
texts = File.read(@filename)
check_texts.each do |check_text|
if !texts.include?(check_text)
puts "editing #{folder}assets/stylesheets/template/base/_variables.scss"
File.open(@filename, 'a') do |file|
file.puts check_text
end
end
end
end
rescue => e
puts "not found #{folder}assets/stylesheets/template/base/_variables.scss"
end
end
end
if old_gemfile_text != new_gemfile_text
puts 'updating gemfile'
File.open(ENV['PWD']+'/Gemfile', 'w') do |file|
file.write new_gemfile_text
end
old_playground = File.read (ENV['PWD']+'/app/controllers/admin/playground_controller.rb') rescue ''
new_playground = File.read (app_path+'/temp_file/playground_controller.rb') rescue ''
if old_playground != new_playground
puts 'updating playground'
File.open(ENV['PWD']+'/app/controllers/admin/playground_controller.rb', 'w') do |file|
file.write new_playground
end
end
old_multithread = File.read (ENV['PWD']+'/app/models/multithread.rb') rescue ''
new_multithread = File.read (app_path+'/temp_file/multithread.rb') rescue ''
if old_multithread != new_multithread
puts 'updating multithread'
File.open(ENV['PWD']+'/app/models/multithread.rb', 'w') do |file|
file.write new_multithread
end
end
log_development = File.mtime(ENV['PWD']+'/log/development.log').strftime('%Y%m%d%H%M').to_i rescue 0
log_production = File.mtime(ENV['PWD']+'/log/production.log').strftime('%Y%m%d%H%M').to_i rescue 0
if log_development > log_production
mode = 'development'
else
mode = 'production'
end
files = Dir[ENV['PWD']+'/Gemfile.lock']
if files.count ==0
command1 = "cd #{ENV['PWD']} && gem install bundler -v 1.17.3 && bundle update"
else
command1 = "cd #{ENV['PWD']} && gem install bundler -v 1.17.3 && mv -f Gemfile.lock Gemfile.lock.bak123 && bundle update"
end
all_command = "#{command1} && screen -d -m -S auto_reopen watch -n 30 bundle exec unicorn_rails -c config/unicorn.rb -D -E #{mode} && kill -s TERM `cat tmp/pids/unicorn.pid` && bundle exec unicorn_rails -c config/unicorn.rb -D -E #{mode}|at now"
a = Thread.start do
Bundler.with_clean_env do
puts ENV['PWD']
puts mode
exec(all_command)
end
end
a.priority = 2
sleep 2
a.run
#Thread.exit
end
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "announcement"

104
temp_file/Gemfile Normal file
View File

@ -0,0 +1,104 @@
source 'https://rubygems.org'
#test!!!!!!!!
#social gems
gem "omniauth-google-oauth2"
#rails gem
gem 'rake','~> 12.3.3'
gem 'sassc-rails', '~>1.3.0'
gem 'rails', '~> 4.1.16'
gem 'sanitize', '~> 4.6.6'
gem 'faraday', '~>0.15.4'
#assets and templates
#gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jquery-ui-rails', "5.0.0"
gem 'turbolinks'
gem 'normalize-rails', '~> 3.0.1'
#password
gem 'bcrypt-ruby', '~> 3.1.5'
#json
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spring', '~> 1.7.2', group: :development
gem 'active_model_serializers'
#parser
gem 'nokogiri', '~> 1.7.0.1'
#store api
gem 'httparty'
#database
# gem 'mongoid', github: "mongoid/mongoid"
gem 'mongoid', '~> 4.0.2'
# sockets
# gem "websocket-rails"
#file uploading and carrierwave
gem "mini_magick", "3.5.0"
gem 'carrierwave'
gem 'carrierwave-mongoid','~> 0.10.0', :require => 'carrierwave/mongoid'
gem 'zip-zip'
gem 'kaminari', '~> 1.0.1'
gem 'kaminari-mongoid', '~> 0.1.0'
gem 'impressionist', '~> 1.5.2'
gem 'chartkick', '~> 2.3.5'
gem 'usagewatch_ext'
gem 'ckeditor', '~> 4.2.4'
gem 'unicorn', '~> 5.4.0'
gem 'zhconv'
gem 'time_difference'
gem 'execjs'
gem 'therubyracer'
#excel
gem 'axlsx_rails'
gem 'spreadsheet'
gem 'rubyXL'
#form helpers
gem 'dynamic_form'
#built in modules
eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))
#modules installed from the store
eval(File.read(File.dirname(__FILE__) + '/downloaded_extensions.rb'))
if File.exists?(File.dirname(__FILE__) + '/extra_gems.rb')
eval(File.read(File.dirname(__FILE__) + '/extra_gems.rb'))
end
#development related gems
group :development do
gem 'better_errors'
# gem 'guard-bundler'
# gem 'guard-rails'
gem 'rails_layout'
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', '~> 0.9.10', :require=>false
gem 'byebug', '~> 9.0.6'
gem "binding_of_caller"
end
#testing gems
group :test do
gem "minitest", '~>5.11.3'
gem 'minitest-spec-rails'
end
#ask
gem 'gotcha'
#caching observers
# gem 'mongoid-observers'
#desktop
# gem 'angularjs-rails', '~> 1.2.20'
# gem 'angular-ui-bootstrap-rails', '~> 0.11.0'
# gem 'jquery_mousewheel_rails', '~> 3.1.11.3'

5
temp_file/multithread.rb Normal file
View File

@ -0,0 +1,5 @@
class Multithread
include Mongoid::Document
field :key
field :status
end

View File

@ -0,0 +1,179 @@
require "open3"
class Admin::PlaygroundController < OrbitAdminController
before_filter :check_for_testers, :only => "index"
layout "structure"
include Admin::PlaygroundHelper
before_action :clean_multithread_model, :only => :command
def index
modules = ["announcement", "faq", "ad_banner", "archive", "gallery", "web_resource"]
@default_modules = modules.collect do |mod|
ma = ModuleApp.where(:key => mod).first
[ma.title,mod]
end
end
def clean_multithread_model
mul = Multithread.where(key: 'playground').first
mul.destroy if !mul.nil?
end
def generatefakedata
ma = ModuleApp.where(:key => params[:module]).first rescue nil
if !ma.nil?
case ma.key
when "announcement"
make_announcement_fake_data(ma, params[:number].to_i)
when "faq"
make_faq_fake_data(ma, params[:number].to_i)
when "ad_banner"
make_ad_banner_fake_data(ma, params[:number].to_i)
when "archive"
make_archive_fake_data(ma, params[:number].to_i)
when "gallery"
make_gallery_fake_data(ma, params[:number].to_i)
when "web_resource"
make_web_resource_fake_data(ma, params[:number].to_i)
end
end
render :json => {"success" => true}.to_json
end
def deletefakedata
ma = params[:module]
fd = FakeData.where(:module => ma).first rescue nil
if !fd.nil?
case ma
when "announcement"
delete_announcement_fake_data(ma)
when "faq"
delete_faq_fake_data(ma)
when "ad_banner"
delete_ad_banner_fake_data(ma)
when "archive"
delete_archive_fake_data(ma)
when "gallery"
delete_gallery_fake_data(ma)
when "web_resource"
delete_web_resource_fake_data(ma)
end
else
render :json => {"success" => false}.to_json and return
end
render :json => {"success" => true}.to_json
end
def command
response = {}
Multithread.create(key: 'playground',status: {output: [],error: false,alive:true})
case params[:command]
when "clean"
clean_assets
response["success"] = true
when "precompile"
precompile
response["success"] = true
when "bundle"
bundle_update
response["success"] = true
when "restart_server"
restart_server
response["success"] = true
when "restart_unicorn"
restart_unicorn(Rails.env)
response["success"] = true
when "switch_to_production"
restart_unicorn("production")
response["success"] = true
when "switch_to_development"
restart_unicorn("development")
response["success"] = true
else
exec_other_command(params[:command])
response["success"] = true
end
render :json => response.to_json
end
def console_output
if params[:type] == "restart"
render :json => {"success" => true}.to_json
file = File.join(Rails.root,"tmp","restart_unicorn.sh")
File.delete(file) if File.exists?(file)
else
mul = Multithread.where(key: 'playground').first
if !mul.nil?
render :json => {"alive" => mul.status['alive'], "response" => mul.status['output'][params[:count].to_i..-1], "error" => mul.status['error']}.to_json
if !mul.status['alive']
mul.status['output'] = []
mul.status['error'] = false
mul.save
end
else
render :json => {"alive" => true, "response" => "", "error" => false}.to_json
end
end
end
private
def precompile
cmd = "RAILS_ENV=production bundle exec rake assets:precompile"
exec_other_command(cmd)
end
def exec_other_command(command)
mul = Multithread.where(key: 'playground').first
Thread.new do
begin
Bundler.with_clean_env do
IO.popen(command,:err=>[:child, :out]) do |stdout|
stdout.each do |line|
l = line.chomp
mul.status['output'] << l
if l == "rake aborted!"
mul.status['error'] = true
end
mul.save
end
end
mul.status['alive'] = false
mul.save
end
rescue => e
mul.status['alive'] = false
mul.status['output'] << e.inspect
mul.status['error'] = true
mul.save
end
end
end
def bundle_update
cmd = "bundle update"
exec_other_command(cmd)
end
def restart_server
cmd ="kill -s USR2 `cat tmp/pids/unicorn.pid`"
exec_other_command(cmd)
end
def clean_assets
cmd = "rm -r public/assets"
exec_other_command(cmd)
end
def restart_unicorn(mode)
mode = Rails.env if mode.nil?
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
content = "kill -s TERM `cat tmp/pids/unicorn.pid` && bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode} | at now"
system("bundle exec #{unicorn_rails} -c #{ENV['PWD']}/config/unicorn.rb -D -E #{mode} | at now +1 minute")
exec_other_command(content)
end
def check_for_testers
render_401 if !current_user.beta_tester && current_user.user_name != "rulingcom"
end
end