Skip to content

Commit 63ebe69

Browse files
authored
tox integrations with invoke and docker (#1632)
1 parent e60d97e commit 63ebe69

File tree

12 files changed

+256
-95
lines changed

12 files changed

+256
-95
lines changed

.github/workflows/integration.yaml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,62 @@ name: CI
22

33
on:
44
push:
5+
paths-ignore:
6+
- 'docs/**'
7+
- '**/*.rst'
8+
- '**/*.md'
59
pull_request:
10+
paths-ignore:
11+
- 'docs/**'
12+
- '**/*.rst'
13+
- '**/*.md'
614

715
jobs:
8-
integration:
16+
17+
lint:
18+
name: Code linters
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: install python
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: 3.9
26+
- name: run code linters
27+
run: |
28+
pip install -r dev_requirements.txt
29+
invoke linters
30+
31+
run-tests:
32+
runs-on: ubuntu-latest
33+
strategy:
34+
max-parallel: 6
35+
matrix:
36+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy-3.7']
37+
env:
38+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
39+
name: Python ${{ matrix.python-version }} tests
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: install python
43+
uses: actions/setup-python@v2
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
- name: run tests
47+
run: |
48+
pip install -r dev_requirements.txt
49+
invoke tests
50+
51+
build_package:
52+
name: Validate building and installing the package
953
runs-on: ubuntu-latest
1054
steps:
1155
- uses: actions/checkout@v2
12-
- name: test
13-
run: make test
56+
- name: install python
57+
uses: actions/setup-python@v2
58+
with:
59+
python-version: 3.9
60+
- name: build and install
61+
run: |
62+
pip install invoke
63+
invoke package

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ vagrant/.vagrant
1414
env
1515
venv
1616
coverage.xml
17+
.venv

CONTRIBUTING.rst

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,36 @@ Here's how to get started with your code contribution:
2929

3030
1. Create your own fork of redis-py
3131
2. Do the changes in your fork
32-
3. If you need a development environment, run ``make dev``
33-
4. While developing, make sure the tests pass by running ``make test``
32+
3. Create a virtualenv and install the development dependencies from the dev_requirements.txt file:
33+
a. python -m venv .venv
34+
b. source .venv/bin/activate
35+
c. pip install -r dev_requirements.txt
36+
3. If you need a development environment, run ``invoke devenv``
37+
4. While developing, make sure the tests pass by running ``invoke tests``
3438
5. If you like the change and think the project could use it, send a pull request
3539

40+
To see what else is part of the automation, run ``invoke -l``
41+
3642
The Development Environment
3743
---------------------------
3844

39-
Running ``make dev`` will create a Docker-based development environment that starts the following containers:
45+
Running ``invoke devenv`` installs the development dependencies specified in the dev_requirements.txt. It starts all of the dockers used by this project, and leaves them running. These can be easily cleaned up with ``invoke clean``. NOTE: it is assumed that the user running these tests, can execute docker and its various commands.
4046

4147
* A master Redis node
42-
* A slave Redis node
48+
* A Redis replica node
4349
* Three sentinel Redis nodes
44-
* A test container
50+
* A multi-python docker, with your source code mounted in /data
4551

46-
The slave is a replica of the master node, using the `leader-follower replication <https://redis.io/topics/replication>`_ feature.
52+
The replica node, is a replica of the master node, using the `leader-follower replication <https://redis.io/topics/replication>`_ feature.
4753

4854
The sentinels monitor the master node in a `sentinel high-availability configuration <https://redis.io/topics/sentinel>`_.
4955

50-
Meanwhile, the `test` container hosts the code from your checkout of ``redis-py`` and allows running tests against many Python versions.
56+
Testing
57+
-------
58+
59+
Each run of tox starts and stops the various dockers required. Sometimes things get stuck, an ``invoke clean`` can help.
60+
61+
Continuous Integration uses these same wrappers to run all of these tests against multiple versions of python. Feel free to test your changes against all the python versions supported, as declared by the tox.ini file (eg: tox -e py39). If you have the various python versions on your desktop, you can run *tox* by itself, to test all supported versions. Alternatively, as your source code is mounted in the **lots-of-pythons** docker, you can start exploring from there, with all supported python versions!
5162

5263
Docker Tips
5364
^^^^^^^^^^^
@@ -56,17 +67,17 @@ Following are a few tips that can help you work with the Docker-based developmen
5667

5768
To get a bash shell inside of a container:
5869

59-
``$ docker-compose run <service> /bin/bash``
60-
61-
**Note**: The term "service" refers to the "services" defined in the ``docker-compose.yml`` file: "master", "slave", "sentinel_1", "sentinel_2", "sentinel_3", "test".
70+
``$ docker run -it <service> /bin/bash``
71+
72+
**Note**: The term "service" refers to the "services" defined in the ``tox.ini`` file at the top of the repo: "master", "replicaof", "sentinel_1", "sentinel_2", "sentinel_3".
6273

6374
Containers run a minimal Debian image that probably lacks tools you want to use. To install packages, first get a bash session (see previous tip) and then run:
6475

6576
``$ apt update && apt install <package>``
6677

67-
You can see the combined logging output of all containers like this:
78+
You can see the logging output of a containers like this:
6879

69-
``$ docker-compose logs``
80+
``$ docker logs -f <service>``
7081

7182
The command `make test` runs all tests in all tested Python environments. To run the tests in a single environment, like Python 3.6, use a command like this:
7283

@@ -81,13 +92,11 @@ Our test suite uses ``pytest``. You can run a specific test suite against a spec
8192
Troubleshooting
8293
^^^^^^^^^^^^^^^
8394
If you get any errors when running ``make dev`` or ``make test``, make sure that you
84-
are using supported versions of Docker and docker-compose.
95+
are using supported versions of Docker.
8596

86-
The included Dockerfiles and docker-compose.yml file work with the following
87-
versions of Docker and docker-compose:
97+
Please try at least versions of Docker.
8898

8999
* Docker 19.03.12
90-
* docker-compose 1.26.2
91100

92101
How to Report a Bug
93102
-------------------

Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 14 deletions
This file was deleted.

dev_requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
flake8>=3.9.2
2+
pytest==6.2.5
3+
tox==3.24.4
4+
tox-docker==3.1.0
5+
invoke==1.6.0

docker-entry.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.
File renamed without changes.

docker/replica/redis.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bind replica 127.0.0.1
2+
port 6380
3+
save ""
4+
replicaof master 6379

docker/slave/redis.conf

Lines changed: 0 additions & 4 deletions
This file was deleted.

tasks.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
import shutil
3+
from invoke import task, run
4+
5+
with open('tox.ini') as fp:
6+
lines = fp.read().split("\n")
7+
dockers = [line.split("=")[1].strip() for line in lines
8+
if line.find("name") != -1]
9+
10+
11+
@task
12+
def devenv(c):
13+
"""Builds a development environment: downloads, and starts all dockers
14+
specified in the tox.ini file.
15+
"""
16+
clean(c)
17+
cmd = 'tox -e devenv'
18+
for d in dockers:
19+
cmd += " --docker-dont-stop={}".format(d)
20+
print("Running: {}".format(cmd))
21+
run(cmd)
22+
23+
24+
@task
25+
def linters(c):
26+
"""Run code linters"""
27+
run("flake8")
28+
29+
30+
@task
31+
def all_tests(c):
32+
"""Run all linters, and tests in redis-py. This assumes you have all
33+
the python versions specified in the tox.ini file.
34+
"""
35+
linters(c)
36+
tests(c)
37+
38+
39+
@task
40+
def tests(c):
41+
"""Run the redis-py test suite against the current python,
42+
with and without hiredis.
43+
"""
44+
run("tox -e plain -e hiredis")
45+
46+
47+
@task
48+
def clean(c):
49+
"""Stop all dockers, and clean up the built binaries, if generated."""
50+
if os.path.isdir("build"):
51+
shutil.rmtree("build")
52+
if os.path.isdir("dist"):
53+
shutil.rmtree("dist")
54+
run("docker rm -f {}".format(' '.join(dockers)))
55+
56+
57+
@task
58+
def package(c):
59+
"""Create the python packages"""
60+
run("python setup.py build install")

0 commit comments

Comments
 (0)