eBooru/bin/setup
Earlopain 59e80b7a4d
[Docker] Implement recommendations from review
* Use alpine as the base image
* Parallelize bundle install

Using alpine as base make is feasable to use the provides vips library.
The version is actually newer than what was installed previously.

Other stuff I did:
* Set SECRET_TOKEN/SESSION_SECRET_KEY from docker-compose
* Mute elasticsearch startup logspam
* Execute image as root. This means mounted volume do'nt need to  be chowned
2021-11-16 21:32:40 +01:00

47 lines
1.5 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require 'fileutils'
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
FileUtils.chdir APP_ROOT do
# This script is a way to setup or update your development environment automatically.
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler:2.0.1'
system! 'bundler config github.https true'
system('bundle check') || system!('bundle install -j$(nproc)')
# Install JavaScript dependencies
system('bin/yarn')
puts "\n== Copying sample files =="
unless File.exist?('config/database.yml')
FileUtils.cp 'docker/database.yml', 'config/database.yml'
end
unless File.exist?('config/danbooru_local_config.rb')
FileUtils.cp 'docker/danbooru_local_config.rb', 'config/danbooru_local_config.rb'
end
puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
puts "\n== Preparing search indices =="
system! 'bin/rails r Post.__elasticsearch__.create_index!'
system! 'bin/rails r Post.import'
system! 'bin/rails r PostArchive.__elasticsearch__.create_index!'
system! 'bin/rails r PostArchive.import'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end