Skip to content

Commit

Permalink
feat: add support for configuration with YAML file (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque authored Oct 8, 2021
1 parent 7ed4a3d commit 59d23d9
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 963 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build Docker image

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.4

- name: Build image
run: script/build-workflow/run.sh
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
CUSTOM_TAG: ${{ github.event.client_payload.tag }}

- name: Integration tests
run: script/test.sh
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
FROM phusion/passenger-ruby27:1.0.12

# Update OS as per https://github.com/phusion/passenger-docker#upgrading-the-operating-system-inside-the-container
RUN apt-get update && \
apt-get upgrade -y -o Dpkg::Options::="--force-confold" && \
apt-get -qy autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Broken update https://github.com/DiUS/pact_broker-docker/runs/3799650621?check_suite_focus=true#step:9:87
# RUN apt-get update && \
# apt-get upgrade -y -o Dpkg::Options::="--force-confold" && \
# apt-get -qy autoremove && \
# apt-get clean && \
# rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN bash -lc 'rvm --default use ruby-2.7.2'

Expand Down
5 changes: 5 additions & 0 deletions demo/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

echo "sleeping 5"
sleep 5
/pact/entrypoint.sh broker publish /pacts --consumer-app-version 1 --tag "feat/foo" --verbose
1 change: 1 addition & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ services:
PACT_BROKER_DATABASE_HOST: postgres
PACT_BROKER_DATABASE_NAME: postgres
PACT_BROKER_LOG_LEVEL: INFO
PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "10"
ports:
- "80:80"
4 changes: 1 addition & 3 deletions docker-compose-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ services:
PACT_BROKER_BASIC_AUTH_USERNAME: "${PACT_BROKER_BASIC_AUTH_USERNAME:-}"
PACT_BROKER_BASIC_AUTH_PASSWORD: "${PACT_BROKER_BASIC_AUTH_PASSWORD:-}"
PACT_BROKER_PUBLIC_HEARTBEAT: "${PACT_BROKER_PUBLIC_HEARTBEAT:-false}"
entrypoint: /custom-entrypoint.sh
volumes:
- ./script/docker/docker-compose-entrypoint.sh:/custom-entrypoint.sh
PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "10"

sut:
build:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
PACT_BROKER_DATABASE_HOST: postgres
PACT_BROKER_DATABASE_NAME: postgres
PACT_BROKER_LOG_LEVEL: INFO
PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "10"
# If you remove nginx, enable the following
# ports:
# - "80:80"
Expand Down
54 changes: 43 additions & 11 deletions pact_broker/Rakefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
require_relative 'database_connection'
require 'logger'
require 'pact_broker/tasks'
require_relative "docker_configuration"
require "pact_broker/configuration"
require "pact_broker/initializers/database_connection"
require "pact_broker/tasks"

def create_database_configuration
PactBroker.configuration.runtime_configuration = PactBroker.docker_configuration
PactBroker.create_database_connection(PactBroker.configuration.database_configuration, PactBroker.configuration.logger)
end

def env(name)
ENV[name] && ENV[name] != '' ? ENV[name] : nil
end

PactBroker::DB::MigrationTask.new do | task |
task.database_connection = create_database_connection(Logger.new($stdout))
task.database_connection = create_database_configuration
end

PactBroker::DB::VersionTask.new do | task |
task.database_connection = create_database_connection(Logger.new($stdout))
task.database_connection = create_database_configuration
end

PactBroker::DB::CleanTask.new do | task |
task.database_connection = create_database_connection(Logger.new($stdout))
task.database_connection = create_database_configuration
task.logger = PactBroker.configuration.logger

if env('PACT_BROKER_DATABASE_CLEAN_KEEP_VERSION_SELECTORS')
require 'json'
task.keep_version_selectors = JSON.parse(env('PACT_BROKER_DATABASE_CLEAN_KEEP_VERSION_SELECTORS'))
end

if env('PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT')
task.version_deletion_limit = env('PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT').to_i
end

if env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN')
task.dry_run = env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN') == 'true'
end
end

PactBroker::DB::DeleteOverwrittenDataTask.new do | task |
task.database_connection = create_database_connection(Logger.new($stdout))
if ENV['PACT_BROKER_DELETE_OVERWRITTEN_DATA_AGE']
task.age_in_days = ENV['PACT_BROKER_DELETE_OVERWRITTEN_DATA_AGE'].to_i
else
task.age_in_days = 30
task.database_connection = create_database_configuration
task.logger = PactBroker.configuration.logger

if env('PACT_BROKER_DATABASE_CLEAN_OVERWRITTEN_DATA_MAX_AGE')
task.max_age = env('PACT_BROKER_DATABASE_CLEAN_OVERWRITTEN_DATA_MAX_AGE').to_i
end

if env('PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT')
task.deletion_limit = env('PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT').to_i
end

if env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN')
task.dry_run = env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN') == 'true'
end
end
54 changes: 0 additions & 54 deletions pact_broker/basic_auth.rb

This file was deleted.

45 changes: 5 additions & 40 deletions pact_broker/config.ru
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
require 'sequel'
require 'pact_broker'
require_relative 'logger'
require_relative 'basic_auth'
require_relative 'database_connection'
require_relative 'passenger_config'
require_relative 'docker_configuration'

dc = PactBroker::DockerConfiguration.new(ENV, PactBroker::Configuration.default_configuration)
dc.pact_broker_environment_variables.each{ |key, value| $logger.info "#{key}=#{value}"}
require_relative "passenger_config"
require_relative "docker_configuration"
require "pact_broker"

app = PactBroker::App.new do | config |
config.logger = $logger
config.database_connection = create_database_connection_from_config(config.logger, dc.database_configuration)
config.database_connection.timezone = :utc
config.base_url = dc.base_url
config.webhook_host_whitelist = dc.webhook_host_whitelist
config.webhook_http_method_whitelist = dc.webhook_http_method_whitelist
config.webhook_scheme_whitelist = dc.webhook_scheme_whitelist
config.base_equality_only_on_content_that_affects_verification_results = dc.base_equality_only_on_content_that_affects_verification_results
config.order_versions_by_date = dc.order_versions_by_date
config.disable_ssl_verification = dc.disable_ssl_verification
end

PactBroker.configuration.log_configuration

basic_auth_username = ENV.fetch('PACT_BROKER_BASIC_AUTH_USERNAME','')
basic_auth_password = ENV.fetch('PACT_BROKER_BASIC_AUTH_PASSWORD', '')
basic_auth_read_only_username = ENV['PACT_BROKER_BASIC_AUTH_READ_ONLY_USERNAME']
basic_auth_read_only_password = ENV['PACT_BROKER_BASIC_AUTH_READ_ONLY_PASSWORD']
allow_public_read_access = ENV.fetch('PACT_BROKER_ALLOW_PUBLIC_READ', '') == 'true'
allow_public_access_to_heartbeat = ENV.fetch('PACT_BROKER_PUBLIC_HEARTBEAT', '') == 'true'
use_basic_auth = basic_auth_username != '' && basic_auth_password != ''


if use_basic_auth
puts "INFO: Public read access is enabled" if allow_public_read_access
policy = PactBrokerResourceAccessPolicy.build(allow_public_read_access, allow_public_access_to_heartbeat)
use BasicAuth,
[basic_auth_username, basic_auth_password],
[basic_auth_read_only_username, basic_auth_read_only_password],
policy
config.runtime_configuration = PactBroker.docker_configuration
config.basic_auth_enabled = config.basic_auth_credentials_provided?
end

run app
27 changes: 0 additions & 27 deletions pact_broker/database_connection.rb

This file was deleted.

29 changes: 0 additions & 29 deletions pact_broker/database_logger.rb

This file was deleted.

Loading

0 comments on commit 59d23d9

Please sign in to comment.