|
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))) |
2 | 5 |
|
3 | 6 | help: ## list allowed targets |
4 | 7 | @echo |
5 | | - @echo " Executing example ${EXAMPLE}" |
| 8 | + @echo "$(GREEN) Executing example $(EXAMPLE)$(NC)" |
6 | 9 | @echo |
7 | 10 | @grep -E '^[a-zA-Z1-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-20s\033[0m %s\n", $$1, $$2}' |
8 | 11 | @echo |
9 | 12 |
|
10 | | -start: cleanup generate-keys generate-certs ## start docker registry |
| 13 | +start: cleanup generate-keys generate-certs ## Starts the stack |
11 | 14 | @echo |
12 | | - @echo " Start environment" |
| 15 | + @echo "$(GREEN) Starting the stack to run $(EXAMPLE)$(NC)" |
13 | 16 | @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 |
15 | 18 |
|
16 | | -cleanup: ## cleanup example environment |
| 19 | +cleanup: ## Stops the stack |
17 | 20 | @echo |
18 | | - @echo " Cleanup environment" |
| 21 | + @echo "$(GREEN) Stopping the stack to run $(EXAMPLE)$(NC)" |
19 | 22 | @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 |
21 | 24 |
|
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 |
23 | 26 | @echo |
24 | | - @echo " Generate ssh key pair" |
| 27 | + @echo "$(GREEN) Generate ssh key pair for $(EXAMPLE)$(NC)" |
25 | 28 | @echo |
26 | 29 | @docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm openssh -t rsa -q -N "password" -f id_rsa -C "[email protected]" |
27 | 30 |
|
28 | | -cleanup-keys: ## cleanup the ssh key pair |
| 31 | +cleanup-keys: ## Cleans up the ssh key pair |
29 | 32 | @echo |
30 | | - @echo " Cleanup ssh key pair" |
| 33 | + @echo "$(GREEN) Cleanup ssh key pair for $(EXAMPLE)$(NC)" |
31 | 34 | @echo |
32 | 35 | @docker compose --project-name ${EXAMPLE} --file ../../test/docker-compose.yml run --rm --entrypoint /bin/sh openssh -c 'rm -rf $$(ls)' |
33 | 36 |
|
34 | | -generate-certs: cleanup-certs ## generate certificate for go-docker-builder.test |
| 37 | +generate-certs: cleanup-certs ## Generates certificate for go-docker-builder.test |
35 | 38 | @echo |
36 | | - @echo " Generate certificates" |
| 39 | + @echo "$(GREEN) Generate certificates for $(EXAMPLE)$(NC)" |
37 | 40 | @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 |
40 | 43 |
|
41 | | -cleanup-certs: ## cleanup certificates |
| 44 | +cleanup-certs: ## Cleans up certificates |
42 | 45 | @echo |
43 | | - @echo " Cleanup certificates" |
| 46 | + @echo "$(GREEN) Cleanup certificates $(EXAMPLE)$(NC)" |
44 | 47 | @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)' |
46 | 49 |
|
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 |
48 | 51 | @echo |
49 | | - @echo " Prepare" |
| 52 | + @echo "$(GREEN) Prepare Docker images for $(EXAMPLE)$(NC)" |
50 | 53 | @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 \ |
52 | 63 | || ( docker pull alpine:3.13 \ |
53 | 64 | && docker tag alpine:3.13 base-registry.go-docker-builder.test:5000/alpine:3.13 \ |
54 | 65 | && 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 \ |
56 | 67 | || ( docker pull golang:1.15-alpine \ |
57 | 68 | && docker tag golang:1.15-alpine base-registry.go-docker-builder.test:5000/golang:1.15-alpine \ |
58 | 69 | && 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 |
59 | 89 |
|
60 | | -example: start prepare ## executes the examples |
| 90 | +test: prepare ## Executes functional test |
61 | 91 | @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; |
63 | 104 | @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 |
66 | 105 |
|
67 | | -test: start prepare ## executes the examples |
| 106 | +logs: ## Show services logs |
68 | 107 | @echo |
69 | | - @echo " Test" |
| 108 | + @echo "$(GREEN) Logs for $(EXAMPLE)$(NC)" |
70 | 109 | @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 |
73 | 111 |
|
74 | | -logs: ## show services logs |
| 112 | +follow-logs: ## Follow services logs |
75 | 113 | @echo |
76 | | - @echo " Logs" |
| 114 | + @echo "$(GREEN) Follow logs for $(EXAMPLE)$(NC)" |
77 | 115 | @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 |
0 commit comments