diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7538d6d6d7..2ded21021b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,6 @@ jobs: DISCOURSE_HOSTNAME: www.example.com RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072 RAILS_ENV: test - PGHOST: postgres PGUSER: discourse PGPASSWORD: discourse USES_PARALLEL_DATABASES: ${{ matrix.build_type == 'backend' && matrix.target == 'core' }} @@ -32,27 +31,10 @@ jobs: matrix: build_type: [backend, frontend, annotations] target: [core, plugins] - postgres: ["13"] exclude: - build_type: annotations target: plugins - services: - postgres: - image: postgres:${{ matrix.postgres }} - ports: - - 5432:5432 - env: - POSTGRES_USER: discourse - POSTGRES_PASSWORD: discourse - POSTGRES_DB: discourse_test - options: >- - --mount type=tmpfs,destination=/var/lib/postgresql/data - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - steps: - uses: actions/checkout@master with: @@ -67,6 +49,12 @@ jobs: run: | redis-server /etc/redis/redis.conf & + - name: Start Postgres + run: | + chown -R postgres /var/run/postgresql + sudo -E -u postgres script/start_test_db.rb + sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';" + - name: Bundler cache uses: actions/cache@v2 with: diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake index 30f8675e9c..90bc68d040 100644 --- a/lib/tasks/docker.rake +++ b/lib/tasks/docker.rake @@ -102,16 +102,8 @@ task 'docker:test' do puts "Starting background redis" @redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis') - @postgres_bin = "/usr/lib/postgresql/#{ENV['PG_MAJOR']}/bin/" - `#{@postgres_bin}initdb -D tmp/test_data/pg` - - # speed up db, never do this in production mmmmk - `echo fsync = off >> tmp/test_data/pg/postgresql.conf` - `echo full_page_writes = off >> tmp/test_data/pg/postgresql.conf` - `echo shared_buffers = 500MB >> tmp/test_data/pg/postgresql.conf` - puts "Starting postgres" - @pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg") + @pg_pid = Process.spawn("script/start_test_db.rb --exec") ENV["RAILS_ENV"] = "test" # this shaves all the creation of the multisite db off diff --git a/script/start_test_db.rb b/script/start_test_db.rb new file mode 100755 index 0000000000..280a6347f2 --- /dev/null +++ b/script/start_test_db.rb @@ -0,0 +1,30 @@ +#!/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_exec = false +while a = ARGV.pop + if a == "--exec" + should_exec = true + else + raise "Unknown argument #{a}" + end +end + +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" + +if should_exec + exec "#{BIN}/postmaster -D #{DATA}" +else + run "#{BIN}/pg_ctl -D #{DATA} start" +end