Skip to content

Commit dc56003

Browse files
committed
start the client container once and execute actions on it
1 parent fb87a6d commit dc56003

File tree

20 files changed

+548
-244
lines changed

20 files changed

+548
-244
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Changed
1010

11+
- On the examples, start the client container once and execute actions on it.
1112
- Bump github.com/docker/docker from v20.10+incompatible to v24.0.7+incompatible
1213
- Bump github.com/docker/distribution from v2.8.2+incompatible to v2.8.3+incompatible
1314
- Bump github.com/go-git/go-git/v5 from v5.6.1 to v5.10.0

Makefile

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,61 @@ help: ## list allowed targets
77

88
test: unit-test functional-test ## Run all test
99

10-
functional-test: build-and-push-test build-and-push-join-context-test build-git-context-test build-git-context-auth-test build-git-path-test copy-remote-test## Run functional tests
11-
10+
functional-test: build-and-push-test build-and-push-join-context-test build-git-context-test build-git-context-auth-test build-path-context-test copy-remote-test ## Run functional tests
1211

1312
build-and-push-test: ## Execute functional test build-and-push
1413
@echo
1514
@echo " Run functional test: build-and-push"
16-
@echo
17-
cd ${BASE_FUNCTIONAL_FOLDER}/build-and-push && $(MAKE) test ; cd -
15+
@echo
16+
@RC=0; \
17+
cd ${BASE_FUNCTIONAL_FOLDER}/build-and-push && $(MAKE) test || RC=1; \
18+
cd -; \
19+
exit $$RC;
1820

1921
build-and-push-join-context-test: ## Execute functional test build-and-push-join-context
2022
@echo
2123
@echo " Run functional test: build-and-push-join-context"
22-
@echo
23-
cd ${BASE_FUNCTIONAL_FOLDER}/build-and-push-join-context && $(MAKE) test ; cd -
24+
@echo
25+
@RC=0; \
26+
cd ${BASE_FUNCTIONAL_FOLDER}/build-and-push-join-context && $(MAKE) test || RC=1; \
27+
cd -; \
28+
exit $$RC;
2429

2530
build-git-context-test: ## Execute functional test build-git-context
2631
@echo
2732
@echo " Run functional test: build-git-context"
28-
@echo
29-
cd ${BASE_FUNCTIONAL_FOLDER}/build-git-context && $(MAKE) test ; cd -
33+
@echo
34+
@RC=0; \
35+
cd ${BASE_FUNCTIONAL_FOLDER}/build-git-context && $(MAKE) test || RC=1; \
36+
cd -; \
37+
exit $$RC;
3038

3139
build-git-context-auth-test: ## Execute functional test build-git-context-auth
3240
@echo
3341
@echo " Run functional test: build-git-context-auth"
34-
@echo
35-
cd ${BASE_FUNCTIONAL_FOLDER}/build-git-context-auth && $(MAKE) test ; cd -
42+
@echo
43+
@RC=0; \
44+
cd ${BASE_FUNCTIONAL_FOLDER}/build-git-context-auth && $(MAKE) test || RC=1; \
45+
cd -; \
46+
exit $$RC;
3647

37-
build-git-path-test: ## Execute functional test build-git-path
48+
build-path-context-test: ## Execute functional test build-path-context
49+
@echo
50+
@echo " Run functional test: build-path-context"
3851
@echo
39-
@echo " Run functional test: build-git-path"
40-
@echo
41-
cd ${BASE_FUNCTIONAL_FOLDER}/build-git-path && $(MAKE) test ; cd -
52+
@RC=0; \
53+
cd ${BASE_FUNCTIONAL_FOLDER}/build-path-context && $(MAKE) test || RC=1; \
54+
cd -; \
55+
exit $$RC;
4256

4357
copy-remote-test: ## Execute functional test copy-remote
4458
@echo
4559
@echo " Run functional test: copy-remote"
46-
@echo
47-
cd ${BASE_FUNCTIONAL_FOLDER}/copy-remote && $(MAKE) test ; cd -
48-
60+
@echo
61+
@RC=0; \
62+
cd ${BASE_FUNCTIONAL_FOLDER}/copy-remote && $(MAKE) test || RC=1; \
63+
cd -; \
64+
exit $$RC;
4965

5066
unit-test: ## Run unitary tests
5167
@echo

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Changed
1010

11+
- On the examples, start the client container once and execute actions on it.
1112
- Bump github.com/docker/docker from v20.10+incompatible to v24.0.7+incompatible
1213
- Bump github.com/docker/distribution from v2.8.2+incompatible to v2.8.3+incompatible
1314
- Bump github.com/go-git/go-git/v5 from v5.6.1 to v5.10.0
Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,116 @@
1-
EXAMPLE=build-and-push-join-context
1+
EXAMPLE := $(shell basename ${PWD})
2+
GREEN := "\\033[32m"
3+
NC := "\\033[0m"
4+
DOCKER_COMPOSE_VERSION := $(shell docker compose version > /dev/null 2>&1 && echo "docker compose" || (which docker-compose > /dev/null 2>&1 && echo "docker-compose" || (echo "docker compose not found. Aborting." >&2; exit 1)))
25

36
help: ## list allowed targets
47
@echo
5-
@echo " Executing example ${EXAMPLE}"
8+
@echo "$(GREEN) Executing example $(EXAMPLE)$(NC)"
69
@echo
710
@grep -E '^[a-zA-Z1-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-20s\033[0m %s\n", $$1, $$2}'
811
@echo
912

10-
start: cleanup generate-keys generate-certs ## start docker registry
13+
start: cleanup generate-keys generate-certs ## Starts the stack
1114
@echo
12-
@echo " Start environment"
15+
@echo "$(GREEN) Starting the stack to run $(EXAMPLE)$(NC)"
1316
@echo
14-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml up --detach --build
17+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml up --detach --build
1518

16-
cleanup: ## cleanup example environment
19+
cleanup: ## Stops the stack
1720
@echo
18-
@echo " Cleanup environment"
21+
@echo "$(GREEN) Stopping the stack to run $(EXAMPLE)$(NC)"
1922
@echo
20-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml down --volume --remove-orphans --timeout 3
23+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml down --volumes --remove-orphans --timeout 3
2124

22-
generate-keys: cleanup-keys ## generate an ssh key pair required to autheneticate to git server
25+
generate-keys: cleanup-keys ## Generates an ssh key pair required to autheneticate to git server
2326
@echo
24-
@echo " Generate ssh key pair"
27+
@echo "$(GREEN) Generate ssh key pair for $(EXAMPLE)$(NC)"
2528
@echo
2629
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm openssh -t rsa -q -N "password" -f id_rsa -C "[email protected]"
2730

28-
cleanup-keys: ## cleanup the ssh key pair
31+
cleanup-keys: ## Cleans up the ssh key pair
2932
@echo
30-
@echo " Cleanup ssh key pair"
33+
@echo "$(GREEN) Cleanup ssh key pair for $(EXAMPLE)$(NC)"
3134
@echo
3235
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm --entrypoint /bin/sh openssh -c 'rm -rf $$(ls)'
3336

34-
generate-certs: cleanup-certs ## generate certificate for go-docker-builder.test
37+
generate-certs: cleanup-certs ## Generates certificate for go-docker-builder.test
3538
@echo
36-
@echo " Generate certificates"
39+
@echo "$(GREEN) Generate certificates for $(EXAMPLE)$(NC)"
3740
@echo
38-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm openssl req -newkey rsa:2048 -nodes -keyout go-docker-builder.test.key -out go-docker-builder.test.csr -config /root/ssl/go-docker-builder.test.cnf
39-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm openssl x509 -signkey go-docker-builder.test.key -in go-docker-builder.test.csr -req -days 365 -out go-docker-builder.test.crt -extensions req_ext -extfile /root/ssl/go-docker-builder.test.cnf
41+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml run --rm openssl req -newkey rsa:2048 -nodes -keyout go-docker-builder.test.key -out go-docker-builder.test.csr -config /root/ssl/go-docker-builder.test.cnf
42+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml run --rm openssl x509 -signkey go-docker-builder.test.key -in go-docker-builder.test.csr -req -days 365 -out go-docker-builder.test.crt -extensions req_ext -extfile /root/ssl/go-docker-builder.test.cnf
4043

41-
cleanup-certs: ## cleanup certificates
44+
cleanup-certs: ## Cleans up certificates
4245
@echo
43-
@echo " Cleanup certificates"
46+
@echo "$(GREEN) Cleanup certificates $(EXAMPLE)$(NC)"
4447
@echo
45-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm --entrypoint /bin/sh openssl -c 'rm -rf $$(ls)'
48+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml run --rm --entrypoint /bin/sh openssl -c 'rm -rf $$(ls)'
4649

47-
prepare: ## prepare docker images required to run the example or test
50+
prepare: start ## Prepares Docker images required to run the example or test
4851
@echo
49-
@echo " Prepare"
52+
@echo "$(GREEN) Prepare Docker images for $(EXAMPLE)$(NC)"
5053
@echo
51-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run client sh -c 'docker pull base-registry.go-docker-builder.test:5000/alpine:3.13 \
54+
55+
@echo " [$(EXAMPLE)]$(GREEN) Waiting for dockerd$(NC)"
56+
@for i in $$(seq 1 5); \
57+
do $(DOCKER_COMPOSE_VERSION) -p $(EXAMPLE) exec client /usr/local/bin/wait-for-dockerd.sh && RC=0 && break || RC=$$? && $(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml restart client --timeout 3; \
58+
done || { echo " Error synchronizing $(EXAMPLE)"; exit $$RC; }
59+
@echo
60+
61+
@echo " [$(EXAMPLE)]$(GREEN) Pulling Docker images$(NC)"
62+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml exec client sh -c 'docker pull base-registry.go-docker-builder.test:5000/alpine:3.13 \
5263
|| ( docker pull alpine:3.13 \
5364
&& docker tag alpine:3.13 base-registry.go-docker-builder.test:5000/alpine:3.13 \
5465
&& docker push base-registry.go-docker-builder.test:5000/alpine:3.13)'
55-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run client sh -c 'docker pull base-registry.go-docker-builder.test:5000/golang:1.15-alpine \
66+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml exec client sh -c 'docker pull base-registry.go-docker-builder.test:5000/golang:1.15-alpine \
5667
|| ( docker pull golang:1.15-alpine \
5768
&& docker tag golang:1.15-alpine base-registry.go-docker-builder.test:5000/golang:1.15-alpine \
5869
&& docker push base-registry.go-docker-builder.test:5000/golang:1.15-alpine)'
70+
@echo
71+
72+
73+
example: prepare ## Executes the examples
74+
@echo
75+
@echo "$(GREEN) Run example $(EXAMPLE)$(NC)"
76+
@echo
77+
78+
@echo " [$(EXAMPLE)]$(GREEN) Waiting for dockerd$(NC)"
79+
@$(DOCKER_COMPOSE_VERSION) -p $(EXAMPLE) exec client /usr/local/bin/wait-for-dockerd.sh || { echo " Error synchronizing $(EXAMPLE)"; exit 1; }
80+
@echo
81+
82+
@echo " [$(EXAMPLE)]$(GREEN) Executing the example$(NC)"
83+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml exec --workdir /app/examples/$(EXAMPLE) client go run $(EXAMPLE).go -test
84+
@echo
85+
86+
@echo " [$(EXAMPLE)]$(GREEN) Cleanup the stack$(NC)"
87+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml down --volumes --remove-orphans --timeout 3
88+
@echo
5989

60-
example: start prepare ## executes the examples
90+
test: prepare ## Executes functional test
6191
@echo
62-
@echo " Example"
92+
@echo "$(GREEN) Testing $(EXAMPLE)$(NC)"
93+
@echo
94+
95+
@echo " [$(EXAMPLE)]$(GREEN) Waiting for dockerd$(NC)"
96+
@$(DOCKER_COMPOSE_VERSION) -p $(EXAMPLE) exec client /usr/local/bin/wait-for-dockerd.sh || { echo " Error synchronizing $(EXAMPLE)"; exit 1; }
97+
@echo
98+
99+
@echo " [$(EXAMPLE)]$(GREEN) Running tests$(NC)"
100+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml exec --workdir /app/examples/$(EXAMPLE) client go test . -count=1 || RC=1; \
101+
echo; echo " [$(EXAMPLE)]$(GREEN) Cleanup the stack$(NC)"; echo && \
102+
$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml down --volumes --remove-orphans --timeout 3; \
103+
exit $$RC;
63104
@echo
64-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --build --workdir /app/examples/${EXAMPLE} client go run ${EXAMPLE}.go
65-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml down --volume --remove-orphans --timeout 3
66105

67-
test: start prepare ## executes the examples
106+
logs: ## Show services logs
68107
@echo
69-
@echo " Test"
108+
@echo "$(GREEN) Logs for $(EXAMPLE)$(NC)"
70109
@echo
71-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --build --workdir /app/examples/${EXAMPLE} client go test . -count=1
72-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml down --volume --remove-orphans --timeout 3
110+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml logs
73111

74-
logs: ## show services logs
112+
follow-logs: ## Follow services logs
75113
@echo
76-
@echo " Logs"
114+
@echo "$(GREEN) Follow logs for $(EXAMPLE)$(NC)"
77115
@echo
78-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml logs
116+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml logs --follow

examples/build-and-push-join-context/build-and-push-join-context_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ func TestBuildAndPushJoinContext(t *testing.T) {
1919
t.Error(err.Error())
2020
}
2121

22-
expected := `1.15-alpine: Pulling from golang
22+
// expected := `1.15-alpine: Pulling from golang
23+
// <HASH>: Pushed
24+
// Digest: sha256
25+
// Status: Downloaded newer image for base-registry.go-docker-builder.test
26+
// sha256: <HASH>
27+
// latest: digest
28+
// `
29+
30+
expected := `sha256: <HASH>
2331
<HASH>: Pushed
24-
Digest: sha256
25-
Status: Downloaded newer image for base-registry.go-docker-builder.test
26-
sha256: <HASH>
2732
latest: digest
2833
`
34+
2935
actual := helper.SanitizeDockerOutputForIntegrationTest(&buff)
3036

3137
assert.Equal(t, expected, actual)

examples/build-and-push/Makefile

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,99 @@
1-
EXAMPLE=build-and-push
1+
EXAMPLE := $(shell basename ${PWD})
2+
GREEN := "\\033[32m"
3+
NC := "\\033[0m"
4+
DOCKER_COMPOSE_VERSION := $(shell docker compose version > /dev/null 2>&1 && echo "docker compose" || (which docker-compose > /dev/null 2>&1 && echo "docker-compose" || (echo "docker compose not found. Aborting." >&2; exit 1)))
25

36
help: ## list allowed targets
47
@echo
5-
@echo " Executing example ${EXAMPLE}"
8+
@echo "$(GREEN) Executing example $(EXAMPLE)$(NC)"
69
@echo
710
@grep -E '^[a-zA-Z1-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-20s\033[0m %s\n", $$1, $$2}'
811
@echo
912

10-
start: cleanup generate-certs ## start docker registry
13+
start: cleanup generate-certs ## Starts the stack
1114
@echo
12-
@echo " Start environment"
15+
@echo "$(GREEN) Starting the stack to run $(EXAMPLE)$(NC)"
1316
@echo
14-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml up --detach --build
17+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml up --detach --build
1518

16-
cleanup: ## cleanup example environment
19+
cleanup: ## Stops the stack
1720
@echo
18-
@echo " Cleanup environment"
21+
@echo "$(GREEN) Stopping the stack to run $(EXAMPLE)$(NC)"
1922
@echo
20-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml down --volume --remove-orphans --timeout 3
23+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml down --volumes --remove-orphans --timeout 3
2124

22-
generate-certs: cleanup-certs ## generate certificate for go-docker-builder.test
25+
generate-certs: cleanup-certs ## Generates certificate for go-docker-builder.test
2326
@echo
24-
@echo " Generate certificates"
27+
@echo "$(GREEN) Generate certificates for $(EXAMPLE)$(NC)"
2528
@echo
26-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm openssl req -newkey rsa:2048 -nodes -keyout go-docker-builder.test.key -out go-docker-builder.test.csr -config /root/ssl/go-docker-builder.test.cnf
27-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm openssl x509 -signkey go-docker-builder.test.key -in go-docker-builder.test.csr -req -days 365 -out go-docker-builder.test.crt -extensions req_ext -extfile /root/ssl/go-docker-builder.test.cnf
29+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml run --rm openssl req -newkey rsa:2048 -nodes -keyout go-docker-builder.test.key -out go-docker-builder.test.csr -config /root/ssl/go-docker-builder.test.cnf
30+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml run --rm openssl x509 -signkey go-docker-builder.test.key -in go-docker-builder.test.csr -req -days 365 -out go-docker-builder.test.crt -extensions req_ext -extfile /root/ssl/go-docker-builder.test.cnf
2831

29-
cleanup-certs: ## cleanup certificates
32+
cleanup-certs: ## Cleans up certificates
3033
@echo
31-
@echo " Cleanup certificates"
34+
@echo "$(GREEN) Cleanup certificates $(EXAMPLE)$(NC)"
3235
@echo
33-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm --entrypoint /bin/sh openssl -c 'rm -rf $$(ls)'
36+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml run --rm --entrypoint /bin/sh openssl -c 'rm -rf $$(ls)'
3437

35-
prepare: ## prepare docker images required to run the example or test
38+
prepare: start ## Prepares Docker images required to run the example or test
3639
@echo
37-
@echo " Prepare"
40+
@echo "$(GREEN) Prepare Docker images for $(EXAMPLE)$(NC)"
3841
@echo
39-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run client sh -c 'docker pull base-registry.go-docker-builder.test:5000/alpine:3.13 \
42+
43+
@echo " [$(EXAMPLE)]$(GREEN) Waiting for dockerd$(NC)"
44+
@for i in $$(seq 1 5); \
45+
do $(DOCKER_COMPOSE_VERSION) -p $(EXAMPLE) exec client /usr/local/bin/wait-for-dockerd.sh && RC=0 && break || RC=$$? && $(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml restart client --timeout 3; \
46+
done || { echo " Error synchronizing $(EXAMPLE)"; exit $$RC; }
47+
@echo
48+
49+
@echo " [$(EXAMPLE)]$(GREEN) Pulling Docker images$(NC)"
50+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml exec client sh -c 'docker pull base-registry.go-docker-builder.test:5000/alpine:3.13 \
4051
|| ( docker pull alpine:3.13 \
4152
&& docker tag alpine:3.13 base-registry.go-docker-builder.test:5000/alpine:3.13 \
4253
&& docker push base-registry.go-docker-builder.test:5000/alpine:3.13)'
54+
@echo
55+
56+
example: prepare ## Executes the examples
57+
@echo
58+
@echo "$(GREEN) Run example $(EXAMPLE)$(NC)"
59+
@echo
60+
61+
@echo " [$(EXAMPLE)]$(GREEN) Waiting for dockerd$(NC)"
62+
@$(DOCKER_COMPOSE_VERSION) -p $(EXAMPLE) exec client /usr/local/bin/wait-for-dockerd.sh || { echo " Error synchronizing $(EXAMPLE)"; exit 1; }
63+
@echo
4364

44-
example: start prepare ## executes the examples
65+
@echo " [$(EXAMPLE)]$(GREEN) Executing the example$(NC)"
66+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml exec --workdir /app/examples/$(EXAMPLE) client go run $(EXAMPLE).go -test
4567
@echo
46-
@echo " Example"
68+
69+
@echo " [$(EXAMPLE)]$(GREEN) Cleanup the stack$(NC)"
70+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml down --volumes --remove-orphans --timeout 3
71+
@echo
72+
73+
test: prepare ## Executes functional test
74+
@echo
75+
@echo "$(GREEN) Testing $(EXAMPLE)$(NC)"
76+
@echo
77+
78+
@echo " [$(EXAMPLE)]$(GREEN) Waiting for dockerd$(NC)"
79+
@$(DOCKER_COMPOSE_VERSION) -p $(EXAMPLE) exec client /usr/local/bin/wait-for-dockerd.sh || { echo " Error synchronizing $(EXAMPLE)"; exit 1; }
80+
@echo
81+
82+
@echo " [$(EXAMPLE)]$(GREEN) Running tests$(NC)"
83+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml exec --workdir /app/examples/$(EXAMPLE) client go test . -count=1 || RC=1; \
84+
echo; echo " [$(EXAMPLE)]$(GREEN) Cleanup the stack$(NC)"; echo && \
85+
$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml down --volumes --remove-orphans --timeout 3; \
86+
exit $$RC;
4787
@echo
48-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --build --workdir /app/examples/${EXAMPLE} client go run ${EXAMPLE}.go -test
49-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml down --volume --remove-orphans --timeout 3
5088

51-
test: start prepare ## executes functional test
89+
logs: ## Show services logs
5290
@echo
53-
@echo " Test"
91+
@echo "$(GREEN) Logs for $(EXAMPLE)$(NC)"
5492
@echo
55-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --build --workdir /app/examples/${EXAMPLE} client go test . -count=1
56-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml down --volume --remove-orphans --timeout 3
93+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml logs
5794

58-
logs: ## show services logs
95+
follow-logs: ## Follow services logs
5996
@echo
60-
@echo " Logs"
97+
@echo "$(GREEN) Follow logs for $(EXAMPLE)$(NC)"
6198
@echo
62-
@docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml logs
99+
@$(DOCKER_COMPOSE_VERSION) --project-name $(EXAMPLE) --file ../../test/docker-compose.yml logs --follow

0 commit comments

Comments
 (0)