Skip to content

Commit

Permalink
chore: support for hosted/local brokers
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Jun 17, 2024
1 parent 7f56969 commit 32a9a74
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
APP_REF: ${{ github.ref }}
LD_LIBRARY_PATH: /tmp
PACT_GO_LIB_DOWNLOAD_PATH: /tmp
LOG_LEVEL: info
LOG_LEVEL: debug
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
docker build \
--platform linux/amd64 \
--build-arg VERSION=${{ matrix.go-version }} \
-f Dockerfile-deb \
-f Dockerfile \
-t pactfoundation/pact-go-test-${{ matrix.go-version }} .
- name: Unit Test (amd64 docker)
if: matrix.os == 'ubuntu-22.04'
Expand Down
91 changes: 91 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,94 @@ The previous major version. Only bug fixes and security updates will be consider
### `master`

The `2.x.x` release line. Current major version.


## Running locally

### Pre-reqs

- GoLang

### Unit tests

```sh
make ci_unit
```

### E2E Examples

#### E2E Pre-reqs

- Pact CLI tools (for examples). Available via
- Docker
- Ruby
- Standalone package
-
- Pact Broker
- Locally via Docker
- Hosted (OSS or PactFlow)
- Java
- For Avro example
- Protobuf Compiler
- For gRPC / Protobuf examples

#### Running

With Docker

```sh
APP_SHA=foo make ci_examples
```

Without Docker

```sh
APP_SHA=foo make ci_hosted_examples
```

You will need to use a Pact Broker to run the examples.

You can either use an OSS Pact Broker and set the following env vars

- `PACT_BROKER_BASE_URL`
- `PACT_BROKER_USERNAME`
- `PACT_BROKER_PASSWORD`

Or a PactFlow Broker

- `PACT_BROKER_BASE_URL`
- `PACT_BROKER_TOKEN`

To use the different cli tools, use

- `PACT_TOOL=standalone make ci_examples`
- Install it `make install-pact-ruby-standalone`
- https://github.com/pact-foundation/pact-ruby-standalone
- `PACT_TOOL=ruby make ci_examples`
- Install it `make install-pact-ruby-cli`
- Requires ruby
- https://github.com/pact-foundation/pact_broker-client
- `PACT_TOOL=docker make ci_examples`
- Requires docker
- https://github.com/pact-foundation/pact-ruby-cli
You will want to install them first

### Docker

Build an image from the repo

```sh
make docker_build
```

Run the repo's unit test

```
make docker_run_test
```

Run the repo's examples

```
make docker_run_examples
```
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM golang:alpine

RUN apk add --no-cache curl gcc musl-dev gzip openjdk17-jre bash protoc protobuf-dev make file
ARG VERSION=latest
FROM golang:${VERSION}

RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler ruby ruby-dev ruby-bundler
COPY . /go/src/github.com/pact-foundation/pact-go

WORKDIR /go/src/github.com/pact-foundation/pact-go
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile-deb → Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ARG VERSION=latest
FROM golang:${VERSION}
FROM golang:${VERSION}-alpine

RUN apk add --no-cache curl gcc musl-dev gzip openjdk17-jre bash protoc protobuf-dev make file

RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler ruby ruby-dev ruby-bundler
COPY . /go/src/github.com/pact-foundation/pact-go

WORKDIR /go/src/github.com/pact-foundation/pact-go
Expand Down
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ include make/config.mk
TEST?=./...
.DEFAULT_GOAL := ci
DOCKER_HOST_HTTP?="http://host.docker.internal"
# PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD pactfoundation/pact-cli"
ifeq ($(OS),Windows_NT)
EXT=.exe
endif

ci:: docker deps clean bin test pact
ci_unit:: deps clean bin test
ci_examples:: docker pact
ci_hosted_examples:: pact
ci_hosted_examples:: run_ci_hosted_examples

run_ci_hosted_examples:
DOCKER_HOST_HTTP=$(PACT_BROKER_BASE_URL) make pact
# Run the ci target from a developer machine with the environment variables
# set as if it was on Travis CI.
# Use this for quick feedback when playing around with your workflows.
Expand Down Expand Up @@ -101,14 +102,12 @@ pact: clean install

publish:
@echo "-- 📃 Publishing pacts"
@"${PACT_BROKER_COMMAND}" publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod --branch ${APP_BRANCH}
@${PACT_BROKER_COMMAND} publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod --branch ${APP_BRANCH}

release:
echo "--- 🚀 Releasing it"
"$(CURDIR)/scripts/release.sh"

# @for d in $$(go list -buildvcs=false ./... | grep -v vendor | grep -v examples);

RACE?='-race'

ifdef SKIP_RACE
Expand Down Expand Up @@ -140,11 +139,9 @@ updatedeps:
go get -d -v -p 2 ./...

docker_build:
docker build -f Dockerfile-deb --build-arg VERSION=1.21 -t pactfoundation/pact-go-test .
docker build -f Dockerfile --build-arg VERSION=1.21 -t pactfoundation/pact-go-test .
docker_run_test:
docker run \
-e PACT_BROKER_BASE_URL \
-e PACT_BROKER_TOKEN \
-e LOG_LEVEL=info \
-e APP_SHA=foo \
--rm \
Expand All @@ -153,8 +150,10 @@ docker_run_test:
/bin/sh -c "make test"
docker_run_examples:
docker run \
-e PACT_BROKER_BASE_URL \
-e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) \
-e PACT_BROKER_TOKEN \
-e PACT_BROKER_USERNAME \
-e PACT_BROKER_PASSWORD \
-e LOG_LEVEL=info \
-e APP_SHA=foo \
--rm \
Expand Down Expand Up @@ -187,7 +186,7 @@ PACT_TOOL?=docker
PACT_CLI_DOCKER_VERSION?=latest
PACT_CLI_VERSION?=latest
PACT_CLI_STANDALONE_VERSION?=2.4.1
PACT_CLI_DOCKER_RUN_COMMAND?=docker run --rm -v /${PWD}:/${PWD} -w ${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli:${PACT_CLI_DOCKER_VERSION}
PACT_CLI_DOCKER_RUN_COMMAND?=docker run --rm -v /${PWD}:/${PWD} -w ${PWD} -e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) -e PACT_BROKER_TOKEN -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD pactfoundation/pact-cli:${PACT_CLI_DOCKER_VERSION}
PACT_BROKER_COMMAND=pact-broker
PACTFLOW_CLI_COMMAND=pactflow

Expand Down
2 changes: 1 addition & 1 deletion internal/native/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package native
/*
#cgo darwin,arm64 LDFLAGS: -L/tmp -L/usr/local/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi
#cgo darwin,amd64 LDFLAGS: -L/tmp -L/usr/local/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi
#cgo windows,amd64 LDFLAGS: -L/tmp -lpact_ffi
#cgo windows,amd64 LDFLAGS: -lpact_ffi
#cgo linux,amd64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi
#cgo linux,arm64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi
*/
Expand Down
6 changes: 3 additions & 3 deletions make/config.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export PATH := $(PWD)/pact/bin:$(PATH)
export PATH
# export PACT_BROKER_BASE_URL=http://127.0.0.1
# export PACT_BROKER_USERNAME=pact_workshop
# export PACT_BROKER_PASSWORD=pact_workshop
export PACT_BROKER_BASE_URL?=http://127.0.0.1
export PACT_BROKER_USERNAME?=pact_workshop
export PACT_BROKER_PASSWORD?=pact_workshop

0 comments on commit 32a9a74

Please sign in to comment.