Skip to content

Commit

Permalink
feat: allow the env var used to set the port to be called a different…
Browse files Browse the repository at this point in the history
… name to support running on Heroku
  • Loading branch information
bethesque committed Jun 25, 2020
1 parent af1e7f5 commit f626662
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ COPY pact_broker $HOME/

# Start Puma
ENV RACK_ENV=production
ENV PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME=PACT_BROKER_PORT
ENV PACT_BROKER_PORT=9292
USER ruby
EXPOSE $PACT_BROKER_PORT
ENTRYPOINT ["./entrypoint.sh"]
CMD ["config.ru"]
51 changes: 51 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: "3"

services:
postgres:
image: postgres
healthcheck:
test: psql postgres --command "select 1" -U postgres
ports:
- "5432:5432"
# volumes:
# - postgres-volume:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres

pact-broker:
# image: pactfoundation/pact-broker
build: .
ports:
- "9393:9393"
depends_on:
- postgres
environment:
PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME: PORT
PACT_BROKER_DATABASE_URL_ENVIRONMENT_VARIABLE_NAME: DATABASE_URL
DATABASE_URL: "postgres://postgres:password@postgres/postgres"
# PACT_BROKER_DATABASE_USERNAME: postgres
# PACT_BROKER_DATABASE_PASSWORD: password
# PACT_BROKER_DATABASE_HOST: postgres
# PACT_BROKER_DATABASE_NAME: postgres
# PACT_BROKER_PORT: "9292"
PORT: '9393'
PACT_BROKER_LOG_LEVEL: INFO
PACT_BROKER_SQL_LOG_LEVEL: DEBUG

# Nginx is not necessary, but demonstrates how
# one might use a reverse proxy in front of the broker,
# and includes the use of a self-signed TLS certificate
nginx:
image: nginx:alpine
depends_on:
- pact-broker
volumes:
- ./ssl/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./ssl:/etc/nginx/ssl
ports:
- "8443:443"
- "80:80"
volumes:
postgres-volume:
31 changes: 31 additions & 0 deletions docker-compose-heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This example demonstrates how you can run the Pact Broker docker image on Heroku
# by allowing the PORT and DATABASE_URL environment variables to be used instead of
# PACT_BROKER_PORT and PACT_BROKER_DATABASE_URL.

version: "3"

services:
postgres:
image: postgres
healthcheck:
test: psql postgres --command "select 1" -U postgres
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres

pact-broker:
image: pactfoundation/pact-broker
ports:
- "9393:9393"
depends_on:
- postgres
environment:
PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME: "PORT"
PORT: "9393"
PACT_BROKER_DATABASE_URL_ENVIRONMENT_VARIABLE_NAME: "DATABASE_URL"
DATABASE_URL: "postgres://postgres:password@postgres/postgres"
PACT_BROKER_LOG_LEVEL: INFO
PACT_BROKER_SQL_LOG_LEVEL: DEBUG
11 changes: 3 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ services:
POSTGRES_DB: postgres

pact-broker:
# image: pactfoundation/pact-broker
image: pactfoundation/pact-broker
build: .
ports:
- "9292:9292"
depends_on:
- postgres
environment:
PACT_BROKER_DATABASE_URL_ENVIRONMENT_VARIABLE_NAME: DATABASE_URL
DATABASE_URL: "postgres://postgres:password@postgres/postgres"
# PACT_BROKER_DATABASE_USERNAME: postgres
# PACT_BROKER_DATABASE_PASSWORD: password
# PACT_BROKER_DATABASE_HOST: postgres
# PACT_BROKER_DATABASE_NAME: postgres
PACT_BROKER_PORT: "9292"
PACT_BROKER_PORT: '9292'
PACT_BROKER_DATABASE_URL: "postgres://postgres:password@postgres/postgres"
PACT_BROKER_LOG_LEVEL: INFO
PACT_BROKER_SQL_LOG_LEVEL: DEBUG

Expand Down
1 change: 1 addition & 0 deletions pact_broker/config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
port ENV[ENV['PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME']]
11 changes: 7 additions & 4 deletions pact_broker/docker_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ def initialize env, default_configuration
end

def pact_broker_environment_variables
@env.each_with_object({}) do | (key, value), hash |
if key.start_with?("PACT_BROKER_")
hash[key] = key =~ /password/i ? "*****" : value
end
pact_broker_environment_variable_names.sort.each_with_object({}) do | name, hash |
hash[name] = name =~ /password/i ? "*****" : @env[name]
end
end

def pact_broker_environment_variable_names
remapped_env_var_names = @env.keys.select { |k| k.start_with?('PACT_BROKER_') && k.end_with?('_ENVIRONMENT_VARIABLE_NAME') }
@env.keys.select{ |k| k.start_with?('PACT_BROKER_') } + remapped_env_var_names.collect{ |name| @env[name] }.compact
end

def webhook_host_whitelist
space_delimited_string_list_or_default(:webhook_host_whitelist)
end
Expand Down
2 changes: 1 addition & 1 deletion pact_broker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

bundle exec puma --port $PACT_BROKER_PORT
bundle exec puma
4 changes: 2 additions & 2 deletions ssl/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ server {
ssl_stapling_verify on;

location / {
proxy_pass http://pact_broker:9292;
proxy_pass http://pact-broker:9292;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Scheme "https";
proxy_set_header X-Forwarded-Port "443";
Expand All @@ -25,7 +25,7 @@ server {
server_name localhost;

location / {
proxy_pass http://pact_broker:9292;
proxy_pass http://pact-broker:9292;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
Expand Down

0 comments on commit f626662

Please sign in to comment.