Unset DATABASE_URL in .gitpod.yml (#7059)

* Unset DATABASE_URL in .gitpod.yml

* Only run bin/setup once

* Try alternative approach for unsetting DATABASE_URL

* Update bin/setup

* Consistently use db_url

* Fix bug caused by typo (= instead of ==)
This commit is contained in:
Michael Kohl 2020-04-03 20:56:43 +07:00 committed by GitHub
parent 990abc5eb2
commit 1d069d8ed1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 21 deletions

View file

@ -16,9 +16,7 @@ ports:
tasks:
- command: redis-server
- command: /home/gitpod/elasticsearch-7.5.2/bin/elasticsearch
- init: >
cp config/sample_application.yml config/application.yml &&
bin/setup 2>/dev/null || true
- init: cp config/sample_application.yml config/application.yml
command: >
while [ -z "${ALGOLIASEARCH_APPLICATION_ID:=$(cat config/application.yml | grep ALGOLIASEARCH_APPLICATION_ID | sed 's/.*:\s*//')}" ] ||
[ -z "${ALGOLIASEARCH_SEARCH_ONLY_KEY:=$(cat config/application.yml | grep ALGOLIASEARCH_SEARCH_ONLY_KEY | sed 's/.*:\s*//')}" ] ||

View file

@ -1,13 +1,17 @@
#!/usr/bin/env ruby
require 'fileutils'
require "fileutils"
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
APP_ROOT = File.expand_path("..", __dir__)
DB = if ENV['DATABASE_URL'].to_s.empty?
'PracticalDeveloper_development'
db_url = ENV["DATABASE_URL"].to_s
# We explicitly unset DATABASE_URL for Gitpod so bin/setup can do its job.
# See: https://github.com/thepracticaldev/dev.to/issues/7040
DB = if db_url.to_s.empty? || db_url == "postgresql://gitpod@localhost"
"PracticalDeveloper_development"
else
ENV['DATABASE_URL']
db_url
end
def system!(*args)
@ -19,39 +23,39 @@ FileUtils.chdir APP_ROOT do
# 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 --conservative'
system('bundle check') || system!('bundle install')
puts "== Installing dependencies =="
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
system! 'gem install foreman'
system! "gem install foreman"
# Install JavaScript dependencies if using Yarn
system('bin/yarn')
system("bin/yarn")
puts "\n== Copying sample files =="
unless File.exist?('config/database.yml')
FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
unless File.exist?("config/database.yml")
FileUtils.cp "config/database.yml.sample", "config/database.yml"
end
puts "\n== Preparing database =="
command = "psql -o /dev/null -q -n -c 'select 1' #{DB}"
db_exists = system(command)
if db_exists
system! 'bin/rails db:migrate'
system! "bin/rails db:migrate"
else
system! 'bin/rails db:setup'
system! "bin/rails db:setup"
end
puts "\n== Preparing Elasticsearch =="
system! 'bin/rails search:setup'
system! "bin/rails search:setup"
system! 'RAILS_ENV="test" bin/rails search:setup'
puts "\n== Updating Data =="
system! 'bin/rails data_updates:run'
system! "bin/rails data_updates:run"
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 =="
system! 'bin/rails restart'
system! "bin/rails restart"
end