Skip to content

Commit 33cc2f0

Browse files
committed
Eliminated the need to set DOCKER_HOST_IP
1 parent 4ef65b4 commit 33cc2f0

File tree

16 files changed

+280
-74
lines changed

16 files changed

+280
-74
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- ftgo-application-{{ checksum "gradle.properties" }}
1111
- ftgo-application-
1212
- run: TERM=dumb ./gradlew buildContracts
13-
- run: TERM=dumb ./gradlew testClasses :ftgo-order-service:compileComponentTestJava
13+
- run: TERM=dumb ./gradlew compileAll
1414
- save_cache:
1515
paths:
1616
- ~/.gradle
@@ -19,7 +19,7 @@ jobs:
1919
- run:
2020
command: |
2121
./.circleci/upgrade-docker-compose.sh
22-
. ./setenv-circle-ci.sh
22+
. .circleci/setenv-circle-ci.sh
2323
./build-and-test-all.sh
2424
- run:
2525
name: Save test results
@@ -33,7 +33,7 @@ jobs:
3333
path: ~/junit
3434
- run:
3535
command: |
36-
. ./setenv-circle-ci.sh
36+
. .circleci/setenv-circle-ci.sh
3737
./gradlew assemble
3838
docker-compose build
3939
./publish-docker-images.sh
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

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

4-
export DOCKER_HOST_IP=$(hostname -I | sed -e 's/ .*//g')
4+
echo NOT setting DOCKER_HOST_IP
55
export TERM=dumb
6-
7-

README.adoc

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -127,39 +127,6 @@ Build the services using this command:
127127
./gradlew assemble
128128
```
129129

130-
=== Setting environment variables
131-
132-
133-
==== Quick way
134-
135-
A quick way to set the environment variables is to run the script `./set-env.sh`
136-
137-
==== Long way
138-
139-
To run the application you must set the `DOCKER_HOST_IP` environment variable to the IP address of where the Docker containers are running:
140-
141-
* Docker toolbox/Virtual machine - IP address of the virtual machine
142-
* Docker for Windows/Mac/Linux - IP address of your laptop/desktop
143-
144-
The value of `DOCKER_HOST_IP` must be meaningful to both Java services/tests running on your desktop/laptop and to Docker containers.
145-
Please do NOT set it to the unresolvable hostname of your machine, `localhost` or `127.0.0.1` since the Docker containers will probably not work correctly.
146-
147-
=== Verifying that DOCKER_HOST_IP is set correctly
148-
149-
You can verify that `DOCKER_HOST_IP` is set correctly by running this command:
150-
151-
----
152-
docker run -p 8889:8888 -e DOCKER_DIAGNOSTICS_PORT=8889 -e DOCKER_HOST_IP \
153-
--rm eventuateio/eventuateio-docker-networking-diagnostics:0.2.0.RELEASE
154-
----
155-
156-
==== Setting the environment variable in your IDE
157-
158-
If you want to run Java services/tests within your IDE on your desktop/laptop AND the Docker containers are not accessible via `localhost` THEN you will need to set `DOCKER_HOST_IP` within your IDE.
159-
How to do this depends on your operating system and IDE.
160-
For example, I find it convenient to launch my IDE from the command line and after setting this environment variable.
161-
162-
163130
=== Running the application
164131

165132
Run the application using this command:
@@ -174,15 +141,17 @@ This can take a while.
174141

175142
Use the services Swagger UIs to invoke the services.
176143

177-
* Create consumer - `http://${DOCKER_HOST_IP?}:8081/swagger-ui.html`
178-
* Create a restaurant - `http://${DOCKER_HOST_IP?}:8084/swagger-ui.html`
179-
* Create an order - `http://${DOCKER_HOST_IP?}:8082/swagger-ui.html`
180-
* View the order - `http://${DOCKER_HOST_IP?}:8082/swagger-ui.html`
181-
* View the order history - `http://${DOCKER_HOST_IP?}:8086/swagger-ui.html`
144+
* Create consumer - `http://localhost:8081/swagger-ui.html`
145+
* Create a restaurant - `http://localhost:8084/swagger-ui.html`
146+
* Create an order - `http://localhost:8082/swagger-ui.html`
147+
* View the order - `http://localhost:8082/swagger-ui.html`
148+
* View the order history - `http://localhost:8086/swagger-ui.html`
182149

183-
You can also access the application via the `API Gateway` at `http://${DOCKER_HOST_IP?}:8087`.
150+
You can also access the application via the `API Gateway` at `http://localhost:8087`.
184151
However, currently it doesn't have a Swagger UI so you will have to use `curl`, for example.
185152

153+
Note: if the containers aren't accessible via `localhost`, you will have to use `${DOCKER_HOST_IP}` as described below.
154+
186155
=== Stopping the application
187156

188157
Stop the application using this command:
@@ -217,3 +186,35 @@ If you want to delete the persistent volumes for Apache Kafka, Zookeeper and MyS
217186
```
218187
./deployment/kubernetes/scripts/kubernetes-delete-volumes.sh
219188
```
189+
190+
== Setting environment variables to do development
191+
192+
You should not need to set any environment variables.
193+
To run the application, you certainly do not.
194+
Similarly, to do development (e.g. run tests), you typically do not need to set any environment variables.
195+
That's because Docker containers are generally accessible (e.g. Docker for Windows/Mac) on the host via `localhost`.
196+
However, if Docker is running elsewhere you will need to set `DOCKER_HOST_IP`.
197+
198+
=== Quick way
199+
200+
A quick way to set the environment variables is to run the script `./set-env.sh`.
201+
202+
=== Long way
203+
204+
The value of `DOCKER_HOST_IP` must be meaningful to both Java services/tests running on your desktop/laptop and to Docker containers.
205+
Please do NOT set it to the unresolvable hostname of your machine, `localhost` or `127.0.0.1` since the Docker containers will probably not work correctly.
206+
207+
=== Verifying that DOCKER_HOST_IP is set correctly
208+
209+
You can verify that `DOCKER_HOST_IP` is set correctly by running this command:
210+
211+
----
212+
docker run -p 8889:8888 -e DOCKER_DIAGNOSTICS_PORT=8889 -e DOCKER_HOST_IP \
213+
--rm eventuateio/eventuateio-docker-networking-diagnostics:0.2.0.RELEASE
214+
----
215+
216+
=== Setting the environment variable in your IDE
217+
218+
If you want to run Java services/tests within your IDE on your desktop/laptop AND the Docker containers are not accessible via `localhost` THEN you will need to set `DOCKER_HOST_IP` within your IDE.
219+
How to do this depends on your operating system and IDE.
220+
For example, I find it convenient to launch my IDE from the command line and after setting this environment variable.

_wait-for-services.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ports=$*
77
echo $path
88
echo $ports
99

10-
host=$DOCKER_HOST_IP
10+
host=${DOCKER_HOST_IP:-localhost}
1111

1212
done=false
1313

docker-compose.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
version: '3'
22
services:
33
zookeeper:
4-
image: eventuateio/eventuate-zookeeper:0.4.0.RELEASE
4+
image: confluentinc/cp-zookeeper:5.2.4
55
ports:
66
- 2181:2181
7+
environment:
8+
ZOOKEEPER_CLIENT_PORT: 2181
79
kafka:
8-
image: eventuateio/eventuate-kafka:0.3.0.RELEASE
10+
image: "confluentinc/cp-enterprise-kafka:5.2.4"
911
ports:
1012
- 9092:9092
1113
depends_on:
1214
- zookeeper
1315
environment:
14-
- ADVERTISED_HOST_NAME=${DOCKER_HOST_IP?DOCKER_HOST_IP must be set}
15-
- KAFKA_HEAP_OPTS=-Xmx192m -Xms192m
16-
- ZOOKEEPER_SERVERS=zookeeper:2181
16+
KAFKA_LISTENERS: LC://kafka:29092,LX://kafka:9092
17+
KAFKA_ADVERTISED_LISTENERS: LC://kafka:29092,LX://localhost:9092
18+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LC:PLAINTEXT,LX:PLAINTEXT
19+
KAFKA_INTER_BROKER_LISTENER_NAME: LC
20+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
21+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
1722
mysql:
1823
build: ./mysql
1924
ports:
@@ -30,7 +35,7 @@ services:
3035
- mysql
3136
- kafka
3237
environment:
33-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
38+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
3439
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
3540
EVENTUATE_CDC_PIPELINE_PIPELINE1_TYPE: eventuate-tram
3641
EVENTUATE_CDC_PIPELINE_PIPELINE1_READER: reader1
@@ -86,7 +91,7 @@ services:
8691
SPRING_DATASOURCE_USERNAME: ftgo_consumer_service_user
8792
SPRING_DATASOURCE_PASSWORD: ftgo_consumer_service_password
8893
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
89-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
94+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
9095
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
9196
EVENTUATE_DATABASE_SCHEMA: ftgo_consumer_service
9297
JAVA_OPTS: -Xmx192m
@@ -104,7 +109,7 @@ services:
104109
SPRING_DATASOURCE_USERNAME: ftgo_order_service_user
105110
SPRING_DATASOURCE_PASSWORD: ftgo_order_service_password
106111
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
107-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
112+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
108113
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
109114
JAVA_OPTS: -Xmx192m
110115
SPRING_SLEUTH_ENABLED: "true"
@@ -125,7 +130,7 @@ services:
125130
SPRING_DATASOURCE_USERNAME: ftgo_kitchen_service_user
126131
SPRING_DATASOURCE_PASSWORD: ftgo_kitchen_service_password
127132
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
128-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
133+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
129134
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
130135
JAVA_OPTS: -Xmx192m
131136
EVENTUATE_DATABASE_SCHEMA: ftgo_kitchen_service
@@ -143,7 +148,7 @@ services:
143148
SPRING_DATASOURCE_USERNAME: ftgo_restaurant_service_user
144149
SPRING_DATASOURCE_PASSWORD: ftgo_restaurant_service_password
145150
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
146-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
151+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
147152
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
148153
JAVA_OPTS: -Xmx192m
149154
EVENTUATE_DATABASE_SCHEMA: ftgo_restaurant_service
@@ -161,7 +166,7 @@ services:
161166
SPRING_DATASOURCE_USERNAME: ftgo_accounting_service_user
162167
SPRING_DATASOURCE_PASSWORD: ftgo_accounting_service_password
163168
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
164-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
169+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
165170
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
166171
JAVA_OPTS: -Xmx192m
167172
EVENTUATE_DATABASE_SCHEMA: ftgo_accounting_service
@@ -176,7 +181,7 @@ services:
176181
- dynamodblocal
177182
- dynamodblocal-init
178183
environment:
179-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
184+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
180185
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
181186
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-id_key}
182187
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-access_key}

ftgo-delivery-service/build.gradle

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
apply plugin: FtgoServicePlugin
3+
4+
// apply plugin: 'spring-cloud-contract'
5+
6+
apply plugin: 'docker-compose'
7+
8+
apply plugin: IntegrationTestsPlugin
9+
apply plugin: ComponentTestsPlugin
10+
apply plugin: FtgoJSONSchema2PojoPlugin
11+
12+
dependencies {
13+
ftgoApiSpecification project(":ftgo-restaurant-service-api-spec")
14+
15+
compile project(":ftgo-delivery-service-api")
16+
compile project(":ftgo-kitchen-service-api")
17+
compile project(":ftgo-restaurant-service-api")
18+
compile project(":ftgo-order-service-api")
19+
compile project(":ftgo-common")
20+
compile project(":ftgo-common-jpa")
21+
compile project(":common-swagger")
22+
23+
compile "io.eventuate.tram.core:eventuate-tram-spring-events:$eventuateTramVersion"
24+
compile "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
25+
compile "io.eventuate.tram.core:eventuate-tram-spring-jdbc-kafka:$eventuateTramVersion"
26+
27+
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
28+
compile "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"
29+
30+
compile('org.apache.kafka:kafka-clients:2.3.0') {
31+
force = true
32+
}
33+
34+
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
35+
testCompile "io.eventuate.tram.core:eventuate-tram-spring-in-memory:$eventuateTramVersion"
36+
testCompile "io.eventuate.util:eventuate-util-test:$eventuateUtilVersion"
37+
38+
componentTestCompile "com.jayway.restassured:rest-assured:$restAssuredVersion"
39+
componentTestCompile "com.jayway.jsonpath:json-path:2.3.0"
40+
componentTestCompile "org.hamcrest:hamcrest:2.1"
41+
componentTestCompile project(":ftgo-test-util")
42+
43+
}
44+
45+
dockerCompose {
46+
47+
componentTests {
48+
startedServices = [ 'ftgo-delivery-service']
49+
stopContainers = true
50+
}
51+
52+
}
53+
54+
componentTestsComposeUp.dependsOn(assemble)
55+
dockerCompose.componentTests.isRequiredBy(componentTest)
56+
57+
ftgoJsonSchema2Pojo {
58+
59+
ftgoRestaurantService {
60+
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec/messages")
61+
targetPackage = "net.chrisrichardson.ftgo.restaurantservice.events"
62+
includeAdditionalProperties = false
63+
generateBuilders = true
64+
useLongIntegers = true
65+
}
66+
67+
}
68+

0 commit comments

Comments
 (0)