Skip to content

Commit

Permalink
Update to use pact-broker
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneLimburg committed Nov 8, 2024
1 parent af72e16 commit ea4b2e0
Show file tree
Hide file tree
Showing 39 changed files with 467 additions and 28 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ jobs:
distribution: 'temurin'
cache: maven

- name: Build with Docker
run: docker compose build

- name: Start with Docker
run: docker compose up -d

- name: Build customer-service
run: mvn clean package -f customer-service/pom.xml -Dservice.name=customer-service
run: mvn clean package -f customer-service/pom.xml -Dservice.name=customer-service pact:publish

- name: Build billing-service
run: mvn clean package -f billing-service/pom.xml -Dservice.name=billing-service
Expand All @@ -28,11 +34,5 @@ jobs:
- name: Build address-validation-service
run: mvn clean package -f address-validation-service/pom.xml -Dservice.name=address-validation-service

- name: Build with Docker
run: docker compose build

- name: Start with Docker
run: docker compose up -d

- name: Stop Docker Containers
run: docker compose down
1 change: 1 addition & 0 deletions address-validation-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
2 changes: 1 addition & 1 deletion address-validation-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh "mvn test -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B"
}
}
stage ('Package') {
Expand Down
4 changes: 2 additions & 2 deletions address-validation-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<version>1.0.0-SNAPSHOT</version>

<scm>
<connection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git</developerConnection>
<connection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git</developerConnection>
</scm>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package de.openknowledge.sample.address;

import static java.util.Optional.ofNullable;

import org.apache.meecrowave.Meecrowave;
import org.apache.meecrowave.junit5.MonoMeecrowaveConfig;
import org.apache.meecrowave.testing.ConfigurationInject;
Expand All @@ -25,27 +27,30 @@
import au.com.dius.pact.provider.junit5.HttpTestTarget;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;

@IgnoreNoPactsToVerify
@Provider("address-validation-service")
@PactFolder("src/test/pacts")
@PactBroker(url = "${pactBroker.url:http://localhost:5000}")
@MonoMeecrowaveConfig
public class AddressValidationServiceTest {

@ConfigurationInject
private Meecrowave.Builder config;

@BeforeEach
public void setUp(PactVerificationContext context) {
context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/"));
public void setUp(PactVerificationContext verificationContext) {
ofNullable(verificationContext)
.ifPresent(context -> context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/")));
}

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
context.verifyInteraction();
ofNullable(context).ifPresent(PactVerificationContext::verifyInteraction);
}

@State("Three customers")
Expand Down
2 changes: 1 addition & 1 deletion billing-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh "mvn test -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B"
}
}
stage ('Package') {
Expand Down
4 changes: 2 additions & 2 deletions billing-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<version>1.0.0-SNAPSHOT</version>

<scm>
<connection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/billing-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/billing-service.git</developerConnection>
<connection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/billing-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/billing-service.git</developerConnection>
</scm>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import au.com.dius.pact.provider.junit5.HttpTestTarget;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;

@IgnoreNoPactsToVerify
@Provider("billing-service")
@PactFolder("src/test/pacts")
@PactBroker(url = "${pactBroker.url:http://localhost:5000}")
@MonoMeecrowaveConfig
public class BillingAddressServiceTest {

Expand Down
1 change: 1 addition & 0 deletions customer-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
2 changes: 1 addition & 1 deletion customer-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh 'mvn test pact:publish -DpactBroker.url=http://pact-service:8080 -B'
}
}
stage ('Package') {
Expand Down
13 changes: 11 additions & 2 deletions customer-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<version>1.0.0-SNAPSHOT</version>

<scm>
<connection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/customer-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/customer-service.git</developerConnection>
<connection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/customer-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/customer-service.git</developerConnection>
</scm>

<properties>
Expand All @@ -26,6 +26,7 @@
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pactBroker.url>http://localhost:5000</pactBroker.url>
<meecrowave.version>1.2.15</meecrowave.version>
<deltaspike.version>1.9.6</deltaspike.version>
<junit.version>5.8.2</junit.version>
Expand Down Expand Up @@ -189,6 +190,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>maven</artifactId>
<version>4.3.5</version>
<configuration>
<pactBrokerUrl>${pactBroker.url}</pactBrokerUrl>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void initializeRepository(MockServer mockServer) {

@PactTestFor(pactMethod = "getMax")
@Test
public void findDeliveryAddressForExistingCustomer() {
public void findBillingAddressForExistingCustomer() {
Optional<Address> address = repository.find(new CustomerNumber("0815"));
assertThat(address).isPresent().contains(
new Address(
Expand Down
1 change: 1 addition & 0 deletions delivery-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
2 changes: 1 addition & 1 deletion delivery-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh "mvn test pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B"
}
}
stage ('Package') {
Expand Down
4 changes: 3 additions & 1 deletion delivery-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pactBroker.url>http://localhost:5000</pactBroker.url>
<meecrowave.version>1.2.15</meecrowave.version>
<deltaspike.version>1.9.6</deltaspike.version>
<hibernate.version>5.4.21.Final</hibernate.version>
Expand Down Expand Up @@ -197,6 +198,7 @@
<configuration>
<systemPropertyVariables>
<pact.provider.version>${project.version}</pact.provider.version>
<pactBroker.url>${pactBroker.url}</pactBroker.url>
<javax.persistence.jdbc.url>jdbc:h2:mem:delivery</javax.persistence.jdbc.url>
<javax.persistence.jdbc.driver>org.h2.Driver</javax.persistence.jdbc.driver>
<javax.persistence.jdbc.user>sa</javax.persistence.jdbc.user>
Expand Down Expand Up @@ -237,7 +239,7 @@
<artifactId>maven</artifactId>
<version>4.3.5</version>
<configuration>
<pactBrokerUrl>http://localhost</pactBrokerUrl>
<pactBrokerUrl>${pactBroker.url}</pactBrokerUrl>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@
import au.com.dius.pact.provider.junit5.HttpTestTarget;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.StateChangeAction;
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;
import de.openknowledge.sample.address.domain.AddressValidationService;
import rocks.limburg.cdimock.MockitoBeans;

@IgnoreNoPactsToVerify
@MockitoBeans(types = {AddressValidationService.class})
@Provider("delivery-service")
@PactFolder("src/test/pacts")
@PactBroker(url = "${pactBroker.url:http://localhost:5000}")
@MonoMeecrowaveConfig
public class DeliveryAddressServiceTest {

Expand Down
47 changes: 47 additions & 0 deletions deployment/base/gogs/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: gogs-deployment
labels:
app: gogs-service
spec:
replicas: 1
selector:
matchLabels:
app: gogs-service
template:
metadata:
labels:
app: gogs-service
spec:
containers:
- name: gogs
image: host.docker.internal:5000/gogs:local
ports:
- containerPort: 3000
name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gogs-db-deployment
labels:
app: gogs-db-service
spec:
replicas: 1
selector:
matchLabels:
app: gogs-db-service
template:
metadata:
labels:
app: gogs-db-service
spec:
containers:
- name: gogs-postgres
image: postgres:15.4-bullseye
ports:
- containerPort: 5432
env:
- name: POSTGRES_PASSWORD
value: g0g5db
19 changes: 19 additions & 0 deletions deployment/base/gogs/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gogs-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: gogs.localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: gogs-service
port:
number: 30030
7 changes: 7 additions & 0 deletions deployment/base/gogs/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yaml
- service.yaml
- ingress.yaml
28 changes: 28 additions & 0 deletions deployment/base/gogs/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: v1
kind: Service
metadata:
name: gogs-service
spec:
selector:
app: gogs-service
type: NodePort
ports:
- protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30030
name: service
---
apiVersion: v1
kind: Service
metadata:
name: gogs-db-service
spec:
selector:
app: gogs-db-service
type: NodePort
ports:
- protocol: TCP
port: 5432
targetPort: 5432
name: service
29 changes: 29 additions & 0 deletions deployment/base/jenkins/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-deployment
labels:
app: jenkins-service
spec:
replicas: 1
selector:
matchLabels:
app: jenkins-service
template:
metadata:
labels:
app: jenkins-service
spec:
containers:
- name: jenkins
image: host.docker.internal:5000/jenkins:local
ports:
- containerPort: 8080
name: http
volumeMounts:
- mountPath: /var/run
name: docker-sock
volumes:
- name: docker-sock
hostPath:
path: /var/run
19 changes: 19 additions & 0 deletions deployment/base/jenkins/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: jenkins-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: jenkins.localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: jenkins-service
port:
number: 30040
Loading

0 comments on commit ea4b2e0

Please sign in to comment.