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

WIP: Complete the Docker compose testing setup #147

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ FROM ruby:latest
RUN ruby --version

ENV BUNDLE_GEMFILE=/app/Gemfile.docker
RUN gem install bundler nokogiri
COPY Gemfile* *.gemspec /app/
RUN mkdir -p /app/lib/active_record_upsert
COPY lib/active_record_upsert/version.rb /app/lib/active_record_upsert/
WORKDIR /app
RUN bundle install
COPY . /app
CMD bin/run_docker_test.sh
CMD [ "bin/run_docker_test.sh" ]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


6 changes: 4 additions & 2 deletions Gemfile.docker
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'https://rubygems.org'
group :development, :test do
gem 'rails', '~> 8.0.0'
end

gemspec
eval_gemfile "#{__dir__}/Gemfile.base"
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
COMMAND ?= `grep 'web' Procfile | cut -d ':' -f2`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COMMAND ?= `grep 'web' Procfile | cut -d ':' -f2`

REVISION ?= `git rev-parse HEAD`

.PHONY: build_docker_image run

build_docker_image:
DOCKER_BUILDKIT=1 docker build \
--build-arg REVISION=$(REVISION) \
--progress=plain \
-t active_record_upsert .

run: build_docker_image
docker run -it active_record_upsert bin/run_docker_test.sh
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ task :setup_and_run_spec do |rake_task|

require File.expand_path('../spec/dummy/config/environment.rb', __FILE__)

if Rails.version >= '5.2.0'
if Rails.version >= '8.0.0'
ActiveRecord::Migrator.migrations_paths << 'spec/dummy/db/migrate'
elsif Rails.version >= '5.2.0'
ActiveRecord::Base.connection.migrations_paths << 'spec/dummy/db/migrate'
end

Expand Down
4 changes: 2 additions & 2 deletions bin/run_docker_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
pushd spec/dummy
DATABASE_URL=postgresql://localhost/upsert_test RAILS_ENV=test rails db:migrate
DATABASE_URL=postgresql://db/activerecord_upsert_test RAILS_ENV=test bundle exec rails db:setup db:migrate
popd
RAILS_ENV=test bundle exec rspec
DATABASE_URL=postgresql://db/activerecord_upsert_test RAILS_ENV=test bundle exec rspec
22 changes: 17 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
version: '2'
services:
db:
image: postgres:9.5
image: postgres:17.2
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
restart: always
ports:
- "5432:5432"
- 5432:5432
volumes:
- database_data:/var/lib/postgresql/data

app:
environment:
- DATABASE_URL=postgresql://postgres@db/active_record_upsert_test
- POSTGRES_HOST_AUTH_METHOD='trust'
- PGHOST='db'
- PGDATABASE='activerecord_upsert_test'
build: .
depends_on:
- db
links:
- db
- db

volumes:
database_data:
driver: local

1 change: 1 addition & 0 deletions spec/dummy/tmp/local_secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b8c94d1feb3f0a66ec0bd2a83f9c1c8f0b5e112f81f6c270a03f8a45a5158ba999121e4eee44b136de6655c1a37ecfa80b63fc35f37d80784cf36a02cc123cf6
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could go in the .gitignore I guess.

Loading