forked from elastic/apm-integration-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
152 lines (117 loc) · 4.64 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
SHELL := /bin/bash
PYTHON ?= python3
VENV ?= ./venv
COMPOSE_ARGS ?=
JUNIT_RESULTS_DIR=tests/results
JUNIT_OPT=--junitxml $(JUNIT_RESULTS_DIR)
CERT_VALID_DAYS ?= 3650
APM_SERVER_URL ?= http://apm-server:8200
ES_URL ?= http://elasticsearch:9200
KIBANA_URL ?= http://kibana:5601
DJANGO_URL ?= http://djangoapp:8003
DOTNET_URL ?= http://dotnetapp:8100
EXPRESS_URL ?= http://expressapp:8010
FLASK_URL ?= http://flaskapp:8001
GO_NETHTTP_URL ?= http://gonethttpapp:8080
JAVA_SPRING_URL ?= http://javaspring:8090
RAILS_URL ?= http://railsapp:8020
RUM_URL ?= http://rum:8000
ES_USER ?= elastic
ES_PASS ?= changeme
ELASTIC_APM_SECRET_TOKEN ?= SuPeRsEcReT
PYTHONHTTPSVERIFY ?= 1
# Make sure we run local versions of everything, particularly commands
# installed into our virtualenv with pip eg. `docker-compose`.
export PATH := ./bin:$(VENV)/bin:$(PATH)
export APM_SERVER_URL := $(APM_SERVER_URL)
export KIBANA_URL := $(KIBANA_URL)
export ES_URL := $(ES_URL)
export ES_USER := $(ES_USER)
export ES_PASS := $(ES_PASS)
export ELASTIC_APM_SECRET_TOKEN := $(ELASTIC_APM_SECRET_TOKEN)
export PYTHONHTTPSVERIFY := $(PYTHONHTTPSVERIFY)
all: test
# The tests are written in Python. Make a virtualenv to handle the dependencies.
# make doesn't play nicely with custom VENV, intended only for CI usage
venv: requirements.txt
test -d $(VENV) || virtualenv -q --python=$(PYTHON) $(VENV);\
source $(VENV)/bin/activate || exit 1;\
pip install -q -r requirements.txt;\
touch $(VENV);\
lint: venv
flake8 --ignore=D100,D101,D102,D103,D104,D105,D106,D107,D200,D205,D400,D401,D403,W504 tests/ scripts/compose.py scripts/modules
.PHONY: create-x509-cert
create-x509-cert:
openssl req -x509 -newkey rsa:4096 -keyout scripts/tls/key.pem -out scripts/tls/cert.crt -days "${CERT_VALID_DAYS}" -subj '/CN=apm-server' -nodes
.PHONY: lint
start-env: venv
$(PYTHON) scripts/compose.py start $(COMPOSE_ARGS)
docker-compose up -d
stop-env: venv
docker-compose down -v --remove-orphans || true
destroy-env: venv
[ -n "$(docker ps -aqf network=apm-integration-testing)" ] && (docker ps -aqf network=apm-integration-testing | xargs -t docker rm -f && docker network rm apm-integration-testing) || true
# default (all) started for now
env-%: venv
$(MAKE) start-env
test: test-all
test-agent-%-version: venv
pytest tests/agent/test_$*.py -v -s -m version $(JUNIT_OPT)/agent-$*-version-junit.xml
test-agent-%: venv
pytest tests/agent/test_$*.py -v -s $(JUNIT_OPT)/agent-$*-junit.xml
test-compose: venv
pytest scripts/tests/*_tests.py -v -s $(JUNIT_OPT)/compose-junit.xml
test-compose-2:
virtualenv --python=python2.7 venv2
./venv2/bin/pip2 install mock pytest pyyaml
./venv2/bin/pytest --noconftest scripts/tests/*_tests.py
test-kibana: venv
pytest tests/kibana/test_integration.py -v -s $(JUNIT_OPT)/kibana-junit.xml
test-server: venv
pytest tests/server/ -v -s $(JUNIT_OPT)/server-junit.xml
test-upgrade: venv
pytest tests/server/test_upgrade.py -v -s $(JUNIT_OPT)/server-junit.xml
SUBCOMMANDS = list-options load-dashboards start status stop upload-sourcemap versions
test-helps:
$(foreach subcommand,$(SUBCOMMANDS), $(PYTHON) scripts/compose.py $(subcommand) --help >/dev/null || exit 1;)
test-all: venv test-compose lint test-helps
pytest -v -s $(JUNIT_OPT)/all-junit.xml
docker-compose-wait: venv
docker-compose-wait || (docker ps -a && exit 1)
docker-test-%:
TARGET=test-$* $(MAKE) dockerized-test
dockerized-test:
@echo waiting for services to be healthy
$(MAKE) docker-compose-wait || (./scripts/docker-summary.sh; echo "[ERROR] Failed waiting for all containers are healthy"; exit 1)
./scripts/docker-summary.sh
@echo running make $(TARGET) inside a container
docker build --pull -t apm-integration-testing .
mkdir -p -m 777 "$(PWD)/$(JUNIT_RESULTS_DIR)"
chmod 777 "$(PWD)/$(JUNIT_RESULTS_DIR)"
docker run \
--name=apm-integration-testing \
--network=apm-integration-testing \
--security-opt seccomp=unconfined \
-e APM_SERVER_URL=$${APM_SERVER_URL} \
-e ES_URL=$${ES_URL} \
-e KIBANA_URL=$${KIBANA_URL} \
-e DJANGO_URL=$(DJANGO_URL) \
-e DOTNET_URL=$(DOTNET_URL) \
-e EXPRESS_URL=$(EXPRESS_URL) \
-e FLASK_URL=$(FLASK_URL) \
-e GO_NETHTTP_URL=$(GO_NETHTTP_URL) \
-e JAVA_SPRING_URL=$(JAVA_SPRING_URL) \
-e RAILS_URL=$(RAILS_URL) \
-e RUM_URL=$(RUM_URL) \
-e PYTHONDONTWRITEBYTECODE=1 \
-e PYTHONHTTPSVERIFY=$(PYTHONHTTPSVERIFY) \
-e ENABLE_ES_DUMP=$(ENABLE_ES_DUMP) \
-e ES_USER=$${ES_USER} \
-e ES_PASS=$${ES_PASS} \
-e ELASTIC_APM_SECRET_TOKEN=$${ELASTIC_APM_SECRET_TOKEN} \
-v "$(PWD)/$(JUNIT_RESULTS_DIR)":"/app/$(JUNIT_RESULTS_DIR)" \
--rm \
--entrypoint make \
apm-integration-testing \
$(TARGET)
.PHONY: test-% docker-test-% dockerized-test docker-compose-wait