mirror of
https://github.com/discourse/discourse.git
synced 2024-12-18 09:54:17 +08:00
9caba30d5c
## What is the context here? The `docker.rake` Rakefile contains Rake tasks that are meant to be run in the `discourse/discourse_test:release` Docker image. For example, we have the `docker:test` Rake task that makes it easier to run the test suite for a particular Discourse commit. Why are we introducing a `docker:test:setup` Rake task? While we have the `docker:test` Rake task, it is very limited in the test commands that can be executed. It is very useful for automated testing but not very useful for running tests in the development environment. Therefore, we are introducing a `docker:test:setup` rake task that can be used to set up the test environment for running tests. The envisioned example usage is something like this: ``` docker run -d --name=discourse_test --entrypoint=/sbin/boot discourse/discourse_test:release docker exec -u discourse:discourse discourse_test ruby script/docker_test.rb --no-tests docker exec -u discourse:discourse discourse_test bundle exec rake docker:test:setup docker exec -u discourse:discourse discourse_test bundle exec rspec <path to file> ```
41 lines
848 B
Ruby
Executable File
41 lines
848 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
BIN = "/usr/lib/postgresql/#{ENV["PG_MAJOR"]}/bin"
|
|
DATA = "/tmp/test_data/pg"
|
|
|
|
def run(*args)
|
|
system(*args, exception: true)
|
|
end
|
|
|
|
should_setup = true
|
|
should_run = true
|
|
should_exec = false
|
|
while a = ARGV.pop
|
|
if a == "--skip-setup"
|
|
should_setup = false
|
|
elsif a == "--skip-run"
|
|
should_run = false
|
|
elsif a == "--exec"
|
|
should_exec = true
|
|
else
|
|
raise "Unknown argument #{a}"
|
|
end
|
|
end
|
|
|
|
if should_setup
|
|
run "rm -rf #{DATA}"
|
|
run "mkdir -p #{DATA}"
|
|
run "#{BIN}/initdb -D #{DATA}"
|
|
|
|
run "echo fsync = off >> #{DATA}/postgresql.conf"
|
|
run "echo full_page_writes = off >> #{DATA}/postgresql.conf"
|
|
run "echo shared_buffers = 500MB >> #{DATA}/postgresql.conf"
|
|
end
|
|
|
|
if should_exec
|
|
exec "#{BIN}/postgres -D #{DATA}"
|
|
elsif should_run
|
|
run "#{BIN}/pg_ctl -D #{DATA} start"
|
|
end
|