From 3c4e363a2e9d52381924c0a93109f056c7f8f5d7 Mon Sep 17 00:00:00 2001 From: Anas Date: Thu, 23 Dec 2021 08:49:47 +0200 Subject: [PATCH] First try with tox-docker --- .github/workflows/ci.yml | 12 ++----- docker/base/Dockerfile | 3 ++ docker/base/Dockerfile.sentinel | 3 ++ docker/base/README.md | 1 + docker/master/redis.conf | 2 ++ docker/sentinel/sentinel.conf | 6 ++++ setup.cfg | 57 +++++++++++++++++++++++---------- 7 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 docker/base/Dockerfile create mode 100644 docker/base/Dockerfile.sentinel create mode 100644 docker/base/README.md create mode 100644 docker/master/redis.conf create mode 100644 docker/sentinel/sentinel.conf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66440eb4..d28c2aa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,18 +79,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install --upgrade tox tox-gh-actions + python -m pip install --upgrade tox tox-gh-actions tox-docker - name: Tox tests - run: | - REDIS_PRIMARY=$(tests/start_redis.sh) - REDIS_SENTINEL=$(tests/start_redis.sh --sentinel) - CONTAINERS="$REDIS_PRIMARY $REDIS_SENTINEL" - trap "docker stop $CONTAINERS && docker rm $CONTAINERS" EXIT - tests/wait_for_redis.sh $REDIS_PRIMARY 6379 - tests/wait_for_redis.sh $REDIS_SENTINEL 26379 - - tox + run: tox env: DJANGO: ${{ matrix.django-version }} REDIS: ${{ matrix.redis-version }} diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile new file mode 100644 index 00000000..60be3748 --- /dev/null +++ b/docker/base/Dockerfile @@ -0,0 +1,3 @@ +FROM redis:6.2.6-buster + +CMD ["redis-server", "/redis.conf"] diff --git a/docker/base/Dockerfile.sentinel b/docker/base/Dockerfile.sentinel new file mode 100644 index 00000000..93c16a71 --- /dev/null +++ b/docker/base/Dockerfile.sentinel @@ -0,0 +1,3 @@ +FROM redis:6.2.6-buster + +CMD ["redis-sentinel", "/sentinel.conf"] diff --git a/docker/base/README.md b/docker/base/README.md new file mode 100644 index 00000000..5ba63f5f --- /dev/null +++ b/docker/base/README.md @@ -0,0 +1 @@ +Dockers in this folder are built, and uploaded to the redislab dockerhub store. diff --git a/docker/master/redis.conf b/docker/master/redis.conf new file mode 100644 index 00000000..15a31b5a --- /dev/null +++ b/docker/master/redis.conf @@ -0,0 +1,2 @@ +port 6379 +save "" diff --git a/docker/sentinel/sentinel.conf b/docker/sentinel/sentinel.conf new file mode 100644 index 00000000..0eff44d6 --- /dev/null +++ b/docker/sentinel/sentinel.conf @@ -0,0 +1,6 @@ +port 26379 + +sentinel monitor default_service 127.0.0.1 6379 1 +sentinel down-after-milliseconds default_service 10000 +sentinel failover-timeout default_service 60000 +sentinel parallel-syncs default_service 1 diff --git a/setup.cfg b/setup.cfg index 28c1fc1a..20137794 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,7 +46,6 @@ hiredis = redis[hiredis]>=3,!=4.0.0,!=4.0.1 [coverage:run] omit = - # tests tests/*, [coverage:report] @@ -66,17 +65,38 @@ multi_line_output = 3 [tox:tox] minversion = 3.15.0 +requires = tox-docker envlist = black flake8 isort mypy - # tests against released versions +# tests against released versions py{36,37,38,39,310}-dj{22,31,32,40}-redislatest - # tests against unreleased versions +# tests against unreleased versions py310-dj40-redismaster py310-djmain-redis{latest,master} +[docker:master] +name = master +image = redisfab/redis-py:6.2.6-buster +ports = + 6379:6379/tcp +healtcheck_cmd = python -c "import socket;print(True) if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('127.0.0.1',6379)) else False" +volumes = + bind:rw:{toxinidir}/docker/master/redis.conf:/redis.conf + +[docker:sentinel] +name = sentinel +image = redisfab/redis-py-sentinel:6.2.6-buster +links = + master:master +ports = + 26379:26379/tcp +healtcheck_cmd = python -c "import socket;print(True) if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('127.0.0.1',26379)) else False" +volumes = + bind:rw:{toxinidir}/docker/sentinel/sentinel.conf:/sentinel.conf + [gh-actions] python = 3.6: py36 @@ -99,18 +119,20 @@ REDIS = [testenv] passenv = CI GITHUB* commands = - {envpython} -m pytest --cov-report= --ds=settings.sqlite {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_json {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_lz4 {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_msgpack {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_sentinel {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_sharding {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_usock {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_zlib {posargs} - {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_zstd {posargs} - {envpython} -m coverage report - {envpython} -m coverage xml - + {envpython} -m pytest --cov-report= --ds=settings.sqlite {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_json {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_lz4 {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_msgpack {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_sentinel {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_sharding {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_usock {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_zlib {posargs} + {envpython} -m pytest --cov-append --cov-report= --ds=settings.sqlite_zstd {posargs} + {envpython} -m coverage report + {envpython} -m coverage xml +docker = + master + sentinel deps = dj22: Django>=2.2,<2.3 dj31: Django>=3.1,<3.2 @@ -129,7 +151,8 @@ deps = [testenv:{black,flake8,isort,mypy}] basepython = python3 -envdir={toxworkdir}/lint +envdir = {toxworkdir}/lint +docker = commands = black: black --target-version py36 {posargs:--check --diff} setup.py django_redis/ tests/ flake8: flake8 {posargs} setup.py django_redis/ tests/ @@ -142,7 +165,7 @@ deps = isort >= 5.0.2 lxml mypy - # typing dependencies +# typing dependencies pytest pytest-django pytest-mock