Skip to content

Commit 0a29bcf

Browse files
author
Luis Sanchez
committed
[FAB-1780] Cleanup kafka docker image build
- moved image from bddtests/environments/ to images/ - cleaned up Makefile - configured compose environments to use image Change-Id: I08caff43c947d8f3b15f69775f578556e847312b Signed-off-by: Luis Sanchez <[email protected]>
1 parent f91dace commit 0a29bcf

File tree

9 files changed

+37
-22
lines changed

9 files changed

+37
-22
lines changed

Makefile

+14-13
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PROTOS = $(shell git ls-files *.proto | grep -v vendor)
6363
MSP_SAMPLECONFIG = $(shell git ls-files msp/sampleconfig/*.pem)
6464
GENESIS_SAMPLECONFIG = $(shell git ls-files common/configtx/test/*.template)
6565
PROJECT_FILES = $(shell git ls-files)
66-
IMAGES = peer orderer ccenv javaenv testenv runtime zookeeper
66+
IMAGES = peer orderer ccenv javaenv testenv runtime zookeeper kafka
6767

6868
pkgmap.peer := $(PKGNAME)/peer
6969
pkgmap.orderer := $(PKGNAME)/orderer
@@ -106,13 +106,11 @@ docker: $(patsubst %,build/image/%/$(DUMMY), $(IMAGES))
106106
native: peer orderer
107107

108108
BEHAVE_ENVIRONMENTS = kafka orderer-1-kafka-1 orderer-1-kafka-3
109-
.PHONY: behave-environments $(BEHAVE_ENVIRONMENTS)
110-
behave-environments: $(BEHAVE_ENVIRONMENTS)
111-
$(BEHAVE_ENVIRONMENTS):
112-
@echo "# Generated from Dockerfile.in. DO NOT EDIT!" > bddtests/environments/kafka/Dockerfile
113-
@cat bddtests/environments/kafka/Dockerfile.in | \
114-
sed -e "s|_DOCKER_TAG_|$(DOCKER_TAG)|" >> bddtests/environments/kafka/Dockerfile
115-
@docker-compose --file bddtests/environments/$@/docker-compose.yml build
109+
BEHAVE_ENVIRONMENT_TARGETS = $(patsubst %,bddtests/environments/%, $(BEHAVE_ENVIRONMENTS))
110+
.PHONY: behave-environments $(BEHAVE_ENVIRONMENT_TARGETS)
111+
behave-environments: $(BEHAVE_ENVIRONMENT_TARGETS)
112+
$(BEHAVE_ENVIRONMENT_TARGETS):
113+
@docker-compose --file $@/docker-compose.yml build
116114

117115
behave-deps: docker peer build/bin/block-listener behave-environments
118116
behave: behave-deps
@@ -197,18 +195,21 @@ build/image/testenv/payload: build/gotools.tar.bz2 \
197195
build/msp-sampleconfig.tar.bz2
198196
build/image/runtime/payload: build/docker/busybox
199197
build/image/zookeeper/payload: images/zookeeper/docker-entrypoint.sh
198+
build/image/kafka/payload: images/kafka/docker-entrypoint.sh
200199

201200
build/image/%/payload:
202201
mkdir -p $@
203202
cp $^ $@
204203

205-
build/image/%/$(DUMMY): Makefile build/image/%/payload
206-
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
207-
@echo "Building docker $(TARGET)-image"
208-
@cat images/$(TARGET)/Dockerfile.in \
204+
build/image/%/Dockerfile: images/%/Dockerfile.in
205+
@cat $< \
209206
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
210207
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
211-
> $(@D)/Dockerfile
208+
> $@
209+
210+
build/image/%/$(DUMMY): Makefile build/image/%/payload build/image/%/Dockerfile
211+
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
212+
@echo "Building docker $(TARGET)-image"
212213
$(DBUILD) -t $(PROJECT_NAME)-$(TARGET) $(@D)
213214
docker tag $(PROJECT_NAME)-$(TARGET) $(PROJECT_NAME)-$(TARGET):$(DOCKER_TAG)
214215
@touch $@

bddtests/environments/kafka/.dockerignore

-1
This file was deleted.

bddtests/environments/kafka/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ Stopping kafka_kafka_1 ... done
2727
Stopping kafka_zookeeper_1 ... done
2828
$
2929
```
30+
#### Cleanup
31+
Use `docker-compose down` instead of `docker-compose rm` when cleaning up, so that the network is purged in addition to the containers.
32+
```console
33+
$ docker-compose down
34+
Stopping kafka_kafka_3 ... done
35+
Stopping kafka_kafka_2 ... done
36+
Stopping kafka_kafka_1 ... done
37+
Stopping kafka_zookeeper_1 ... done
38+
Removing kafka_kafka_3 ... done
39+
Removing kafka_kafka_2 ... done
40+
Removing kafka_kafka_1 ... done
41+
Removing kafka_zookeeper_1 ... done
42+
Removing network kafka_default
43+
$
44+
```
3045
## Configuration
3146
Edit the [`docker-compose.yml`](docker-compose.yml) file to configure.
3247
### server.properties

bddtests/environments/kafka/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
image: hyperledger/fabric-zookeeper
55

66
kafka:
7-
build: .
7+
image: hyperledger/fabric-kafka
88
environment:
99
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
1010
depends_on:

bddtests/environments/orderer-1-kafka-1/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- kafka0
1818

1919
kafka0:
20-
build: ../kafka
20+
image: hyperledger/fabric-kafka
2121
environment:
2222
KAFKA_BROKER_ID: 0
2323
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

bddtests/environments/orderer-1-kafka-3/docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
- kafka2
2020

2121
kafka0:
22-
build: ../kafka
22+
image: hyperledger/fabric-kafka
2323
environment:
2424
KAFKA_BROKER_ID: 0
2525
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
@@ -28,7 +28,7 @@ services:
2828
- zookeeper
2929

3030
kafka1:
31-
build: ../kafka
31+
image: hyperledger/fabric-kafka
3232
environment:
3333
KAFKA_BROKER_ID: 1
3434
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
@@ -37,7 +37,7 @@ services:
3737
- zookeeper
3838

3939
kafka2:
40-
build: ../kafka
40+
image: hyperledger/fabric-kafka
4141
environment:
4242
KAFKA_BROKER_ID: 2
4343
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

bddtests/environments/orderer-n-kafka-n/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- kafka
1717

1818
kafka:
19-
build: ../kafka
19+
image: hyperledger/fabric-kafka
2020
environment:
2121
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
2222
depends_on:

bddtests/environments/kafka/Dockerfile.in images/kafka/Dockerfile.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hyperledger/fabric-testenv:_DOCKER_TAG_
1+
FROM hyperledger/fabric-baseimage:_BASE_TAG_
22

33
ENV SCALA_VERSION=2.11 \
44
KAFKA_VERSION=0.9.0.1 \
@@ -10,7 +10,7 @@ RUN curl -fSL "http://www-us.apache.org/dist/kafka/0.9.0.1/kafka_${SCALA_VERSION
1010
&& mv /opt/kafka_"$SCALA_VERSION"-"$KAFKA_VERSION" /opt/kafka \
1111
&& rm kafka_"$SCALA_VERSION"-"$KAFKA_VERSION".tgz
1212

13-
ADD docker-entrypoint.sh /docker-entrypoint.sh
13+
ADD payload/docker-entrypoint.sh /docker-entrypoint.sh
1414

1515
EXPOSE 9092
1616

0 commit comments

Comments
 (0)