Skip to content

Commit 8e5db5f

Browse files
committed
Setup postgres container on GitHub CI Actions
1 parent f8ed252 commit 8e5db5f

3 files changed

Lines changed: 44 additions & 11 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,39 @@ jobs:
1313
test:
1414
runs-on: ubuntu-latest
1515

16+
services:
17+
postgres:
18+
image: postgres:latest
19+
env:
20+
POSTGRES_USER: postgres
21+
POSTGRES_PASSWORD: postgres
22+
POSTGRES_HOST: localhost
23+
options: >-
24+
--health-cmd pg_isready
25+
--health-interval 10s
26+
--health-timeout 5s
27+
--health-retries 5
28+
ports:
29+
- 5432:5432
30+
1631
steps:
17-
- uses: actions/checkout@v4
32+
- name: Setup system dependencies
33+
run: sudo apt-get install -y libpq-dev postgresql-server-dev-16
34+
35+
# https://github.com/actions/checkout
36+
- uses: actions/checkout@v6
37+
1838
- name: Set up Ruby
1939
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
20-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
21-
# uses: ruby/setup-ruby@v1
40+
# use ruby/setup-ruby@v1. See https://github.com/ruby/setup-ruby
2241
uses: ruby/setup-ruby@v1
2342
with:
2443
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
44+
2545
- name: Run tests
2646
run: bundle exec rake spec
27-
47+
env:
48+
JUNETHACK_POSTGRES_USER: postgres
49+
JUNETHACK_POSTGRES_PASSWORD: postgres
50+
JUNETHACK_POSTGRES_HOST: localhost
51+
JUNETHACK_POSTGRES_DATABASE: postgres

config/database.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
development:
1+
production:
22
adapter: postgresql
3-
database: junethack-dev
3+
database: <%= ENV['JUNETHACK_POSTGRES_DATABASE'] || 'junethack' %>
4+
host: <%= ENV['JUNETHACK_POSTGRES_HOST'] || 'localhost' %>
5+
username: <%= ENV['JUNETHACK_POSTGRES_USER'] || 'junethack' %>
6+
password: <%= ENV['JUNETHACK_POSTGRES_PASSWORD'] || 'test' %>
47

5-
production:
8+
development:
69
adapter: postgresql
7-
database: junethack-prod
10+
database: <%= ENV['JUNETHACK_POSTGRES_DATABASE'] || 'junethack-dev' %>
11+
host: <%= ENV['JUNETHACK_POSTGRES_HOST'] || 'localhost' %>
12+
username: <%= ENV['JUNETHACK_POSTGRES_USER'] || 'junethack' %>
13+
password: <%= ENV['JUNETHACK_POSTGRES_PASSWORD'] || 'test' %>
814

915
test:
1016
adapter: postgresql
11-
database: junethack-test
12-
user: junethack
13-
password: junethack
17+
database: <%= ENV['JUNETHACK_POSTGRES_DATABASE'] || 'junethack-test' %>
18+
host: <%= ENV['JUNETHACK_POSTGRES_HOST'] || 'localhost' %>
19+
username: <%= ENV['JUNETHACK_POSTGRES_USER'] || 'junethack' %>
20+
password: <%= ENV['JUNETHACK_POSTGRES_PASSWORD'] || 'test' %>

lib/junethack/database.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
ActiveRecord.schema_format = :sql
1111

12+
Dir.mkdir('logs') unless File.exist?('logs')
13+
1214
configure :development do
1315
puts "Configuring development database"
1416
ActiveRecord::Base.logger = Logger.new("logs/dev_db.log")

0 commit comments

Comments
 (0)