Skip to content

Commit

Permalink
Simplified docker usage. Added docker-compose upgrade to circle ci. F…
Browse files Browse the repository at this point in the history
  • Loading branch information
dartartem committed Apr 8, 2020
1 parent bd15913 commit 4cb04f7
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 97 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- eventuate-tram-sagas-examples-customers-and-orders-
- run:
command: |
./.circleci/upgrade-docker-compose.sh
. ./.circleci/setenv-circle-ci.sh
./gradlew testClasses
- save_cache:
Expand Down
1 change: 0 additions & 1 deletion .circleci/setenv-circle-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Host DNS name doesn't resolve in Docker alpine images

export DOCKER_HOST_IP=$(hostname -I | sed -e 's/ .*//g')
export TERM=dumb

export SDKMAN_DIR=/home/circleci/.sdkman
Expand Down
7 changes: 7 additions & 0 deletions .circleci/upgrade-docker-compose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash -e

docker-compose version
docker version
curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
chmod +x ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
17 changes: 6 additions & 11 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,20 @@ First, build the application
Next, launch the services using https://docs.docker.com/compose/[Docker Compose]:

```
export DOCKER_HOST_IP=...
./gradlew mysqlComposeBuild
./gradlew mysqlComposeUp
```

Note:

1. You can also run the Postgres version using `./gradlew postgresComposeBuild` and `./gradlew postgresComposeUp`
2. You need to set `DOCKER_HOST_IP` before running Docker Compose.
This must be an IP address or resolvable hostname.
It cannot be `localhost`.
See this http://eventuate.io/docs/usingdocker.html[guide to setting `DOCKER_HOST_IP`] for more information.
You can also run the Postgres version using `./gradlew postgresComposeBuild` and `./gradlew postgresComposeUp`

== Using the application

Once the application has started, you can use the application via the Swagger UI:

* `Order Service` - `http://${DOCKER_HOST_IP}:8081/swagger-ui.html`
* `Customer Service` - `http://${DOCKER_HOST_IP}:8082/swagger-ui.html`
* `Order Service` - `http://localhost:8081/swagger-ui.html`
* `Customer Service` - `http://localhost:8082/swagger-ui.html`

You can also use `curl` to interact with the services.
First, let's create a customer:
Expand All @@ -109,7 +104,7 @@ $ curl -X POST --header "Content-Type: application/json" -d '{
"amount": 5
},
"name": "Jane Doe"
}' http://${DOCKER_HOST_IP}:8082/customers
}' http://localhost:8082/customers

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Expand All @@ -127,7 +122,7 @@ $ curl -X POST --header "Content-Type: application/json" -d '{
"orderTotal": {
"amount": 4
}
}' http://${DOCKER_HOST_IP}:8081/orders
}' http://localhost:8081/orders

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Expand All @@ -141,7 +136,7 @@ Content-Type: application/json;charset=UTF-8
Finally, check the status of the `Order`:

```bash
$ curl -X GET http://${DOCKER_HOST_IP}:8081/orders/1
$ curl -X GET http://localhost:8081/orders/1

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Expand Down
16 changes: 12 additions & 4 deletions _build-and-test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
set -e


. ./set-env-${DATABASE?}.sh

./gradlew testClasses

dockercdc="./gradlew ${DATABASE?}cdcCompose"
Expand All @@ -14,14 +12,24 @@ ${dockerall}Down
${dockercdc}Build
${dockercdc}Up

./wait-for-services.sh $DOCKER_HOST_IP "8099"
./wait-for-services.sh localhost "8099"

#Testing db cli
if [ "${DATABASE}" == "mysql" ]; then
echo 'show databases;' | ./mysql-cli.sh -i
elif [ "${DATABASE}" == "postgres" ]; then
echo '\l' | ./postgres-cli.sh -i
else
echo "Unknown Database"
exit
fi

./gradlew -x :end-to-end-tests:test build

${dockerall}Build
${dockerall}Up

./wait-for-services.sh $DOCKER_HOST_IP "8081 8082"
./wait-for-services.sh localhost "8081 8082"

./gradlew :end-to-end-tests:cleanTest :end-to-end-tests:test

Expand Down
2 changes: 2 additions & 0 deletions build-and-test-all-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set -e

export DATABASE=postgres

export SPRING_PROFILES_ACTIVE=postgres

./_build-and-test-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.datasource.url=jdbc:postgresql://localhost/eventuate
spring.datasource.username=eventuate
spring.datasource.password=eventuate
spring.datasource.driver-class-name=org.postgresql.Driver
7 changes: 7 additions & 0 deletions customer-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eventuatelocal.kafka.bootstrap.servers=localhost:9092
eventuatelocal.zookeeper.connection.string=localhost:2181

spring.datasource.url=jdbc:mysql://localhost/eventuate
spring.datasource.username=mysqluser
spring.datasource.password=mysqlpw
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
21 changes: 13 additions & 8 deletions docker-compose-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
SPRING_DATASOURCE_USERNAME: mysqluser
SPRING_DATASOURCE_PASSWORD: mysqlpw
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181

customerservice:
Expand All @@ -31,24 +31,29 @@ services:
SPRING_DATASOURCE_USERNAME: mysqluser
SPRING_DATASOURCE_PASSWORD: mysqlpw
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181

zookeeper:
image: eventuateio/eventuate-zookeeper:$EVENTUATE_COMMON_VERSION
image: confluentinc/cp-zookeeper:5.2.4
ports:
- 2181:2181
environment:
ZOOKEEPER_CLIENT_PORT: 2181

kafka:
image: eventuateio/eventuate-kafka:$EVENTUATE_KAFKA_VERSION
image: "confluentinc/cp-enterprise-kafka:5.2.4"
ports:
- 9092:9092
depends_on:
- zookeeper
environment:
- ADVERTISED_HOST_NAME=${DOCKER_HOST_IP}
- KAFKA_HEAP_OPTS=-Xmx320m -Xms320m
- ZOOKEEPER_SERVERS=zookeeper:2181
KAFKA_LISTENERS: LC://kafka:29092,LX://kafka:9092
KAFKA_ADVERTISED_LISTENERS: LC://kafka:29092,LX://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LC:PLAINTEXT,LX:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LC
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

mysql:
build:
Expand All @@ -75,7 +80,7 @@ services:
SPRING_DATASOURCE_USERNAME: mysqluser
SPRING_DATASOURCE_PASSWORD: mysqlpw
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
EVENTUATELOCAL_CDC_DB_USER_NAME: root
EVENTUATELOCAL_CDC_DB_PASSWORD: rootpassword
Expand Down
44 changes: 13 additions & 31 deletions docker-compose-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,9 @@ services:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres/eventuate
SPRING_DATASOURCE_USERNAME: eventuate
SPRING_DATASOURCE_PASSWORD: eventuate
SPRING_DATASOURCE_TEST_ON_BORROW: "true"
SPRING_DATASOURCE_VALIDATION_QUERY: SELECT 1
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.postgresql.Driver
EVENTUATELOCAL_CDC_POLLING_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_CDC_MAX_EVENTS_PER_POLLING: 1000
EVENTUATELOCAL_CDC_MAX_ATTEMPTS_FOR_POLLING: 100
EVENTUATELOCAL_CDC_POLLING_RETRY_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
EVENTUATELOCAL_CDC_BINLOG_CLIENT_ID: 1234567890
EVENTUATELOCAL_CDC_SOURCE_TABLE_NAME: message
SPRING_PROFILES_ACTIVE: EventuatePolling

customerservice:
build: ./customer-service/
Expand All @@ -39,35 +30,30 @@ services:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres/eventuate
SPRING_DATASOURCE_USERNAME: eventuate
SPRING_DATASOURCE_PASSWORD: eventuate
SPRING_DATASOURCE_TEST_ON_BORROW: "true"
SPRING_DATASOURCE_VALIDATION_QUERY: SELECT 1
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.postgresql.Driver
EVENTUATELOCAL_CDC_POLLING_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_CDC_MAX_EVENTS_PER_POLLING: 1000
EVENTUATELOCAL_CDC_MAX_ATTEMPTS_FOR_POLLING: 100
EVENTUATELOCAL_CDC_POLLING_RETRY_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
EVENTUATELOCAL_CDC_BINLOG_CLIENT_ID: 1234567890
EVENTUATELOCAL_CDC_SOURCE_TABLE_NAME: message
SPRING_PROFILES_ACTIVE: EventuatePolling

zookeeper:
image: eventuateio/eventuate-zookeeper:$EVENTUATE_COMMON_VERSION
image: confluentinc/cp-zookeeper:5.2.4
ports:
- 2181:2181

environment:
ZOOKEEPER_CLIENT_PORT: 2181

kafka:
image: eventuateio/eventuate-kafka:$EVENTUATE_KAFKA_VERSION
image: "confluentinc/cp-enterprise-kafka:5.2.4"
ports:
- 9092:9092
depends_on:
- zookeeper
environment:
- ADVERTISED_HOST_NAME=${DOCKER_HOST_IP}
- KAFKA_HEAP_OPTS=-Xmx320m -Xms320m
- ZOOKEEPER_SERVERS=zookeeper:2181
KAFKA_LISTENERS: LC://kafka:29092,LX://kafka:9092
KAFKA_ADVERTISED_LISTENERS: LC://kafka:29092,LX://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LC:PLAINTEXT,LX:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LC
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1


postgres:
Expand Down Expand Up @@ -96,11 +82,7 @@ services:
SPRING_DATASOURCE_TEST_ON_BORROW: "true"
SPRING_DATASOURCE_VALIDATION_QUERY: SELECT 1
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.postgresql.Driver
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
EVENTUATELOCAL_CDC_POLLING_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_CDC_MAX_EVENTS_PER_POLLING: 1000
EVENTUATELOCAL_CDC_MAX_ATTEMPTS_FOR_POLLING: 100
EVENTUATELOCAL_CDC_POLLING_RETRY_INTERVAL_IN_MILLISECONDS: 500
EVENTUATELOCAL_CDC_READER_NAME: PostgresPollingReader
SPRING_PROFILES_ACTIVE: EventuatePolling
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@SpringBootTest(classes = CustomersAndOrdersE2ETestConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class CustomersAndOrdersE2ETest{

@Value("#{systemEnvironment['DOCKER_HOST_IP']}")
@Value("localhost")
private String hostName;

private String baseUrlOrders(String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.datasource.url=jdbc:postgresql://localhost/eventuate
spring.datasource.username=eventuate
spring.datasource.password=eventuate
spring.datasource.driver-class-name=org.postgresql.Driver
10 changes: 9 additions & 1 deletion integration-tests/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
spring.main.allow-bean-definition-overriding=true
spring.jpa.generate-ddl=true
spring.jpa.generate-ddl=true

eventuatelocal.kafka.bootstrap.servers=localhost:9092
eventuatelocal.zookeeper.connection.string=localhost:2181

spring.datasource.url=jdbc:mysql://localhost/eventuate
spring.datasource.username=mysqluser
spring.datasource.password=mysqlpw
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
4 changes: 2 additions & 2 deletions mysql-cli.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash -e

docker run $* \
--name mysqlterm --rm \
-e MYSQL_HOST=$DOCKER_HOST_IP \
--name mysqlterm --network=${PWD##*/}_default --rm \
-e MYSQL_HOST=mysql \
mysql:5.7.13 \
sh -c 'exec mysql -h"$MYSQL_HOST" -uroot -prootpassword -o eventuate'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.datasource.url=jdbc:postgresql://localhost/eventuate
spring.datasource.username=eventuate
spring.datasource.password=eventuate
spring.datasource.driver-class-name=org.postgresql.Driver
7 changes: 7 additions & 0 deletions order-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eventuatelocal.kafka.bootstrap.servers=localhost:9092
eventuatelocal.zookeeper.connection.string=localhost:2181

spring.datasource.url=jdbc:mysql://localhost/eventuate
spring.datasource.username=mysqluser
spring.datasource.password=mysqlpw
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
4 changes: 2 additions & 2 deletions postgres-cli.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash -e

docker run $* \
--name postgresterm \
-e POSTGRES_HOST=$DOCKER_HOST_IP \
--name postgresterm --network=${PWD##*/}_default \
-e POSTGRES_HOST=postgres \
--rm postgres:9.6.5 \
sh -c 'export PGPASSWORD=eventuate; exec psql -h "$POSTGRES_HOST" -U eventuate'
8 changes: 0 additions & 8 deletions set-env-mysql.sh

This file was deleted.

13 changes: 0 additions & 13 deletions set-env-postgres.sh

This file was deleted.

15 changes: 0 additions & 15 deletions set-env.sh

This file was deleted.

0 comments on commit 4cb04f7

Please sign in to comment.