DEV: Use discourse image for postgres in GitHub Actions (#15291)
The discourse base image already contains a postgres installation, so pulling a separate postgres image is a little wasteful. Using the copy of Postgres in the discourse image saves about 20 seconds on every GitHub actions run. This commit sets up Postgres with a few performance-improving flags, which we were already using for the `rake docker:test` task (used on our internal CI system).
This commit is contained in:
parent
031f4f06d5
commit
0e87f882a7
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue