Skip to content

Commit 6fd587d

Browse files
committedApr 2, 2020
Eliminated the need to set DOCKER_HOST_IP
1 parent 86d11e0 commit 6fd587d

File tree

17 files changed

+94
-77
lines changed

17 files changed

+94
-77
lines changed
 

‎.circleci/config.yml

+3-3
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
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

+40-39
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

+1-1
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

+18-13
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.8.0.MICRONAUT.M6
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.MICRONAUT.M6
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
@@ -90,7 +95,7 @@ services:
9095
SPRING_DATASOURCE_USERNAME: ftgo_consumer_service_user
9196
SPRING_DATASOURCE_PASSWORD: ftgo_consumer_service_password
9297
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
93-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
98+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
9499
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
95100
EVENTUATE_DATABASE_SCHEMA: ftgo_consumer_service
96101
JAVA_OPTS: -Xmx192m
@@ -108,7 +113,7 @@ services:
108113
SPRING_DATASOURCE_USERNAME: ftgo_order_service_user
109114
SPRING_DATASOURCE_PASSWORD: ftgo_order_service_password
110115
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
111-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
116+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
112117
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
113118
JAVA_OPTS: -Xmx192m
114119
SPRING_SLEUTH_ENABLED: "true"
@@ -129,7 +134,7 @@ services:
129134
SPRING_DATASOURCE_USERNAME: ftgo_kitchen_service_user
130135
SPRING_DATASOURCE_PASSWORD: ftgo_kitchen_service_password
131136
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
132-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
137+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
133138
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
134139
JAVA_OPTS: -Xmx192m
135140
EVENTUATE_DATABASE_SCHEMA: ftgo_kitchen_service
@@ -147,7 +152,7 @@ services:
147152
SPRING_DATASOURCE_USERNAME: ftgo_restaurant_service_user
148153
SPRING_DATASOURCE_PASSWORD: ftgo_restaurant_service_password
149154
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
150-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
155+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
151156
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
152157
JAVA_OPTS: -Xmx192m
153158
EVENTUATE_DATABASE_SCHEMA: ftgo_restaurant_service
@@ -165,7 +170,7 @@ services:
165170
SPRING_DATASOURCE_USERNAME: ftgo_accounting_service_user
166171
SPRING_DATASOURCE_PASSWORD: ftgo_accounting_service_password
167172
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
168-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
173+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
169174
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
170175
JAVA_OPTS: -Xmx192m
171176
EVENTUATE_DATABASE_SCHEMA: ftgo_accounting_service
@@ -183,7 +188,7 @@ services:
183188
SPRING_DATASOURCE_USERNAME: ftgo_delivery_service_user
184189
SPRING_DATASOURCE_PASSWORD: ftgo_delivery_service_password
185190
SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.jdbc.Driver
186-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
191+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
187192
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
188193
JAVA_OPTS: -Xmx192m
189194
SPRING_SLEUTH_ENABLED: "true"
@@ -201,7 +206,7 @@ services:
201206
- dynamodblocal
202207
- dynamodblocal-init
203208
environment:
204-
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:9092
209+
EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: kafka:29092
205210
EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: zookeeper:2181
206211
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-id_key}
207212
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-access_key}

‎ftgo-delivery-service/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies {
3838
componentTestCompile "com.jayway.restassured:rest-assured:$restAssuredVersion"
3939
componentTestCompile "com.jayway.jsonpath:json-path:2.3.0"
4040
componentTestCompile "org.hamcrest:hamcrest:2.1"
41+
componentTestCompile project(":ftgo-test-util")
4142

4243
}
4344

‎ftgo-delivery-service/src/component-test/java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceOutOfProcessComponentTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.chrisrichardson.ftgo.orderservice.api.events.OrderCreatedEvent;
99
import net.chrisrichardson.ftgo.orderservice.api.events.OrderDetails;
1010
import net.chrisrichardson.ftgo.restaurantservice.RestaurantServiceChannels;
11+
import net.chrisrichardson.ftgo.testutil.FtgoTestUtil;
1112
import org.junit.Test;
1213
import org.junit.runner.RunWith;
1314
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,7 +39,7 @@ public class DeliveryServiceOutOfProcessComponentTest {
3839
public static class Config {
3940
}
4041

41-
private String host = System.getenv("DOCKER_HOST_IP");
42+
private String host = FtgoTestUtil.getDockerHostIp();
4243
private int port = 8089;
4344
private long restaurantId;
4445
private long orderId;

‎ftgo-end-to-end-tests/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ dependencies {
5050
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
5151
testCompile "com.jayway.restassured:rest-assured:$restAssuredVersion"
5252
testCompile "com.jayway.jsonpath:json-path:2.3.0"
53+
testCompile project(":ftgo-test-util")
5354

5455

5556
}

‎ftgo-end-to-end-tests/src/test/java/net/chrisrichardson/ftgo/endtoendtests/EndToEndTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import net.chrisrichardson.ftgo.orderservice.api.web.CreateOrderRequest;
1919
import net.chrisrichardson.ftgo.orderservice.api.web.ReviseOrderRequest;
2020
import io.eventuate.util.test.async.Eventually;
21+
import net.chrisrichardson.ftgo.testutil.FtgoTestUtil;
2122
import org.junit.BeforeClass;
2223
import org.junit.Test;
2324

2425
import java.time.LocalDateTime;
2526
import java.util.Collections;
26-
import java.util.Optional;
2727

2828
import static com.jayway.restassured.RestAssured.given;
2929
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,7 +39,8 @@ public class EndToEndTests {
3939
public static final String RESTAURANT_NAME = "My Restaurant";
4040

4141
private final int revisedQuantityOfChickenVindaloo = 10;
42-
private String host = Optional.ofNullable(System.getenv("DOCKER_HOST_IP")).orElse("localhost");
42+
private String host = FtgoTestUtil.getDockerHostIp();
43+
4344
private int consumerId;
4445
private int restaurantId;
4546
private int orderId;

‎ftgo-order-service/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ dependencies {
175175
componentTestCompile 'info.cukes:cucumber-java:1.2.5'
176176
componentTestCompile 'info.cukes:cucumber-junit:1.2.5'
177177
componentTestCompile 'info.cukes:cucumber-spring:1.2.5'
178+
178179
testCompile project(":ftgo-test-util")
179180
testCompile "org.hamcrest:hamcrest:2.1"
180181

‎ftgo-order-service/src/attic/OrderServiceExternalComponentTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class OrderServiceExternalComponentTest extends AbstractOrderServiceCompo
2424
}
2525

2626
private int port = 8082;
27-
private String host = System.getenv("DOCKER_HOST_IP");
27+
private String host = FtgoTestUtil.getDockerHostIp();
2828

2929
@Override
3030
protected String baseUrl(String path) {

‎ftgo-order-service/src/component-test/java/net/chrisrichardson/ftgo/orderservice/cucumber/OrderServiceComponentTestStepDefinitions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class OrderServiceComponentTestStepDefinitions {
6060
}
6161

6262
private int port = 8082;
63-
private String host = System.getenv("DOCKER_HOST_IP");
63+
private String host = FtgoTestUtil.getDockerHostIp();
6464

6565
protected String baseUrl(String path) {
6666
return String.format("http://%s:%s%s", host, port, path);

‎ftgo-test-util/src/main/java/net/chrisrichardson/ftgo/testutil/FtgoTestUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ public class FtgoTestUtil {
99
public static <T> void assertPresent(Optional<T> value) {
1010
assertTrue(value.isPresent());
1111
}
12+
13+
public static String getDockerHostIp() {
14+
return Optional.ofNullable(System.getenv("DOCKER_HOST_IP")).orElse("localhost");
15+
}
1216
}

‎mysql-cli.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
docker run $* \
44
--name mysqlterm --rm \
5-
-e MYSQL_PORT_3306_TCP_ADDR=$DOCKER_HOST_IP -e MYSQL_PORT_3306_TCP_PORT=3306 -e MYSQL_ENV_MYSQL_ROOT_PASSWORD=rootpassword \
5+
-e MYSQL_PORT_3306_TCP_ADDR=${DOCKER_HOST_IP:-localhost} -e MYSQL_PORT_3306_TCP_PORT=3306 -e MYSQL_ENV_MYSQL_ROOT_PASSWORD=rootpassword \
66
mysql:5.7.13 \
77
sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" '

‎open-swagger-uis.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
for port in 8081 8084 8082 ; do
5-
open http://${DOCKER_HOST_IP?}:$port/swagger-ui.html
5+
open http://${DOCKER_HOST_IP:-localhost}:$port/swagger-ui.html
66
done

‎set-env.sh

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
if [ -z "$DOCKER_HOST_IP" ] ; then
2-
if [ -z "$DOCKER_HOST" ] ; then
3-
export DOCKER_HOST_IP=`hostname`
4-
else
2+
if [ ! -z "$DOCKER_HOST" ] ; then
53
echo using ${DOCKER_HOST?}
64
XX=${DOCKER_HOST%\:*}
75
export DOCKER_HOST_IP=${XX#tcp\:\/\/}
86
fi
97
fi
108

11-
echo DOCKER_HOST_IP is $DOCKER_HOST_IP
12-
export COMPOSE_HTTP_TIMEOUT=240
9+
10+
if [ -z "$DOCKER_HOST_IP" ] ; then
11+
echo DOCKER_HOST_IP is not set - localhost will be used
12+
else
13+
echo DOCKER_HOST_IP is ${DOCKER_HOST_IP}
14+
fi
15+
16+
export COMPOSE_HTTP_TIMEOUT=240

‎show-swagger-ui-urls.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
./wait-for-services.sh
44

5-
echo Create consumer - open http://${DOCKER_HOST_IP?}:8081/swagger-ui.html
6-
echo Create a restaurant - open http://${DOCKER_HOST_IP?}:8084/swagger-ui.html
7-
echo Create an order - open http://${DOCKER_HOST_IP?}:8082/swagger-ui.html
8-
echo View the order - open http://${DOCKER_HOST_IP?}:8082/swagger-ui.html
9-
echo View the order history - open http://${DOCKER_HOST_IP?}:8086/swagger-ui.html
10-
echo Zipkin distributed tracing - open http://${DOCKER_HOST_IP?}:9411
5+
echo Create consumer - open http://${DOCKER_HOST_IP:-localhost}:8081/swagger-ui.html
6+
echo Create a restaurant - open http://${DOCKER_HOST_IP:-localhost}:8084/swagger-ui.html
7+
echo Create an order - open http://${DOCKER_HOST_IP:-localhost}:8082/swagger-ui.html
8+
echo View the order - open http://${DOCKER_HOST_IP:-localhost}:8082/swagger-ui.html
9+
echo View the order history - open http://${DOCKER_HOST_IP:-localhost}:8086/swagger-ui.html
10+
echo Zipkin distributed tracing - open http://${DOCKER_HOST_IP:-localhost}:9411
1111

0 commit comments

Comments
 (0)
Please sign in to comment.