From c67673a49e37b01fe512ed1fcb327af7e6490408 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Thu, 9 Nov 2023 13:06:31 +0000 Subject: [PATCH] Remove now-redundant PaaS-related things Our Pact Broker instance has now been fully migrated to Heroku, so we can remove the old wrapper script that was used to run it on PaaS. Some notes: - The documentation about versioning is no longer valid because our new instance no longer uses a custom version parser - The documentation related to deployment has been moved into the README - Dependabot's bundler-related config has been removed because we no longer use Ruby in this repo - Similarly, I have removed CodeQL SAST scanning because this repo no longer contains any code --- .github/dependabot.yml | 4 - .github/workflows/ci.yml | 12 +-- .ruby-version | 1 - Gemfile | 8 -- Gemfile.lock | 165 --------------------------------------- Procfile | 1 - README.md | 52 +----------- config.ru | 69 ---------------- docs/deployment.md | 25 ------ docs/infrastructure.md | 62 --------------- docs/versioning.md | 16 ---- manifest.yml | 5 -- unicorn.rb | 16 ---- 13 files changed, 4 insertions(+), 432 deletions(-) delete mode 100644 .ruby-version delete mode 100644 Gemfile delete mode 100644 Gemfile.lock delete mode 100644 Procfile delete mode 100644 config.ru delete mode 100644 docs/deployment.md delete mode 100644 docs/infrastructure.md delete mode 100644 docs/versioning.md delete mode 100644 manifest.yml delete mode 100644 unicorn.rb diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d94b83c..ca1a2f3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,9 +1,5 @@ version: 2 updates: - - package-ecosystem: bundler - directory: / - schedule: - interval: daily - package-ecosystem: docker directory: / schedule: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9a0860..d49c7cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,19 +5,9 @@ on: push: branches: - main - paths-ignore: - - "Jenkinsfile" - - ".git**" - pull_request: - + pull_request: jobs: - codeql-sast: - name: CodeQL SAST scan - uses: alphagov/govuk-infrastructure/.github/workflows/codeql-analysis.yml@main - permissions: - security-events: write - dependency-review: name: Dependency Review scan uses: alphagov/govuk-infrastructure/.github/workflows/dependency-review.yml@main diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 49cdd66..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.7.6 diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 0eb2359..0000000 --- a/Gemfile +++ /dev/null @@ -1,8 +0,0 @@ -ruby File.read(".ruby-version").chomp - -source "https://rubygems.org" - -gem "pact_broker", "~> 2.107" - -gem "pg", "~> 1.5" -gem "unicorn", "~> 6.1" diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 945b21b..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,165 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - anyway_config (2.4.0) - ruby-next-core (>= 0.14.0) - as-notifications (1.0.2) - awesome_print (1.9.2) - concurrent-ruby (1.2.2) - crass (1.0.6) - declarative (0.0.20) - diff-lcs (1.5.0) - disposable (0.6.3) - declarative (>= 0.0.9, < 1.0.0) - representable (>= 3.1.1, < 4) - dry-configurable (1.0.1) - dry-core (~> 1.0, < 2) - zeitwerk (~> 2.6) - dry-core (1.0.0) - concurrent-ruby (~> 1.0) - zeitwerk (~> 2.6) - dry-inflector (1.0.0) - dry-initializer (3.1.1) - dry-logic (1.5.0) - concurrent-ruby (~> 1.0) - dry-core (~> 1.0, < 2) - zeitwerk (~> 2.6) - dry-schema (1.13.1) - concurrent-ruby (~> 1.0) - dry-configurable (~> 1.0, >= 1.0.1) - dry-core (~> 1.0, < 2) - dry-initializer (~> 3.0) - dry-logic (>= 1.4, < 2) - dry-types (>= 1.7, < 2) - zeitwerk (~> 2.6) - dry-types (1.7.1) - concurrent-ruby (~> 1.0) - dry-core (~> 1.0) - dry-inflector (~> 1.0) - dry-logic (~> 1.4) - zeitwerk (~> 2.6) - dry-validation (1.10.0) - concurrent-ruby (~> 1.0) - dry-core (~> 1.0, < 2) - dry-initializer (~> 3.0) - dry-schema (>= 1.12, < 2) - zeitwerk (~> 2.6) - expgen (0.1.1) - parslet - haml (5.2.2) - temple (>= 0.8.0) - tilt - i18n (1.13.0) - concurrent-ruby (~> 1.0) - json (2.6.3) - kgio (2.11.4) - mini_portile2 (2.8.2) - moments (0.2.0) - multi_json (1.15.0) - mustermann (2.0.2) - ruby2_keywords (~> 0.0.1) - nokogiri (1.15.3) - mini_portile2 (~> 2.8.2) - racc (~> 1.4) - pact-support (1.19.0) - awesome_print (~> 1.9) - diff-lcs (~> 1.4) - expgen (~> 0.1) - rainbow (~> 3.1.1) - pact_broker (2.107.1) - anyway_config (~> 2.1) - dry-validation (~> 1.8) - haml (~> 5.0) - json (~> 2.3) - moments (~> 0.2) - pact-support (~> 1.16, >= 1.16.4) - padrino-core (~> 0.14, >= 0.14.3) - psych (~> 4.0) - rack (~> 2.2, >= 2.2.3) - rack-protection (>= 2.0.8.1, < 3.0) - redcarpet (~> 3.5, >= 3.5.1) - reform (~> 2.6) - request_store (~> 1.5) - roar (~> 1.1) - sanitize (~> 6.0) - semantic_logger (~> 4.11) - semver2 (~> 3.4.2) - sequel (~> 5.28) - sinatra (>= 2.0.8.1, < 3.0) - sucker_punch (~> 2.0) - table_print (~> 1.5) - webmachine (>= 2.0.0.beta, < 3.0) - webrick (~> 1.8) - wisper (~> 2.0) - padrino-core (0.15.3) - padrino-support (= 0.15.3) - sinatra (>= 2.2.4) - thor (~> 1.0) - padrino-support (0.15.3) - parslet (2.0.0) - pg (1.5.4) - psych (4.0.6) - stringio - racc (1.7.1) - rack (2.2.7) - rack-protection (2.2.4) - rack - rainbow (3.1.1) - raindrops (0.20.0) - redcarpet (3.6.0) - reform (2.6.2) - disposable (>= 0.5.0, < 1.0.0) - representable (>= 3.1.1, < 4) - uber (< 0.2.0) - representable (3.2.0) - declarative (< 0.1.0) - trailblazer-option (>= 0.1.1, < 0.2.0) - uber (< 0.2.0) - request_store (1.5.1) - rack (>= 1.4) - roar (1.2.0) - representable (~> 3.1) - ruby-next-core (0.15.3) - ruby2_keywords (0.0.5) - sanitize (6.0.2) - crass (~> 1.0.2) - nokogiri (>= 1.12.0) - semantic_logger (4.13.0) - concurrent-ruby (~> 1.0) - semver2 (3.4.2) - sequel (5.68.0) - sinatra (2.2.4) - mustermann (~> 2.0) - rack (~> 2.2) - rack-protection (= 2.2.4) - tilt (~> 2.0) - stringio (3.0.6) - sucker_punch (2.1.2) - concurrent-ruby (~> 1.0) - table_print (1.5.7) - temple (0.10.0) - thor (1.2.1) - tilt (2.1.0) - trailblazer-option (0.1.2) - uber (0.1.0) - unicorn (6.1.0) - kgio (~> 2.6) - raindrops (~> 0.7) - webmachine (2.0.0) - as-notifications (>= 1.0.2, < 2.0) - i18n (>= 0.4.0) - multi_json - webrick (1.8.1) - wisper (2.0.1) - zeitwerk (2.6.8) - -PLATFORMS - ruby - -DEPENDENCIES - pact_broker (~> 2.107) - pg (~> 1.5) - unicorn (~> 6.1) - -BUNDLED WITH - 2.1.4 diff --git a/Procfile b/Procfile deleted file mode 100644 index d34e30b..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: bundle exec unicorn -p $PORT -c ./unicorn.rb diff --git a/README.md b/README.md index 7798f18..998fac0 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,12 @@ # GOV.UK Pact Broker -This repo is a thin wrapper around the [Pact Broker Gem][pact-broker-gem] that -allows Pact Broker to be run on unicorn server on the -[GOV.UK PAAS][government-paas]. - -As PaaS is being decommissioned later this year, we are currently migrating -Pact Broker to Heroku, and so this repo also contains a `Dockerfile` and -associated `heroku.yml` file to allow it to run there. After the migration is -complete, the leftover pieces of the old wrapper (`config.ru`, `Gemfile`, -`Procfile`, etc.) will be removed from this repo. +This repo contains a minimal configuration to allow the +[pactfoundation/pact-broker](https://hub.docker.com/r/pactfoundation/pact-broker) +Docker image to run on Heroku. Pact Broker is used by projects such as [Publishing API][publishing-api], [GDS API Adapters][gds-api-adapters] and [Content Store][content-store] for contract testing. - -## Getting started (legacy version) - -### Install dependencies - -``` -$ bundle install -``` - -### Create a PostgreSQL database - -``` -$ psql postgres -> create database pact_broker; -> CREATE USER pact_broker WITH PASSWORD 'pact_broker'; -> GRANT ALL PRIVILEGES ON DATABASE pact_broker to pact_broker; -``` - -### Set up environment variables - -``` -$ export AUTH_USERNAME=username -$ export AUTH_PASSWORD=password -$ export DATABASE_URL=postgresql://pact_broker@localhost/pact_broker -``` - -### Run the app - -``` -$ bundle exec unicorn -``` - -## Further documentation - -- [Infrastructure](docs/infrastructure.md) -- [Deployment](docs/deployment.md) -- [Versioning](docs/versioning.md) - -[pact-broker-gem]: https://github.com/bethesque/pact_broker -[government-paas]: https://docs.cloud.service.gov.uk/ [publishing-api]: https://github.com/alphagov/publishing-api [gds-api-adapters]: https://github.com/alphagov/gds-api-adapters [content-store]: https://github.com/alphagov/content-store diff --git a/config.ru b/config.ru deleted file mode 100644 index cbc4ae2..0000000 --- a/config.ru +++ /dev/null @@ -1,69 +0,0 @@ -require 'fileutils' -require 'logger' -require 'sequel' -require 'pact_broker' - -DB_URL = ENV.fetch('DATABASE_URL') -AUTH_USERNAME = ENV.fetch('AUTH_USERNAME') -AUTH_PASSWORD = ENV.fetch('AUTH_PASSWORD') - -class NonGetBasicAuth < Rack::Auth::Basic - def call(env) - if ['GET', 'HEAD'].include?(env['REQUEST_METHOD']) - return @app.call(env) - end - super - end -end - -use NonGetBasicAuth, "Restricted write access" do |username, password| - username == AUTH_USERNAME && password == AUTH_PASSWORD -end - -# Version handler that supports branch names as well as numeric versions. -# Branch names sort after any numeric versions so that latest will always -# return the latest released version -class CustomVersionParser - def self.call(string_version) - case string_version - when "main", /\Abranch-/ - Version.new(string_version) - else - Version.new(::Versionomy.parse(string_version)) - end - rescue ::Versionomy::Errors::ParseError => e - nil - end - - Version = Struct.new(:version) do - def branch? - version.is_a?(String) - end - - def <=>(other) - return version <=> other.version if branch? && other.branch? - return -1 if branch? - return 1 if other.branch? - version <=> other.version - end - end -end - -app = PactBroker::App.new do | config | - # change these from their default values if desired - # config.log_dir = "./log" - # config.auto_migrate_db = true - # config.use_hal_browser = true - config.log_stream = "stdout" - - # Have a look at the Sequel documentation to make decisions about things like connection pooling - # and connection validation. - connection = Sequel.connect(DB_URL, :encoding => 'utf8', :logger => config.logger) - # This is a fix for a postgres losing connection error: https://github.com/bethesque/pact_broker/issues/39 - connection.extension(:connection_validator) - connection.pool.connection_validation_timeout = -1 - config.database_connection = connection - config.version_parser = CustomVersionParser -end - -run app diff --git a/docs/deployment.md b/docs/deployment.md deleted file mode 100644 index 3db317d..0000000 --- a/docs/deployment.md +++ /dev/null @@ -1,25 +0,0 @@ -# Deployment - -## Legacy instance (on PaaS) - -You'll need a cloud foundry account for [GOV.UK PAAS][government-paas] and -be in the `govuk_development` organisation with access to the `sandbox` space. - -From there you should be able to see this app (`pact-broker`) by running: - -``` -$ cf apps -``` - -Then when you have made your changes you can push a new deployment with: - -``` -$ cf push pact-broker -``` - -[government-paas]: https://docs.cloud.service.gov.uk/ - -## New instance (on Heroku) - -This instance is automatically deployed whenever a new commit is pushed. -Logs can be found in [the Heroku dashboard for this project](https://dashboard.heroku.com/apps/govuk-pact-broker). diff --git a/docs/infrastructure.md b/docs/infrastructure.md deleted file mode 100644 index c359927..0000000 --- a/docs/infrastructure.md +++ /dev/null @@ -1,62 +0,0 @@ -# Infrastructure - -This guidance is about how to setup the app from scratch on [GOV.UK PAAS][government-paas]. - -## Space for the app - -You may be given a space by your organisation manager, or need to create one -for the application. - -At the time of writing this app runs on the `govuk_development` organisation -in the `sandbox` space - -## Push the app to the PAAS - -As we've not set everything up we don't want to start the app now. - -``` -$ cf push pact-broker --no-start -``` - -we can pass a `-n HOSTNAME` argument here to specify the hostname, otherwise -it will use the default one of `pact-broker` (as specified in -[manifest.yml](manifest.yml)) - -## Create a database - -There's a number of different database plans available, but the "Free" one -should be sufficient: - -``` -$ cf create-service postgres Free pact-broker-db -``` - -This will take a few minutes. Once completed it can be bound to the application: - -``` -$ cf bind-service pact-broker pact-broker-db -``` - -## Set up environment variables for credentials - -This application requires basic auth credentials of `AUTH_USERNAME` and -`AUTH_PASSWORD`. - -``` -$ cf set-env pact-broker AUTH_USERNAME username -$ cf set-env pact-broker AUTH_PASSWORD password -``` - -## Start the app - -``` -$ cf start pact-broker -``` - -And then you'll probably want it to run on 2 instances: - -``` -$ cf scale pact-broker -i 2 -``` - -[government-paas]: https://docs.cloud.service.gov.uk/ diff --git a/docs/versioning.md b/docs/versioning.md deleted file mode 100644 index 440ea76..0000000 --- a/docs/versioning.md +++ /dev/null @@ -1,16 +0,0 @@ -# Versioning - -Out of the box, the Pact Broker allows uploading of pact files with semver -style versions (eg 2.0.1). For our usage, we wanted to be able to upload pact -files from various branches in addition to the released versions so that our -branch builds of consumers can verify their pactfiles with the providers. - -Pact Broker allows us to [implement our own versioning -scheme](https://github.com/bethesque/pact_broker/wiki/Configuration#version-parser) -by providing a custom version parser. We've [used -this](https://github.com/alphagov/govuk-pact-broker/blob/main/config.ru#L23-L50) -to extend the versioning scheme to allow branch builds to be uploaded as well. -In addition to numeric versions, our scheme allows for "main", and -"branch-foo" versions to be uploaded. These will always be ordered after any -numeric versions, so the 'latest' pactfile from the Pact Broker's point of view will -always be the highest numeric version. diff --git a/manifest.yml b/manifest.yml deleted file mode 100644 index 02c3e2b..0000000 --- a/manifest.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -applications: -- name: pact-broker - memory: 256M - buildpack: ruby_buildpack diff --git a/unicorn.rb b/unicorn.rb deleted file mode 100644 index 9968077..0000000 --- a/unicorn.rb +++ /dev/null @@ -1,16 +0,0 @@ -worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) -timeout 15 -preload_app true - -before_fork do |server, worker| - Signal.trap 'TERM' do - puts 'Unicorn master intercepting TERM and sending myself QUIT instead' - Process.kill 'QUIT', Process.pid - end -end - -after_fork do |server, worker| - Signal.trap 'TERM' do - puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' - end -end