Skip to content

Commit 8006912

Browse files
committed
chore: update developer setup instructions
1 parent 9b451ee commit 8006912

5 files changed

+148
-30
lines changed

DEVELOPER_SETUP.md

+29-16
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,48 @@
22

33
## Preparation
44

5-
### With virtual battery
5+
### With Docker Compose
6+
7+
The following command runs the application from the source code and binds it to port 9292 of your host.
8+
9+
```sh
10+
docker-compose -f docker-compose-dev-postgres.yml up --build
11+
```
12+
13+
### With Docker
14+
15+
This allows you to open a shell to a development environment where you can run the tests and rake tasts.
616

717
* Build an initial local image with Docker
8-
```sh
9-
docker build --rm -t pact_broker:dev .
10-
```
18+
19+
```sh
20+
docker build --rm -t pact_broker:dev .
21+
```
1122

1223
* Spin up a container with mounted volume and open an interactive shell session
13-
```sh
14-
docker run --rm -v $(PWD):/app -w /app -it pact_broker:dev bash
15-
```
24+
25+
```sh
26+
docker run --rm -v $(PWD):/home -w /home -it pact_broker:dev bash
27+
```
28+
29+
Remember to rebuild the image if you change any of the gems or gem versions.
1630

1731
### With native install
1832

1933
* You will need to install Ruby 2.5, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
2034
* Install bundler (the Ruby gem dependency manager) `gem install bundler`
2135
* Check out the pact_broker repository and cd into it.
22-
* Run `bundle install`. If you have not got mysql or postgres installed locally, comment out the `mysql2` and `pg` development dependency lines in `pact_broker.gemspec`, as these are only really required on Travis.
36+
* Run `bundle install`. If you have any gem conflict issues, run `bundle update`.
37+
38+
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`.
2339

2440
## Running a local application
2541

26-
* Run `bundle exec rake pact_broker:dev:setup`. This will create an example application that you can run locally, that uses the local source code.
27-
* To run the example:
28-
```sh
29-
cd dev
30-
bundle install
31-
bundle exec rackup
32-
```
33-
* The application will be available on `http://localhost:9292`
42+
* Install Ruby and the gems as per the instructions above.
43+
* Run `bundle exec rackup`.
44+
* The application will be available on `http://localhost:9292`. It uses a sqlite database that is stored in the `./tmp` directory.
45+
46+
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.
3447

3548
## Running the tests
3649

Dockerfile

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
FROM ruby:2.5.3-alpine
22

3+
WORKDIR /home
4+
35
ENV INSTALL_MYSQL=true
6+
ENV INSTALL_PG=true
47
RUN apk update \
58
&& apk --no-cache add \
69
"build-base>=0.5" \
@@ -14,11 +17,24 @@ RUN apk update \
1417
"mariadb-dev>=10.3" \
1518
&& rm -rf /var/cache/apk/*
1619

17-
WORKDIR /app
20+
RUN apk add --no-cache openssl
21+
22+
ENV DOCKERIZE_VERSION v0.6.1
23+
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
24+
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
25+
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
1826

19-
COPY . ./
27+
28+
COPY Gemfile /home/Gemfile
29+
COPY pact_broker.gemspec /home/pact_broker.gemspec
30+
COPY lib/pact_broker/version.rb /home/lib/pact_broker/version.rb
31+
COPY .gitignore /home/.gitignore
2032

2133
RUN gem install bundler -v '~>2.0.0' \
2234
&& bundle install --jobs 3 --retry 3
2335

36+
RUN echo '#!/bin/sh' >> /home/start.sh
37+
RUN echo 'bundle exec rackup -o 0.0.0.0 -p 9292' >> /home/start.sh
38+
RUN chmod +x /home/start.sh
39+
2440
CMD []

config.ru

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
require File.dirname(__FILE__) + '/config/boot'
2-
require 'db'
3-
require 'pact_broker/api'
4-
require 'rack/hal_browser'
5-
require 'pact_broker/ui/controllers/index'
1+
require 'fileutils'
2+
require 'logger'
3+
require 'sequel'
4+
require 'pg' # for postgres
5+
require 'pact_broker'
66

7+
FileUtils.mkdir_p('tmp') unless ENV['PACT_BROKER_DATABASE_URL']
78

8-
use Rack::Static, :urls => ["/stylesheets", "/css", "/fonts", "/js", "/javascripts", "/images"], :root => "public"
9-
use Rack::HalBrowser::Redirect, :exclude => ['/diagnostic', '/trace','/index']
9+
DATABASE_URL = ENV['PACT_BROKER_DATABASE_URL'] || 'sqlite://tmp/pact_broker_database.sqlite3'
10+
DB_OPTIONS = { encoding: 'utf8', sql_log_level: :debug }
1011

11-
run Rack::URLMap.new(
12-
'/ui/relationships' => PactBroker::UI::Controllers::Index,
13-
'/network-graph' => Rack::File.new("#{File.dirname(__FILE__)}/public/Network Graph REA.html"),
14-
'/' => PactBroker::API,
15-
)
12+
ENV['TZ'] = 'Australia/Melbourne'
13+
14+
SemanticLogger.add_appender(io: $stderr)
15+
SemanticLogger.default_level = :info
16+
17+
app = PactBroker::App.new do | config |
18+
# config.logger.level = ::Logger::INFO
19+
config.auto_migrate_db = true
20+
config.enable_public_badge_access = true
21+
config.order_versions_by_date = true
22+
config.allow_missing_migration_files = true
23+
config.base_equality_only_on_content_that_affects_verification_results = true
24+
config.badge_provider_mode = :redirect
25+
26+
config.webhook_retry_schedule = [3, 3, 3]
27+
config.webhook_host_whitelist = [/.*/, "10.0.0.0/8"]
28+
config.webhook_scheme_whitelist = ['http', 'https']
29+
config.webhook_http_method_whitelist = ['GET', 'POST']
30+
#config.base_url = ENV['PACT_BROKER_BASE_URL']
31+
32+
database_logger = PactBroker::DB::LogQuietener.new(config.logger)
33+
config.database_connection = Sequel.connect(DATABASE_URL, DB_OPTIONS.merge(logger: database_logger))
34+
end
35+
36+
run app

docker-compose-dev-postgres.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: "3"
2+
3+
services:
4+
postgres:
5+
image: postgres
6+
healthcheck:
7+
test: psql postgres --command "select 1" -U postgres
8+
ports:
9+
- "5432:5432"
10+
environment:
11+
POSTGRES_USER: postgres
12+
POSTGRES_PASSWORD: postgres
13+
POSTGRES_DB: postgres
14+
volumes:
15+
- postgres-volume:/var/lib/postgresql/data
16+
17+
pact-broker:
18+
build: .
19+
ports:
20+
- "9292:9292"
21+
depends_on:
22+
- postgres
23+
environment:
24+
DATABASE_URL: postgres://postgres:postgres@postgres/postgres
25+
PACT_BROKER_HIDE_PACTFLOW_MESSAGES: 'true'
26+
command: dockerize -wait tcp://postgres:5432 /home/start.sh
27+
volumes:
28+
- ./lib:/home/lib
29+
- ./db:/home/db
30+
- ./config.ru:/home/config.ru
31+
- ./tasks:/home/tasks
32+
- ./Rakefile:/home/Rakefile
33+
34+
volumes:
35+
postgres-volume:

docker-compose-test-mysql.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This doesn't work yet
2+
version: "3"
3+
4+
services:
5+
tests:
6+
build: .
7+
command: sh -c "sleep 10 && bundle exec rake db:prepare:test && bundle exec rspec spec/lib/pact_broker/domain/version_spec.rb"
8+
depends_on:
9+
- mysql
10+
environment:
11+
RACK_ENV: test
12+
DATABASE_ADAPTER: docker_compose_mysql
13+
PACT_BROKER_DATABASE_USERNAME: pact_broker
14+
PACT_BROKER_DATABASE_PASSWORD: pact_broker
15+
PACT_BROKER_DATABASE_HOST: pact_broker
16+
PACT_BROKER_DATABASE_NAME: pact_broker
17+
PACT_BROKER_BASIC_AUTH_USERNAME: pact_broker
18+
PACT_BROKER_BASIC_AUTH_PASSWORD: pact_broker
19+
PACT_BROKER_PORT: "9292"
20+
volumes:
21+
- ${PWD}:/app
22+
23+
mysql:
24+
image: mysql:5.7.28
25+
command: --default-authentication-plugin=mysql_native_password
26+
# restart: always
27+
environment:
28+
MYSQL_ROOT_PASSWORD: pact_broker
29+
MYSQL_DATABASE: pact_broker
30+
MYSQL_USER: pact_broker
31+
MYSQL_PASSWORD: pact_broker
32+
ports:
33+
- "3306:3306"

0 commit comments

Comments
 (0)