Skip to content

Commit bc7a877

Browse files
author
Nick Zaccardi
authored
MAINT: Run CI with Docker
2 parents 7e94815 + 9c8cdd9 commit bc7a877

File tree

5 files changed

+115
-10
lines changed

5 files changed

+115
-10
lines changed

circle.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
---
2-
31
machine:
42
services:
5-
- postgresql
3+
- docker
64

75
dependencies:
8-
post:
9-
- pip install tox-pyenv
10-
- pyenv local 2.7.11 3.5.1
6+
override:
7+
# We override the dependencies section so that CircleCI doesn't find the
8+
# setup.py and install the dependencies. This is mostly an issue with
9+
# libraries but can carry over into applications as well. (NZ)
10+
- pwd
1111

1212
test:
13-
post:
14-
- pip install codecov && codecov
15-
- mv *.pytests.xml $CIRCLE_TEST_REPORTS
13+
override:
14+
- ls -la
15+
- /home/ubuntu/$CIRCLE_PROJECT_REPONAME/docker-run-tests
16+
17+
deployment:
18+
codecov:
19+
branch: /.*/
20+
commands:
21+
- bash <(curl -s https://codecov.io/bash)

codecov.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
codecov:
2+
bot: level12-codecov-bot
3+
notify:
4+
require_ci_to_pass: true
5+
6+
comment:
7+
behavior: default
8+
layout: header, diff
9+
require_changes: false
10+
11+
coverage:
12+
precision: 2
13+
range:
14+
- 70.0
15+
- 100.0
16+
round: down
17+
status:
18+
changes: false
19+
patch: true
20+
project: true
21+
22+
parsers:
23+
gcov:
24+
branch_detection:
25+
conditional: true
26+
loop: true
27+
macro: false
28+
method: false
29+
javascript:
30+
enable_partials: false

docker-entry

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# This script is ran by the docker image. It does any necessary setup and should then kick-off
5+
# whatever tests you want ran by CI, presumably by using tox. However, you can customize as
6+
# needed.
7+
#
8+
# Image Modification Notice: if you find yourself needing to modify the OS in any way, e.g.
9+
# `apt-get install ...`, this probably isn't the place to do that. It would be better to get
10+
# the docker image that you are using for testing updated to have your modifications.
11+
# While you can technically do it here and it will probably work, it's much slower to have to do
12+
# that modification every time the tests run than to rebuild the docker image with the changes
13+
# needed.
14+
15+
# just some debugging info
16+
pwd
17+
ls -la
18+
19+
# Install tox from the wheelhouse using our target python version.
20+
# You could skip this step and use the tox installed in the docker image. I (RS) like this option
21+
# b/c it gives me control over what version of tox I'm using without having to rebuild the
22+
# docker image.
23+
python3.5 -m pip install --upgrade --force-reinstall \
24+
--quiet --use-wheel --no-index --find-links=requirements/wheelhouse tox
25+
26+
# run the tests using our target python version
27+
python3.5 -m tox -e py27,py35,flake8

docker-run-tests

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# This script is used to run tox in the same docker container and in the same manner that our CI
3+
# will run tox. If tox is passing locally, but CI is failing, use this script to troubleshoot.
4+
5+
set -e
6+
7+
if [ -z "${CIRCLECI}" ]; then
8+
# When testing locally, don't actually run docker mapped to the real source directory. Since
9+
# Docker runs as root, the file permissions get jacked up and you have to use sudo to fix it.
10+
# Instead, git clone the source to a temporary directory and link the docker volume to that.
11+
# This also simulates what CircleCI does and will reveal testing errors caused by files
12+
# that exist locally but have not been checked into git.
13+
local_src_dpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14+
src_dname=$(basename "$local_src_dpath")
15+
random_st=$(env LC_CTYPE=C tr -dc 'a-zA-Z0-9' < /dev/urandom| fold -w 8 | head -n 1)
16+
tmp_src_dpath="/tmp/docker-$src_dname-$random_st"
17+
18+
SRC_DPATH=$tmp_src_dpath
19+
ARTIFACTS_DPATH="$tmp_src_dpath/.ci/artifacts"
20+
TEST_REPORTS_DPATH="$tmp_src_dpath/.ci/test-reports"
21+
22+
set -x
23+
git clone "$local_src_dpath/" "$tmp_src_dpath"
24+
else
25+
SRC_DPATH="/home/ubuntu/$CIRCLE_PROJECT_REPONAME"
26+
ARTIFACTS_DPATH=$CIRCLE_ARTIFACTS
27+
TEST_REPORTS_DPATH=$CIRCLE_TEST_REPORTS
28+
29+
DATABASE_HOST=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
30+
DOCKER_FLAGS="--add-host=database:$DATABASE_HOST"
31+
fi
32+
33+
set -x
34+
docker run \
35+
-v "$SRC_DPATH:/opt/src" \
36+
-v "$ARTIFACTS_DPATH:/opt/src/.ci/artifacts" \
37+
-v "$TEST_REPORTS_DPATH:/opt/src/.ci/test-reports" \
38+
"$DOCKER_FLAGS" \
39+
level12/python-test-multi
40+
41+
ls "$ARTIFACTS_DPATH"
42+
ls "$TEST_REPORTS_DPATH"

keg_apps/db/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class TestProfile(object):
1414
# The postgres connection defaults to what our travis build needs. If testing as a
1515
# developer, then you should setup a TestProfile config for these tests in
1616
# file: ~/.config/keg_apps.db/keg_apps.db-config.py
17-
'postgres': 'postgresql://ubuntu:@localhost/circle_test',
17+
'postgres': 'postgresql://ubuntu:@database/circle_test',
1818
'sqlite2': 'sqlite:///'
1919
}

0 commit comments

Comments
 (0)