Skip to content

Commit

Permalink
chore: use gem groups instead of hacky env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 4, 2023
1 parent c61c324 commit 662398c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 22 deletions.
20 changes: 16 additions & 4 deletions DEVELOPER_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ This allows you to open a shell to a development environment where you can run t
* Spin up a container with mounted volume and open an interactive shell session

```sh
docker run --rm -v $(PWD):/home -w /home -it pact_broker:dev bash
docker run --rm \
-v $(PWD)/config:/home/config \
-v $(PWD)/db:/home/db \
-v $(PWD)/docs:/home/docs \
-v $(PWD)/lib:/home/lib \
-v $(PWD)/public:/home/public \
-v $(PWD)/spec:/home/spec \
-v $(PWD)/tasks:/home/tasks \
-v $(PWD)/vendor:/home/vendor \
-v $(PWD)/Rakefile:/home/Rakefile \
-v $(PWD)/.rspec:/home/.rspec \
-w /home -it pact_broker:dev bash
```
We can't just mount the whole $(PWD) directory because the local Gemfile.lock and .bundle/config will override the ones in the image
Remember to rebuild the image if you change any of the gems or gem versions.
Expand All @@ -41,15 +53,15 @@ Remember to rebuild the image if you change any of the gems or gem versions.
* Check out the pact_broker repository and cd into it.
* Run `bundle install`. If you have any gem conflict issues, run `bundle update`.
To make the barrier to entry as low as possible, the mysql2 and pg gems are not installed by default, as they require mysql and postgres to be installed on your local machine. If you want to install them, set `INSTALL_MYSQL=true` and/or `INSTALL_PG=true` before running `bundle install`.
To make the barrier to entry as low as possible, the mysql2 and pg gems are not installed by default, as they require mysql and postgres to be installed on your local machine. If you want to install them, run `bundle config set --local with pg mysql` before running `bundle install`.
## Running a local application
* Install Ruby and the gems as per the instructions above.
* Run `bundle exec rackup`.
* The application will be available on `http://localhost:9292`. It uses a sqlite database that is stored in the `./tmp` directory.
You can set the `PACT_BROKER_DATABASE_URL` environment variable to use a postgres/mysql database using the format `driver://username:password@host:port/database` eg. `postgres://pact_broker:password@localhost/pact_broker`. Ensure you have set `INSTALL_MYSQL=true` or `INSTALL_PG=true` and run `bundle install` to make sure the required gems are present.
You can set the `PACT_BROKER_DATABASE_URL` environment variable to use a postgres/mysql database using the format `driver://username:password@host:port/database` eg. `postgres://pact_broker:password@localhost/pact_broker`. Ensure you have run `bundle config set --local with pg mysql` and run `bundle install` to make sure the required gems are present.
## Listing the routes
Expand Down Expand Up @@ -118,7 +130,7 @@ The tests and files are stored in the [regression](regression) directory.

To run:

1. Set up your local development environment as described above, making sure you have `INSTALL_PG=true` exported in your shell.
1. Set up your local development environment as described above, making sure you have run `bundle config set --local with pg; bundle install`.

1. Make sure you have the master branch checked out.

Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ FROM ruby:3.2.1-alpine3.17

WORKDIR /home

ENV INSTALL_MYSQL=true
ENV INSTALL_PG=true
RUN apk update \
&& apk --no-cache add \
"build-base>=0.5" \
Expand All @@ -28,13 +26,14 @@ RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz


# lock file does not exist on CI
COPY Gemfile /home/Gemfile
# COPY Gemfile.lock /home/Gemfile.lock # lock file does not exist on CI
COPY pact_broker.gemspec /home/pact_broker.gemspec
COPY lib/pact_broker/version.rb /home/lib/pact_broker/version.rb
COPY .gitignore /home/.gitignore

RUN gem install bundler -v '~>2.0.0' \
&& bundle config set --local with pg mysql \
&& bundle install --jobs 3 --retry 3

RUN echo '#!/bin/sh' >> /usr/local/bin/start
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ group :test do
gem "faraday-retry", "~>2.0"
end

if ENV["INSTALL_MYSQL"] == "true"
gem "mysql2", "~>0.5"
group :pg, optional: true do
gem "pg", "~>1.2"
end

if ENV["INSTALL_PG"] == "true"
gem "pg", "~>1.2"
group :mysql, optional: true do
gem "mysql2", "~>0.5"
end

if ENV["X_PACT_DEVELOPMENT"] == "true"
Expand Down
1 change: 0 additions & 1 deletion docker-compose-ci-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ services:
environment:
DATABASE_ADAPTER: docker_compose_mysql
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
INSTALL_MYSQL: 'true'
volumes:
- ./lib:/home/lib
- ./spec:/home/spec
Expand Down
1 change: 0 additions & 1 deletion docker-compose-ci-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ services:
environment:
PACT_BROKER_TEST_DATABASE_URL: postgres://postgres:postgres@postgres/postgres
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
INSTALL_PG: 'true'
volumes:
- ./lib:/home/lib
- ./spec:/home/spec
Expand Down
5 changes: 0 additions & 5 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ services:
environment:
DATABASE_ADAPTER: docker_compose_postgres
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
INSTALL_PG: 'true'
volumes:
- ./lib:/home/lib
- ./db:/home/db
Expand All @@ -36,7 +35,6 @@ services:
environment:
DATABASE_ADAPTER: docker_compose_postgres
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
INSTALL_PG: 'true'
volumes:
- ./lib:/home/lib
- ./spec:/home/spec
Expand Down Expand Up @@ -70,7 +68,6 @@ services:
environment:
DATABASE_ADAPTER: docker_compose_mysql
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
INSTALL_MYSQL: 'true'
volumes:
- ./lib:/home/lib
- ./db:/home/db
Expand All @@ -86,7 +83,6 @@ services:
environment:
DATABASE_ADAPTER: docker_compose_mysql
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
INSTALL_MYSQL: 'true'
volumes:
- ./lib:/home/lib
- ./spec:/home/spec
Expand All @@ -105,7 +101,6 @@ services:
build: .
environment:
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
INSTALL_MYSQL: 'true'
volumes:
- ./lib:/home/lib
- ./spec:/home/spec
Expand Down
1 change: 0 additions & 1 deletion regression/regression_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
raise "Must set INSTALL_PG=true" unless ENV["INSTALL_PG"] == "true"
raise "Must set DATABASE_ADAPTER=docker_postgres" unless ENV["DATABASE_ADAPTER"] == "docker_postgres"
raise "Must set RACK_ENV=development" unless ENV["RACK_ENV"] == "development"

Expand Down
2 changes: 1 addition & 1 deletion regression/script/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#/bin/sh

REGRESSION=true INSTALL_PG=true DATABASE_ADAPTER=docker_postgres RACK_ENV=development bundle exec rake regression
REGRESSION=true DATABASE_ADAPTER=docker_postgres RACK_ENV=development bundle exec rake regression
5 changes: 3 additions & 2 deletions tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ namespace :db do

desc "Annotate the Sequel domain classes with schema information.
Start the postgres db with script/docker/db-start.sh first and run
INSTALL_PG=true bundle exec rake db:annotate
bundle config set --local with pg
bundle install
bundle exec rake db:annotate
"
task :annotate do
begin
raise "Need to set INSTALL_PG=true" unless ENV["INSTALL_PG"] == "true"
ENV["RACK_ENV"] = "test"
ENV["DATABASE_ADAPTER"] = "docker_postgres"
load "#{__dir__}/../spec/support/test_database.rb"
Expand Down

0 comments on commit 662398c

Please sign in to comment.