-
Notifications
You must be signed in to change notification settings - Fork 1
/
circle.yml
133 lines (130 loc) · 5.63 KB
/
circle.yml
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
machine:
pre:
# Configure elasticsearch circle service.
- sudo cp -v "/home/ubuntu/xp-days-hamburg/test/service-elasticsearch.yml" "/etc/elasticsearch/elasticsearch.yml"; cat $_
hosts:
elasticsearch.circleci.com: 127.0.0.1
services:
- elasticsearch
- docker
environment:
# Circle run tests with parallelism.
CIRCLE_PARALLEL: true
# Tests use dedicated docker containers, log directories and elasticsearch indexes.
TEST_SAMPLE: "logstash-test-process-sample"
TEST_PRODUCTION: "logstash-test-deploy-production"
# Tests use same sample log file.
TEST_LOG: "sample.json"
# Docker run options are set to detach to background and share network addresses from host to container.
LS_DOCKER_REMOVE: false
LS_DOCKER_DETACH: true
LS_DOCKER_NETWORK: true
# Docker build image.
LS_DOCKER_REPO: "logstash"
LS_DOCKER_TAG: "latest"
# Logstash input and output types, info and error log files.
LS_INPUT: "log"
LS_OUTPUT: "log,elasticsearch"
LS_INFO: "logstash-info.json"
LS_ERROR: "logstash-error.json"
# Elasticsearch is needed for integration test.
ES_HOSTS: "[ 'elasticsearch.circleci.com:9200' ]"
ES_CONF: "/etc/elasticsearch/elasticsearch.yml"
ES_LOG: "/var/log/elasticsearch/elasticsearch.log"
dependencies:
cache_directories:
- "~/docker"
override:
# Docker environment used.
- docker info
# Load cached images, if available.
- if [[ -e ~/docker/image.tar ]]; then docker load --input ~/docker/image.tar; fi
# Build our image.
- ./build.sh
# Save built image into cache.
- mkdir -v -p ~/docker; docker save "${LS_DOCKER_REPO}:${LS_DOCKER_TAG}" > ~/docker/image.tar
# Make sure circle project parallelism is set to at least 2 nodes.
- |
if [[ "${CIRCLE_NODE_TOTAL}" -eq "1" ]]; then {
echo "Parallelism [${CIRCLE_NODE_TOTAL}x] needs to be 2x to fasten execution time."
echo "You also need to set our circle env CIRCLE_PARALLEL [${CIRCLE_PARALLEL}] to true."
}; fi
post:
# Check if elasticsearch is there
- sleep 10 && curl --retry 10 --retry-delay 5 -v http://127.0.0.1:9200/
test:
override:
- ? >
case $CIRCLE_NODE_INDEX in
0)
printf "\n%s\n" "+++ Begin test of docker container [${TEST_SAMPLE}] +++"
printf "\n%s\n\n" "=== Prepare test and setup config and log dirs on host ==="
export LS_DOCKER_CONTAINER="${TEST_SAMPLE}"
export LS_LOG="/usr/${TEST_SAMPLE}/log"
export LS_CONFIG="/tmp/${TEST_SAMPLE}/config"
export ES_INDEX="${TEST_SAMPLE}"
mkdir -v -p ${LS_LOG} ${LS_CONFIG}
cp -v -r config/* ${LS_CONFIG}/
cp -v test/${TEST_LOG} ${LS_LOG}/
printf "\n%s\n" "--- Prepare test completed."
# Fire up the container
./start.sh; [[ $? -eq 1 ]] && exit 1
sleep 50;
# Stop the container.
./stop.sh; [[ $? -eq 1 ]] && exit 1
# Test metrics from files including input, output and errors.
./test/test-metrics-from-files.sh; [[ $? -eq 1 ]] && exit 1
# Test metrics form elasticsearch including input, template and documents.
./test/test-metrics-from-elasticsearch.sh; [[ $? -eq 1 ]] && exit 1
printf "\n%s\n" "+++ End test of docker container [${TEST_SAMPLE}] +++"
# Exit case statement if run in parallel else proceed to next case.
$CIRCLE_PARALLEL && exit 0
;&
1)
printf "\n%s\n" "+++ Begin test of [${TEST_PRODUCTION}] +++"
printf "\n%s\n\n" "=== Prepare test and setup config and log dirs on host ==="
export LS_DOCKER_CONTAINER="${TEST_PRODUCTION}"
export LS_LOG="/tmp/${TEST_PRODUCTION}/log"
export LS_CONFIG="/tmp/${TEST_PRODUCTION}/config"
export ES_INDEX="${TEST_PRODUCTION}"
mkdir -v -p ${LS_LOG} ${LS_CONFIG}
cp -v -r config/* ${LS_CONFIG}/
cp -v test/${TEST_LOG} ${LS_LOG}/
printf "\n%s\n" "--- Prepare test completed."
# Run the full deploy script as used in jenkins.
./deploy.sh; [[ $? -eq 1 ]] && exit 1
# Test metrics from files including input, output and errors.
./test/test-metrics-from-files.sh; [[ $? -eq 1 ]] && exit 1
# Test metrics form elasticsearch including input, template and documents.
./test/test-metrics-from-elasticsearch.sh; [[ $? -eq 1 ]] && exit 1
printf "\n%s\n" "+++ End test of [${TEST_PRODUCTION}] +++"
# Exit case statement if run in parallel else proceed to next case.
$CIRCLE_PARALLEL && exit 0
;&
esac
: parallel: true
post:
- ? >
case $CIRCLE_NODE_INDEX in
0)
printf "\n%s\n\n" "=== Archive artifacts of [${TEST_SAMPLE}] ==="
sudo mv -v -f "/tmp/${TEST_SAMPLE}" "${CIRCLE_ARTIFACTS}/"
mkdir -v -p "${CIRCLE_ARTIFACTS}/${TEST_SAMPLE}/services"
sudo cp -v "${ES_CONF}" "${ES_LOG}" $_
# Exit case statement if run in parallel else proceed to next case.
$CIRCLE_PARALLEL && exit 0
;&
1)
printf "\n%s\n\n" "=== Archive artifacts of [${TEST_PRODUCTION}] ==="
sudo mv -v -f "/tmp/${TEST_PRODUCTION}" "${CIRCLE_ARTIFACTS}/"
mkdir -v -p "${CIRCLE_ARTIFACTS}/${TEST_PRODUCTION}/services"
sudo cp -v "${ES_CONF}" "${ES_LOG}" $_
# Exit case statement if run in parallel else proceed to next case.
$CIRCLE_PARALLEL && exit 0
;&
esac
: parallel: true
general:
artifacts:
- "${CIRCLE_ARTIFACTS}/${LS_DOCKER_TEST_SAMPLE}"
- "${CIRCLE_ARTIFACTS}/${LS_DOCKER_TEST_PRODUCTION}"