Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setup for using docker compose to run a local database #93

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
COVERAGE: "${{matrix.coverage}}"
COVERAGE_TOKEN: "${{secrets.CODACY_PROJECT_TOKEN}}"
APT_DEPS: libpq-dev libmysqlclient-dev libsqlite3-dev
DATABASE_URL: "postgres://runner:@localhost:5432/rom_factory"
steps:
- name: Checkout
uses: actions/checkout@v1
Expand Down
4 changes: 4 additions & 0 deletions .postgres.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POSTGRES_USER="rom"
POSTGRES_PASSWORD="password"
POSTGRES_DATABASE="rom_factory"
POSTGRES_HOST_AUTH_METHOD="trust"
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ gem "faker", "~> 3.0"

gem "rspec", "~> 3.0"

gem "dotenv"

git "https://github.com/rom-rb/rom.git", branch: "release-5.3" do
gem "rom-core"
gem "rom"
gem "rom-changeset"
gem "rom-core"
gem "rom-repository"
gem "rom"
end

group :test do
Expand Down
7 changes: 7 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
services:
db:
image: postgres
ports:
- 5432
env_file: .postgres.env
12 changes: 10 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require_relative "support/coverage"
require "dotenv"
Dotenv.load(".postgres.env", ".env")

require "pathname"
SPEC_ROOT = root = Pathname(__FILE__).dirname
Expand All @@ -18,10 +20,16 @@
end

DB_URI = ENV.fetch("DATABASE_URL") do
auth = ENV.values_at("POSTGRES_USER", "POSTGRES_PASSWORD").join(":")
address = `docker compose port db 5432 2> /dev/null`.strip
address = [auth, address].join("@") if address

address ||= "localhost"

if defined? JRUBY_VERSION
"jdbc:postgresql://localhost/rom_factory"
"jdbc:postgresql://#{address}"
else
"postgres://localhost/rom_factory"
"postgres://#{address}"
end
end

Expand Down
Loading