Skip to content

Commit 75a2cfe

Browse files
authored
Dockerize (#1365)
Provide a docker development and testing environment * CI (Travis) now runs tests via the same docker environment that is available to developers. * A simple Makefile has been added to make getting started easier. * `make dev` will standup the development environment. * `make test` will standup the development environment and also run the test suite. * `make clean` will remove the development environment.
2 parents 142a44a + 1f988d8 commit 75a2cfe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+636
-408
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
source = redis

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/__pycache__
2+
**/*.pyc
3+
.tox

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ vagrant/.vagrant
1111
.eggs
1212
.idea
1313
.coverage
14+
env
15+
venv
16+
coverage.xml

.travis.yml

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,14 @@
1-
language: python
2-
cache: pip
3-
matrix:
4-
include:
5-
- env: TOXENV=flake8
6-
- python: 2.7
7-
env: TOXENV=py27-plain
8-
- python: 2.7
9-
env: TOXENV=py27-hiredis
10-
- python: 3.5
11-
env: TOXENV=py35-plain
12-
- python: 3.5
13-
env: TOXENV=py35-hiredis
14-
- python: 3.6
15-
env: TOXENV=py36-plain
16-
- python: 3.6
17-
env: TOXENV=py36-hiredis
18-
- python: 3.7
19-
env: TOXENV=py37-plain
20-
- python: 3.7
21-
env: TOXENV=py37-hiredis
22-
- python: 3.8
23-
env: TOXENV=py38-plain
24-
- python: 3.8
25-
env: TOXENV=py38-hiredis
26-
- python: pypy
27-
env: TOXENV=pypy-plain
28-
- python: pypy
29-
env: TOXENV=pypy-hiredis
30-
- python: pypy3
31-
env: TOXENV=pypy3-plain
32-
- python: pypy3
33-
env: TOXENV=pypy3-hiredis
1+
env:
2+
- DOCKER_COMPOSE_VERSION=1.26.2
3+
344
before_install:
35-
- wget https://github.com/antirez/redis/archive/6.0.5.tar.gz && mkdir redis_install && tar -xvzf 6.0.5.tar.gz -C redis_install && cd redis_install/redis-6.0.5 && make && src/redis-server --daemonize yes && cd ../..
36-
- redis-cli info
37-
install:
38-
- pip install codecov tox
5+
- sudo rm /usr/local/bin/docker-compose
6+
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
7+
- chmod +x docker-compose
8+
- sudo mv docker-compose /usr/local/bin
9+
10+
services:
11+
- docker
12+
3913
script:
40-
- tox
41-
after_success:
42-
- "if [[ $TOXENV != 'flake8' ]]; then codecov; fi"
14+
- make test

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* (in development)
2+
* Provide a development and testing environment via docker. Thanks
3+
@abrookins. #1365
14
* 3.5.3 (June 1, 2020)
25
* Restore try/except clauses to __del__ methods. These will be removed
36
in 4.0 when more explicit resource management if enforced. #1339

CONTRIBUTING.rst

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Contributing
2+
============
3+
4+
Introduction
5+
------------
6+
7+
First off, thank you for considering contributing to redis-py. We value community contributions!
8+
9+
Contributions We Need
10+
----------------------
11+
12+
You may already know what you want to contribute -- a fix for a bug you encountered, or a new feature your team wants to use.
13+
14+
If you don't know what to contribute, keep an open mind! Improving documentation, bug triaging, and writing tutorials are all examples of helpful contributions that mean less work for you.
15+
16+
Your First Contribution
17+
-----------------------
18+
Unsure where to begin contributing? You can start by looking through `help-wanted issues <https://github.com/andymccurdy/redis-py/issues?q=is%3Aopen+is%3Aissue+label%3ahelp-wanted>`_.
19+
20+
Never contributed to open source before? Here are a couple of friendly tutorials:
21+
22+
- http://makeapullrequest.com/
23+
- http://www.firsttimersonly.com/
24+
25+
Getting Started
26+
---------------
27+
28+
Here's how to get started with your code contribution:
29+
30+
1. Create your own fork of redis-py
31+
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``
34+
5. If you like the change and think the project could use it, send a pull request
35+
36+
The Development Environment
37+
---------------------------
38+
39+
Running ``make dev`` will create a Docker-based development environment that starts the following containers:
40+
41+
* A master Redis node
42+
* A slave Redis node
43+
* Three sentinel Redis nodes
44+
* A test container
45+
46+
The slave is a replica of the master node, using the `leader-follower replication <https://redis.io/topics/replication>`_ feature.
47+
48+
The sentinels monitor the master node in a `sentinel high-availability configuration <https://redis.io/topics/sentinel>`_.
49+
50+
Meanwhile, the `test` container hosts the code from your checkout of ``redis-py`` and allows running tests against many Python versions.
51+
52+
Docker Tips
53+
^^^^^^^^^^^
54+
55+
Following are a few tips that can help you work with the Docker-based development environment.
56+
57+
To get a bash shell inside of a container:
58+
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".
62+
63+
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:
64+
65+
``$ apt update && apt install <package>``
66+
67+
You can see the combined logging output of all containers like this:
68+
69+
``$ docker-compose logs``
70+
71+
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:
72+
73+
``$ docker-compose run test tox -e py36 -- --redis-url=redis://master:6379/9``
74+
75+
Here, the flag ``-e py36`` runs tests against the Python 3.6 tox environment. And note from the example that whenever you run tests like this, instead of using `make test`, you need to pass ``-- --redis-url=redis://master:6379/9``. This points the tests at the "master" container.
76+
77+
Our test suite uses ``pytest``. You can run a specific test suite against a specific Python version like this:
78+
79+
``$ docker-compose run test tox -e py36 -- --redis-url=redis://master:6379/9 tests/test_commands.py``
80+
81+
Troubleshooting
82+
^^^^^^^^^^^^^^^
83+
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.
85+
86+
The included Dockerfiles and docker-compose.yml file work with the following
87+
versions of Docker and docker-compose:
88+
89+
* Docker 19.03.12
90+
* docker-compose 1.26.2
91+
92+
How to Report a Bug
93+
-------------------
94+
95+
Security Vulnerabilities
96+
^^^^^^^^^^^^^^^^^^^^^^^^
97+
98+
**NOTE**: If you find a security vulnerability, do NOT open an issue. Email Andy McCurdy ([email protected]) instead.
99+
100+
In order to determine whether you are dealing with a security issue, ask yourself these two questions:
101+
102+
* Can I access something that's not mine, or something I shouldn't have access to?
103+
* Can I disable something for other people?
104+
105+
If the answer to either of those two questions are "yes", then you're probably dealing with a security issue. Note that even if you answer "no" to both questions, you may still be dealing with a security issue, so if you're unsure, just email Andy at [email protected].
106+
107+
Everything Else
108+
^^^^^^^^^^^^^^^
109+
110+
When filing an issue, make sure to answer these five questions:
111+
112+
1. What version of redis-py are you using?
113+
2. What version of redis are you using?
114+
3. What did you do?
115+
4. What did you expect to see?
116+
5. What did you see instead?
117+
118+
How to Suggest a Feature or Enhancement
119+
---------------------------------------
120+
121+
If you'd like to contribute a new feature, make sure you check our issue list to see if someone has already proposed it. Work may already be under way on the feature you want -- or we may have rejected a feature like it already.
122+
123+
If you don't see anything, open a new issue that describes the feature you would like and how it should work.
124+
125+
Code Review Process
126+
-------------------
127+
128+
The core team looks at Pull Requests on a regular basis. We will give feedback as as soon as possible. After feedback, we expect a response within two weeks. After that time, we may close your PR if it isn't showing any activity.

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM fkrull/multi-python:latest
2+
3+
RUN apt update && apt install -y pypy pypy-dev pypy3-dev
4+
5+
WORKDIR /redis-py
6+
7+
COPY . /redis-py

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: base clean dev test
2+
3+
base:
4+
docker build -t redis-py-base docker/base
5+
6+
dev: base
7+
docker-compose up -d --build
8+
9+
test: dev
10+
docker-compose run --rm test /redis-py/docker-entry.sh
11+
12+
clean:
13+
docker-compose stop
14+
docker-compose rm -f

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ or from source:
4747
4848
$ python setup.py install
4949
50+
Contributing
51+
------------
52+
53+
Want to contribute a feature, bug report, or report an issue? Check out our `guide to
54+
contributing <https://github.com/andymccurdy/redis-py/blob/master/CONTRIBUTING.rst>`_.
55+
5056

5157
Getting Started
5258
---------------

build_tools/.bash_profile

Lines changed: 0 additions & 1 deletion
This file was deleted.

build_tools/bootstrap.sh

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

build_tools/build_redis.sh

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

build_tools/install_redis.sh

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

build_tools/install_sentinel.sh

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

build_tools/redis-configs/001-master

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

build_tools/redis-configs/002-slave

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

0 commit comments

Comments
 (0)