Skip to content

Commit

Permalink
feat: add support for anyway config (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque authored Oct 8, 2021
1 parent ef303b4 commit ee2f93d
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 692 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ RUN ln -s /pact_broker/script/db-version.sh /usr/local/bin/db-version

# Start Puma
ENV RACK_ENV=production
ENV PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME=PACT_BROKER_PORT
ENV PACT_BROKER_DATABASE_CLEAN_ENABLED=false
ENV PACT_BROKER_DATABASE_CLEAN_CRON_SCHEDULE="15 2 * * *"
ENV PACT_BROKER_DATABASE_CLEAN_KEEP_VERSION_SELECTORS='[{ "latest": true, "tag": true }, { "max_age": 90 }]'
ENV PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT=500
ENV PACT_BROKER_DATABASE_CLEAN_OVERWRITTEN_DATA_MAX_AGE=7
ENV PACT_BROKER_DATABASE_CLEAN_DRY_RUN=false
ENV PACT_BROKER_PORT=9292
USER ruby
ENTRYPOINT ["./entrypoint.sh"]
CMD ["config.ru"]
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
source 'https://rubygems.org'
instance_eval File.read("pact_broker/Gemfile")

gem 'rake', '~> 13.0'
gem 'conventional-changelog', git: 'https://github.com/bethesque/conventional-changelog-ruby.git', ref: 'feat/pact-foundation'
gem 'rspec', '~> 3.7'
gem 'rspec-its', '~> 1.2'
gem 'rack-test'
gem 'rack-test'
gem 'anyway_config', '~> 2.1'
194 changes: 180 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,44 +1,210 @@
GIT
remote: https://github.com/bethesque/conventional-changelog-ruby.git
revision: 303b4277a64371d01e43754dfd5f47eee42ccd79
revision: ca6b790c3c8079665dee6fe05685e4ab1be0ad6f
ref: feat/pact-foundation
specs:
conventional-changelog (1.3.0)

GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.3)
anyway_config (2.1.0)
ruby-next-core (>= 0.11.0)
as-notifications (1.0.2)
awesome_print (1.9.2)
concurrent-ruby (1.1.9)
crass (1.0.6)
declarative (0.0.20)
declarative-builder (0.1.0)
declarative-option (< 0.2.0)
declarative-option (0.1.0)
diff-lcs (1.4.4)
disposable (0.4.7)
declarative (>= 0.0.9, < 1.0.0)
declarative-builder (< 0.2.0)
declarative-option (< 0.2.0)
representable (>= 2.4.0, <= 3.1.0)
uber (< 0.2.0)
dry-configurable (0.12.1)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5.0)
dry-container (0.8.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.7.1)
concurrent-ruby (~> 1.0)
dry-equalizer (0.3.0)
dry-logic (0.4.2)
dry-container (~> 0.2, >= 0.2.6)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-types (0.10.3)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1)
dry-container (~> 0.3)
dry-core (~> 0.2, >= 0.2.1)
dry-equalizer (~> 0.2)
dry-logic (~> 0.4, >= 0.4.0)
inflecto (~> 0.0.0, >= 0.0.2)
dry-validation (0.10.7)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (~> 0.2, >= 0.2.1)
dry-equalizer (~> 0.2)
dry-logic (~> 0.4, >= 0.4.0)
dry-types (~> 0.9, >= 0.9.0)
expgen (0.1.1)
parslet
haml (5.2.2)
temple (>= 0.8.0)
tilt
httparty (0.20.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
inflecto (0.0.2)
json (2.5.1)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0901)
multi_json (1.15.0)
multi_xml (0.6.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
mysql2 (0.5.3)
nio4r (2.5.7)
nokogiri (1.12.5-x86_64-darwin)
racc (~> 1.4)
nokogumbo (2.0.5)
nokogiri (~> 1.8, >= 1.8.4)
pact-support (1.17.0)
awesome_print (~> 1.9)
diff-lcs (~> 1.4)
expgen (~> 0.1)
term-ansicolor (~> 1.0)
pact_broker (2.87.0)
anyway_config (~> 2.1)
dry-configurable (= 0.12.1)
dry-logic (= 0.4.2)
dry-types (~> 0.10.3)
dry-validation (~> 0.10.5)
haml (~> 5.0)
httparty (~> 0.14)
json (~> 2.3)
pact-support (~> 1.16, >= 1.16.4)
padrino-core (~> 0.14, >= 0.14.3)
rack (~> 2.2, >= 2.2.3)
rack-protection (>= 2.0.8.1, < 3.0)
redcarpet (~> 3.5, >= 3.5.1)
reform (~> 2.3.3)
request_store (~> 1.5)
roar (~> 1.1)
sanitize (~> 5.2, >= 5.2.1)
semantic_logger (~> 4.3)
semver2 (~> 3.4.2)
sequel (~> 5.28)
sinatra (>= 2.0.8.1, < 3.0)
sucker_punch (~> 2.0)
table_print (~> 1.5)
webmachine (= 1.6.0)
wisper (~> 2.0)
padrino-core (0.15.1)
padrino-support (= 0.15.1)
sinatra (>= 2.0.0)
thor (~> 1.0)
padrino-support (0.15.1)
parslet (2.0.0)
pg (1.2.3)
puma (5.3.2)
nio4r (~> 2.0)
racc (1.5.2)
rack (2.2.3)
rack-protection (2.1.0)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (13.0.1)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
rake (13.0.6)
redcarpet (3.5.1)
reform (2.3.3)
disposable (>= 0.4.2, < 0.5.0)
representable (>= 2.4.0, < 3.1.0)
uber (< 0.2.0)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
request_store (1.5.0)
rack (>= 1.4)
roar (1.1.0)
representable (~> 3.0.0)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (~> 3.10.0)
rspec-its (1.3.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.8.1)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
ruby-next-core (0.12.0)
ruby2_keywords (0.0.5)
sanitize (5.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.8.0)
nokogumbo (~> 2.0)
semantic_logger (4.8.2)
concurrent-ruby (~> 1.0)
semver2 (3.4.2)
sequel (5.49.0)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
sqlite3 (1.4.2)
sucker_punch (2.1.2)
concurrent-ruby (~> 1.0)
sync (0.5.0)
table_print (1.5.7)
temple (0.8.2)
term-ansicolor (1.7.1)
tins (~> 1.0)
thor (1.1.0)
tilt (2.0.10)
tins (1.29.1)
sync
uber (0.1.0)
webmachine (1.6.0)
as-notifications (~> 1.0)
i18n (>= 0.4.0)
multi_json
webrick (1.7.0)
wisper (2.0.1)

PLATFORMS
ruby

DEPENDENCIES
anyway_config (~> 2.1)
conventional-changelog!
mysql2 (~> 0.3)
pact_broker
pg (~> 1.0)
puma (~> 5.3)
rack-test
rake (~> 13.0)
rspec (~> 3.7)
rspec-its (~> 1.2)
sqlite3 (~> 1.3)
webrick (~> 1.6)

BUNDLED WITH
2.1.4
53 changes: 13 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ If you want to run the container as a standalone instance, then the `dius/pact-b

## Prerequisites

* A running Postgresql (or MySQL) database and the ability to connect to it (see [POSTGRESQL.md][postgres]). Postgres is recommended over MySQL for performance and support reasons.
* A running Postgresql database and the ability to connect to it (see [POSTGRESQL.md][postgres]).

## Getting Started

1. [Install Docker][docker]
2. Prepare your environment if you are not running postgresql in a docker container. Setup the pact broker connection to the database through the use of the following environment variables.
2. Create a Postgres database.
2. Setup the Pact Broker connection to the database using the environment variables described below.

### Create the database

Expand Down Expand Up @@ -59,45 +60,27 @@ For investigations/spikes you can use SQlite. It is not supported as a productio
* `PACT_BROKER_DATABASE_ADAPTER` (set to `sqlite`)
* `PACT_BROKER_DATABASE_NAME` (arbitrary file in the `/tmp` directory eg. `/tmp/pact_broker.sqlite3`)

You can additionally set:

* `PACT_BROKER_DATABASE_SSLMODE` - optional, possible values: 'disable', 'allow', 'prefer', 'require', 'verify-ca', or 'verify-full' to choose how to treat SSL (only respected if using the postgres database adapter. See https://www.postgresql.org/docs/9.1/libpq-ssl.html for more information.)
* `PACT_BROKER_SQL_LOG_LEVEL` - optional, defaults to debug. The level at which to log SQL statements. Valid options are none, debug, info, warn.
* `PACT_BROKER_SQL_LOG_WARN_DURATION` - optional, defaults to 5 seconds. Log the SQL for queries that take longer than this number of seconds.
* `PACT_BROKER_DATABASE_MAX_CONNECTIONS` - optional, defaults to 4. The maximum size of the connection pool. There is no need to set this unless you notice particular connection contention issues.
* `PACT_BROKER_DATABASE_POOL_TIMEOUT` - optional, 5 seconds by default. The number of seconds to wait if a connection cannot be acquired before raising an error. There is no need to set this unless you notice particular connection contention issues.
* `PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES` - optional, defaults to 0. When running the Pact Broker Docker image experimentally using Docker Compose on a local development machine, the Broker application process may be ready before the database is available for connection, causing the application container to exit with an error. Setting the max retries to a non-zero number will allow it to retry the connection the configured number of times, waiting 3 seconds between attempts.
See the [database section](https://docs.pact.io/pact_broker/configuration/settings/#database) of the Pact Broker configuration docs for all the database configuration options available.

## Notes

* The application makes use of the Puma application server.
* Apart from creating a database no further preparation is required.
* The image does not need root privileges to run, however, the root filesystem (or at least, the /tmp directory) must be writeable for Puma to temporarily store files when processing large requests. See this [issue](https://github.com/pact-foundation/pact-js/issues/583#issuecomment-777728677).

## Using basic auth

To enable basic auth, run your container with:
## Authentication

* `PACT_BROKER_BASIC_AUTH_USERNAME`
* `PACT_BROKER_BASIC_AUTH_PASSWORD`
* `PACT_BROKER_BASIC_AUTH_READ_ONLY_USERNAME`
* `PACT_BROKER_BASIC_AUTH_READ_ONLY_PASSWORD`
The Pact Broker comes with 2 configurable basic auth users - one with read/write privileges, and one with read only privileges. The read only credentials should be distributed to the developers for use from development machines, and the read/write credentials should be used for CI/CD.

If you want to allow public read access (but still require credentials for writing), then omit setting the READ_ONLY credentials and set `PACT_BROKER_ALLOW_PUBLIC_READ=true`.

Developers should use the read only credentials on their local machines, and the CI should use the read/write credentials. This will ensure that pacts and verification results are only published from your CI.
See the [Authentication and authorization](https://docs.pact.io/pact_broker/configuration/settings#authentication-and-authorization) section of the Pact Broker documentation for more details.

Note that the [verification status badges][badges] are not protected by basic auth, so that you may embed them in README markdown.

## Heartbeat URL

If you are using the docker container within an AWS autoscaling group, and you need to make a heartbeat URL publicly available, set `PACT_BROKER_PUBLIC_HEARTBEAT=true`. No database connection will be made during the execution of this endpoint.
## Heartbeat/Healthcheck URL

The heartbeat is available at `/diagnostic/status/heartbeat`.
The heartbeat is available at `/diagnostic/status/heartbeat`. No database connection will be made during the execution of this endpoint.

## Healthcheck URL

See [Heartbeat URL](#heartbeat-url).
If you have enabled basic auth, and you are running the Pact Broker within an AWS autoscaling group or similar and you need to make a heartbeat URL publicly available, set `PACT_BROKER_PUBLIC_HEARTBEAT=true`.

## Using SSL

Expand All @@ -109,26 +92,16 @@ Set the environment variable `PACT_BROKER_LOG_LEVEL` to one of `DEBUG`, `INFO`,

## Webhooks

### Webhook whitelists

* `PACT_BROKER_WEBHOOK_HOST_WHITELIST` - a space delimited list of hosts (eg. `github.com travis.org`), network ranges (eg. `10.2.3.41/24`, or regular expressions (eg. `/.*\\.foo\\.com$/`). Regular expressions should start and end with a `/` to differentiate them from Strings. Note that backslashes need to be escaped with a second backslash. Please read the [Webhook whitelists][webhook-whitelist] section of the Pact Broker configuration documentation to understand how the whitelist is used. Remember to use quotes around this value as it may have spaces in it.
* `PACT_BROKER_WEBHOOK_SCHEME_WHITELIST` - a space delimited list (eg. `http https`). Defaults to `https`.
See the [Webhooks](https://docs.pact.io/pact_broker/configuration/features#webhooks) section of the Pact Broker documentation. The only setting that you need to customize is the [`webhook_host_whitelist`](https://docs.pact.io/pact_broker/configuration/settings#webhook_host_whitelist).

## Other webhook settings
## Other settings

* `PACT_BROKER_WEBHOOK_RETRY_SCHEDULE` - a space delimited list of integers specifying the number of seconds after which to retry webhook requests when they fail. Defaults to `10 60 120 300 600 1200`. This does not normally need to be changed.
* `PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS` - a space delimited list of successful http codes (e.g. `200 201 301`). Defaults to `200 201 202 203 204 205 206`. If webhook call returns the response with http code that is listed in the success codes then the operation is considered as a success, otherwise the webhook will be re-triggered based on `PACT_BROKER_WEBHOOK_RETRY_SCHEDULE` configuration. In most cases, configuring this is not necessary, but there are some CI systems that return a non 200 status for a success, which is why this feature exists.

## Other environment variables
See the [Pact Broker Configuration Settings](https://docs.pact.io/pact_broker/configuration/settings) page for a full list of available settings.

* `PACT_BROKER_PORT` - the port that the Pact Broker application runs on. Defaults to 9292.
* `PACT_BROKER_BASE_URL` - optional but *strongly recommended* when deploying the Pact Broker to production as it prevents some [security vulnerabilities](https://www.cloudflare.com/learning/dns/dns-cache-poisoning/). If you find that the URLs generated by the API are using an IP instead of a hostname, you can set this environment variable to force the desired base URL. Must include the port if it's a non-standard one. eg. `https://my-broker:9292`. This can also be used if you are mounting the Docker container so that it runs on a non root context eg. `https://my-company.com/pact-broker`. Not that this setting does not change where the application is mounted within the Docker container - it just changes the links.
* `PACT_BROKER_DISABLE_SSL_VERIFICATION` - `false` by default, may be set to `true`.
* `PACT_BROKER_BASE_EQUALITY_ONLY_ON_CONTENT_THAT_AFFECTS_VERIFICATION_RESULTS` - `true` by default, may be set to `false`.
* `PACT_BROKER_ORDER_VERSIONS_BY_DATE` - `true` by default. Setting this to false is deprecated.
* `PACT_BROKER_PUMA_PERSISTENT_TIMEOUT` - allows configuration of the Puma persistent timeout.


## General Pact Broker configuration and usage

Documentation for the Pact Broker application itself can be found in the Pact Broker [docs][pact-broker-docs].
Expand Down
9 changes: 6 additions & 3 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
depends_on:
- postgres
environment:
PACT_BROKER_CONF: /tmp/pact_broker.yml
PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME: PORT
PACT_BROKER_DATABASE_URL_ENVIRONMENT_VARIABLE_NAME: DATABASE_URL
DATABASE_URL: "postgres://postgres:password@postgres/postgres"
Expand All @@ -41,6 +42,8 @@ services:
# PACT_BROKER_DATABASE_NAME: postgres
# PACT_BROKER_PORT: "9292"
PORT: '9393'
PACT_BROKER_LOG_LEVEL: INFO
PACT_BROKER_SQL_LOG_LEVEL: DEBUG
PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "5"
# PACT_BROKER_LOG_LEVEL: DEBUG
# PACT_BROKER_SQL_LOG_LEVEL: NONE
# PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "5"
volumes:
- ./docker/config/pact_broker.yml:/tmp/pact_broker.yml
12 changes: 12 additions & 0 deletions docker-compose-with-conf-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3"

services:
pact-broker:
# image: pactfoundation/pact-broker:2.86.0.1
build: .
ports:
- "9292:9292"
environment:
PACT_BROKER_CONF: /tmp/pact_broker.yml
volumes:
- ./docker/config/pact_broker.yml:/tmp/pact_broker.yml
3 changes: 3 additions & 0 deletions docker/config/pact_broker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
log_format: color
database_url: sqlite:////tmp/pact_broker.sqlite3
base_url: 'https://localhost http://localhost http://localhost:9292 http://pact-broker:9292'
Loading

0 comments on commit ee2f93d

Please sign in to comment.