Merge pull request #8376 from SuperTux88/improve-setup-and-docker-scripts

Improve setup and docker scripts
This commit is contained in:
Benjamin Neff 2022-07-23 00:56:19 +02:00
commit 1be79fb40e
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
3 changed files with 51 additions and 15 deletions

View file

@ -15,15 +15,20 @@ FileUtils.chdir APP_ROOT do
puts '== Installing dependencies ==' puts '== Installing dependencies =='
system! 'gem install bundler --conservative' system! 'gem install bundler --conservative'
system!('script/configure_bundler')
system('bundle check') || system!('bundle install') system('bundle check') || system!('bundle install')
# Install JavaScript dependencies # Install JavaScript dependencies
system! 'bin/yarn' system! 'bin/yarn'
# puts "\n== Copying sample files ==" unless File.exist?('config/diaspora.toml')
# unless File.exist?('config/database.yml') puts "\n== Copying example diaspora.toml =="
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml' FileUtils.cp 'config/diaspora.toml.example', 'config/database.yml'
# end end
unless File.exist?('config/database.yml')
puts "\n== Copying example database.yml =="
FileUtils.cp 'config/database.yml.example', 'config/database.yml'
end
puts "\n== Preparing database ==" puts "\n== Preparing database =="
system! 'bin/rails db:prepare' system! 'bin/rails db:prepare'
@ -31,6 +36,6 @@ FileUtils.chdir APP_ROOT do
puts "\n== Removing old logs and tempfiles ==" puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear' system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server ==" # puts "\n== Restarting application server =="
system! 'bin/rails restart' # system! 'bin/rails restart'
end end

View file

@ -1,4 +1,4 @@
FROM ruby:2.7-slim-buster FROM ruby:2.7-slim-bullseye
RUN DEBIAN_FRONTEND=noninteractive \ RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \ apt-get update && \
@ -12,7 +12,7 @@ RUN DEBIAN_FRONTEND=noninteractive \
libcurl4-openssl-dev \ libcurl4-openssl-dev \
libidn11-dev \ libidn11-dev \
libmagickwand-dev \ libmagickwand-dev \
libmariadbclient-dev \ libmariadb-dev-compat \
libpq-dev \ libpq-dev \
libssl-dev \ libssl-dev \
libxml2-dev \ libxml2-dev \

View file

@ -78,8 +78,11 @@ print_usage() {
;; ;;
bundle) bundle)
echo; echo "Install gems using bundle into $DIASPORA_ROOT" echo; echo "Install gems using bundle into $DIASPORA_ROOT"
print_usage_header "bundle [options]" \ print_usage_header "bundle"
"-d Run in background" ;;
yarn)
echo; echo "Install frontend dependencies using yarn into $DIASPORA_ROOT"
print_usage_header "yarn"
;; ;;
config) config)
echo; echo "Create basic configuration files for usage with PostgreSQL (default)" echo; echo "Create basic configuration files for usage with PostgreSQL (default)"
@ -98,6 +101,10 @@ print_usage() {
echo; echo "Show help on a command" echo; echo "Show help on a command"
print_usage_header "help COMMAND" print_usage_header "help COMMAND"
;; ;;
setup-rails)
echo; echo "Set up development environment (install dependencies, migrate db, ...)"
print_usage_header "setup-rails"
;;
setup-tests) setup-tests)
echo; echo "Prepare cached files and database contents for tests" echo; echo "Prepare cached files and database contents for tests"
print_usage_header "setup-tests" print_usage_header "setup-tests"
@ -147,9 +154,11 @@ print_usage_full() {
echo "Misc. Commands:" echo "Misc. Commands:"
echo " build Build basic diaspora* environment" echo " build Build basic diaspora* environment"
echo " bundle (Re-)Install gems for diaspora*" echo " bundle (Re-)Install gems for diaspora*"
echo " yarn (Re-)Install frontend dependencies for diaspora*"
echo " config Configure diaspora*" echo " config Configure diaspora*"
echo " exec Execute a command in the run environment (advanced)" echo " exec Execute a command in the run environment (advanced)"
echo " help Show help for commands" echo " help Show help for commands"
echo " setup-rails Prepare diaspora* development environment (install dependencies, migrate db)"
echo " setup-tests Prepare diaspora* test environment" echo " setup-tests Prepare diaspora* test environment"
echo echo
echo "Run '$SCRIPT_NAME help COMMAND' for more information on a command." echo "Run '$SCRIPT_NAME help COMMAND' for more information on a command."
@ -218,12 +227,19 @@ dia_bundle() {
echo "Installing gems via bundler ..." echo "Installing gems via bundler ..."
dia_docker_compose run \ dia_docker_compose run \
--rm \ --rm \
--no-deps $1 \ --no-deps \
-e DIA_NODB=1 \ -e DIA_NODB=1 \
diaspora \ diaspora \
/bin/sh -c "gem install bundler && script/configure_bundler && bin/bundle install --full-index" /bin/sh -c "gem install bundler && script/configure_bundler && bin/bundle install --full-index"
} }
dia_yarn() {
# Run yarn in order to install all frontend dependencies into $DIASPORA_ROOT
# Do not start database, not required and sometimes not yet configured
echo "Installing frontend dependencies via yarn ..."
dia_docker_compose run --rm --no-deps -e DIA_NODB=1 diaspora bin/yarn
}
dia_clean() { dia_clean() {
# Delete all containers and volumes # Delete all containers and volumes
for i in "$@"; do for i in "$@"; do
@ -423,14 +439,23 @@ dia_setup() {
set -e set -e
dia_build $build dia_build $build
dia_config $config dia_config $config
dia_bundle $bundle dia_bundle
dia_migrate $migrate dia_setup_rails
dia_setup_tests $setup_tests dia_setup_tests
) )
# stop db afterwards as it is not needed while dia is not running # stop db afterwards as it is not needed while dia is not running
dia_docker_compose stop $DIASPORA_DOCKER_DB dia_docker_compose stop $DIASPORA_DOCKER_DB
} }
dia_setup_rails() {
# Prepare rails, install dependencies, migrate database, ...
# stop db if it was not running before
echo "Setting up environment for tests ..."
if ! dia_is_db_running; then stopdb="dia_docker_compose stop $DIASPORA_DOCKER_DB"; fi
dia_docker_compose run --rm diaspora bin/setup
$stopdb
}
dia_setup_tests() { dia_setup_tests() {
# Prepare all possible tests # Prepare all possible tests
# stop db if it was not running before # stop db if it was not running before
@ -510,7 +535,7 @@ case "$dia_command" in
dia_build "$@" dia_build "$@"
;; ;;
bundle) bundle)
dia_bundle "$1" dia_bundle
;; ;;
clean) clean)
dia_clean "$@" dia_clean "$@"
@ -545,6 +570,9 @@ case "$dia_command" in
setup) setup)
dia_setup "$@" dia_setup "$@"
;; ;;
setup-rails)
dia_setup_rails
;;
setup-tests) setup-tests)
dia_setup_tests dia_setup_tests
;; ;;
@ -557,6 +585,9 @@ case "$dia_command" in
stop) stop)
dia_stop dia_stop
;; ;;
yarn)
dia_yarn
;;
*) *)
print_usage print_usage
exit 1 exit 1