Skip to content

Commit 4566b76

Browse files
committed
added ci config
1 parent abb96cb commit 4566b76

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

.circleci/config.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
# Use the latest 2.1 version of CircleCI pipeline process engine. See:
3+
# https://circleci.com/docs/2.0/configuration-reference
4+
version: 2.1
5+
orbs:
6+
codecov: codecov/codecov@4.1.0
7+
# Orchestrate or schedule a set of jobs
8+
workflows:
9+
docker-compose:
10+
jobs:
11+
- build-and-test
12+
jobs:
13+
build-and-test:
14+
machine: true
15+
resource_class: large
16+
steps:
17+
- run:
18+
name: docker-compose version
19+
command: docker-compose --version
20+
- run:
21+
command: |
22+
git clone https://github.com/metacpan/metacpan-docker.git
23+
cd metacpan-docker
24+
name: metacpan-docker checkout
25+
- checkout:
26+
path: metacpan-docker/src/metacpan-ingest
27+
- run:
28+
command: |
29+
pushd metacpan-docker
30+
./bin/metacpan-docker init
31+
name: clone missing repositories
32+
- run:
33+
command: |
34+
pushd metacpan-docker
35+
docker-compose build --build-arg CPM_ARGS='--with-test' insgest_test
36+
name: compose build
37+
- run:
38+
command: |
39+
pushd metacpan-docker
40+
./bin/metacpan-docker init
41+
docker-compose --verbose up -d ingest_test
42+
name: compose up
43+
- run:
44+
command: |
45+
pushd metacpan-docker
46+
docker-compose exec -T ingest_test cpm install -g Devel::Cover
47+
name: install Devel::Cover
48+
# Since we're running docker-compose -d, we don't actually know if
49+
# Elasticsearch is available at the time this build step begins. We
50+
# probably need to wait for it here, so we'll add our own check.
51+
- run:
52+
command: |
53+
pushd metacpan-docker
54+
./src/metacpan-ingest/wait-for-es.sh http://localhost:9200 elasticsearch_test
55+
name: wait for ES
56+
- run:
57+
command: |
58+
pushd metacpan-docker
59+
docker-compose exec -T ingest_test env PLACK_ENV='dev' HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,^t/|^test-data/|^etc/" prove -lr --jobs 4 t
60+
name: run tests with coverage
61+
# We are relying on environment variables from the host to be available when
62+
# we publish the report, so we publish from the host rather than trying
63+
# to propagate env variables to the container.
64+
- run:
65+
command: |
66+
pushd metacpan-docker
67+
docker-compose exec -T ingest_test cover -report json
68+
name: create coverage report
69+
- codecov/upload:
70+
file: metacpan-docker/src/metacpan-ingest/cover_db/cover.json
71+
- run:
72+
command: |
73+
pushd metacpan-docker
74+
docker-compose logs
75+
docker stats --no-stream
76+
docker ps -a | head
77+
name: docker-compose logs
78+
when: on_fail

wait-for-es.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# Courtesy of @fxdgear
4+
# https://github.com/elastic/elasticsearch-py/issues/778#issuecomment-384389668
5+
6+
set -ux
7+
8+
9+
HOST="$1"
10+
CONTAINER=${2:-""}
11+
PREAMBLE=""
12+
13+
echo "container |$CONTAINER|"
14+
if [[ $CONTAINER != "" ]]; then
15+
PREAMBLE="docker-compose exec $CONTAINER"
16+
fi
17+
18+
while true; do
19+
response=$($PREAMBLE curl --write-out '%{http_code}' --silent --fail --output /dev/null "$HOST")
20+
if [[ "$response" -eq "200" ]]; then
21+
break
22+
fi
23+
24+
echo "Elastic Search is unavailable - sleeping" >&2
25+
sleep 1
26+
done
27+
28+
# set -e now because it was causing the curl command above to exit the script
29+
# if the server was not available
30+
set -e
31+
32+
COUNTER=0
33+
MAX_LOOPS=60
34+
while true; do
35+
## Wait for ES status to turn to yellow.
36+
## TODO: Ideally we'd be waiting for green, but we need multiple nodes for that.
37+
health=$($PREAMBLE curl -fsSL "$HOST/_cat/health?format=JSON" | jq '.[0].status == "yellow" or .[0].status == "green"')
38+
if [[ $health == 'true' ]]; then
39+
echo "Elasticsearch is up" >&2
40+
break
41+
fi
42+
echo "Elastic Search is unavailable ($health) - sleeping" >&2
43+
COUNTER=$((COUNTER + 1))
44+
if [[ $COUNTER -gt $MAX_LOOPS ]]; then
45+
echo "Giving up after $COUNTER attempts"
46+
exit 1
47+
break
48+
fi
49+
sleep 1
50+
done
51+
52+
# Allow commands to be chained
53+
shift
54+
shift
55+
exec "$@"

0 commit comments

Comments
 (0)