Skip to content

Commit bef5cad

Browse files
committed
added cluster tests to CI
1 parent 54b29c6 commit bef5cad

File tree

7 files changed

+374
-35
lines changed

7 files changed

+374
-35
lines changed

.github/workflows/ci.yml

Lines changed: 91 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -103,35 +103,94 @@ jobs:
103103
DJANGO: ${{ matrix.django-version }}
104104
VALKEY: ${{ matrix.valkey-version }}
105105

106-
# cluster:
107-
# runs-on: ubuntu-latest
108-
#
109-
# strategy:
110-
# fail-fast: false
111-
# matrix:
112-
# python-version:
113-
# - '3.10'
114-
# - '3.11'
115-
# - '3.12'
116-
# # - '3.13'
117-
# django-version:
118-
# - '4.2'
119-
# - '5.0'
120-
# - '5.1'
121-
# valkey-version:
122-
# - 'latest'
123-
# - '7.2'
124-
# services:
125-
# valkey:
126-
# image: bitnami/valkey-cluster:${{ matrix.valkey-version }}
127-
# ports:
128-
# - 6379:6379
129-
# options: >-
130-
# --health-cmd "valkey-cli ping"
131-
# --health-interval 10s
132-
# --health-timeout 5s
133-
# --health-retries 5
134-
# --volume /tmp:/tmp
135-
# env:
136-
# VALKEY_EXTRA_FLAGS: '--save ""'
137-
# VALKEY_AOF_ENABLE: "no"
106+
populate-cache:
107+
runs-on: ubuntu-latest
108+
timeout-minutes: 60
109+
name: Update docker cache
110+
steps:
111+
- uses: actions/checkout@v4
112+
- name: Cache docker images
113+
id: custom-cache
114+
uses: actions/cache@v4
115+
with:
116+
path: ./custom-cache/
117+
key: custom-cache
118+
- if: ${{ steps.custom-cache.outputs.cache-hit != 'true' || github.event_name == 'schedule' }}
119+
name: Update Cache
120+
run: |
121+
mkdir -p ./custom-cache/
122+
docker compose --profile all build
123+
docker pull valkey/valkey:latest
124+
docker save django-valkey-cluster:latest -o ./custom-cache/all.tar
125+
126+
run-tests:
127+
runs-on: ubuntu-latest
128+
needs: [populate-cache]
129+
strategy:
130+
fail-fast: false
131+
matrix:
132+
python-version:
133+
- '3.10'
134+
- '3.11'
135+
- '3.12'
136+
# - '3.13'
137+
django-version:
138+
- '4.2'
139+
- '5.0'
140+
- '5.1'
141+
env:
142+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
143+
144+
steps:
145+
- uses: actions/checkout@v4
146+
147+
- name: Set up Python ${{ matrix.python-version }}
148+
uses: actions/setup-python@v5
149+
with:
150+
python-version: ${{ matrix.python-version }}
151+
152+
- name: Cache docker image
153+
id: custom-cache
154+
uses: actions/cache@v4
155+
with:
156+
path: ./custom-cache/
157+
fail-on-cache-miss: true
158+
key: custom-cache
159+
- name: use Cache
160+
run: docker image load -i ./custom-cache/all.tar
161+
162+
# - name: Cache
163+
# id: cached-poetry
164+
# uses: actions/cache@v4
165+
# with:
166+
# path: ./.venv
167+
# key: venv-${{ hashFiles('poetry.lock') }}
168+
169+
- name: Install poetry
170+
if: steps.cached-poetry.outputs.cache-hit != 'true'
171+
uses: abatilo/actions-poetry@v3
172+
173+
- name: install dependencies
174+
run: |
175+
poetry install --no-interaction --no-root --all-extras --with dev
176+
177+
- name: config poetry
178+
run: |
179+
poetry config virtualenvs.create true --local
180+
poetry config virtualenvs.in-project true --local
181+
182+
- name: Install project
183+
run: |
184+
poetry add django==${{ matrix.django-version }}
185+
poetry install --no-interaction --all-extras
186+
187+
188+
- name: tests
189+
run: |
190+
poetry run invoke devenv
191+
sh ./util/wait-for-it.sh localhost:16379
192+
poetry run pytest tests/tests_cluster/*.py --ds=tests.settings.sqlite_cluster
193+
194+
env:
195+
DJANGO: ${{ matrix.django-version }}
196+
VALKEY: ${{ matrix.valkey-version }}

compose.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
3+
services:
4+
cluster:
5+
container_name: valkey-cluster
6+
build:
7+
context: .
8+
dockerfile: dockers/Dockerfile.cluster
9+
10+
ports:
11+
- "16379:16379"
12+
- "16380:16380"
13+
- "16381:16381"
14+
- "16382:16382"
15+
- "16383:16383"
16+
- "16384:16384"
17+
volumes:
18+
- "./dockers/cluster.valkey.conf:/valkey.conf:ro"
19+
profiles:
20+
- cluster
21+
- all

dockers/Dockerfile.cluster

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM valkey/valkey:latest as rss
2+
3+
COPY dockers/create_cluster.sh /create_cluster.sh
4+
RUN chmod a+x /create_cluster.sh
5+
6+
ENTRYPOINT [ "/create_cluster.sh"]

dockers/cluster.valkey.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
protected-mode no
2+
enable-debug-command yes

dockers/create_cluster.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! /bin/bash
2+
3+
mkdir -p /nodes
4+
touch /nodes/nodemap
5+
if [ -z ${START_PORT} ]; then
6+
START_PORT=16379
7+
fi
8+
if [ -z ${END_PORT} ]; then
9+
END_PORT=16384
10+
fi
11+
if [ ! -z "$3" ]; then
12+
START_PORT=$2
13+
START_PORT=$3
14+
fi
15+
echo "STARTING: ${START_PORT}"
16+
echo "ENDING: ${END_PORT}"
17+
18+
for PORT in `seq ${START_PORT} ${END_PORT}`; do
19+
mkdir -p /nodes/$PORT
20+
if [[ -e /valkey.conf ]]; then
21+
cp /valkey.conf /nodes/$PORT/valkey.conf
22+
else
23+
touch /nodes/$PORT/valkey.conf
24+
fi
25+
cat << EOF >> /nodes/$PORT/valkey.conf
26+
port ${PORT}
27+
cluster-enabled yes
28+
daemonize yes
29+
logfile /valkey.log
30+
dir /nodes/$PORT
31+
save ""
32+
EOF
33+
34+
set -x
35+
/usr/local/bin/valkey-server /nodes/$PORT/valkey.conf
36+
sleep 1
37+
if [ $? -ne 0 ]; then
38+
echo "Valkey failed to start, exiting."
39+
continue
40+
fi
41+
echo 127.0.0.1:$PORT >> /nodes/nodemap
42+
done
43+
if [ -z "${VALKEY_PASSWORD}" ]; then
44+
echo yes | /usr/local/bin/valkey-cli --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
45+
else
46+
echo yes | /usr/local/bin/valkey-cli -a ${VALKEY_PASSWORD} --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
47+
fi
48+
tail -f /valkey.log

tests/settings/sqlite_cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
CACHES = {
44
"default": {
55
"BACKEND": "django_valkey.cluster_cache.cache.ClusterValkeyCache",
6-
"LOCATION": ["valkey://127.0.0.1:7005", "valkey://127.0.0.1:7005"],
6+
"LOCATION": ["valkey://127.0.0.1:16379", "valkey://127.0.0.1:16384"],
77
"OPTIONS": {
88
"CLIENT_CLASS": "django_valkey.cluster_cache.client.DefaultClusterClient"
99
},
@@ -17,14 +17,14 @@
1717
},
1818
"sample": {
1919
"BACKEND": "django_valkey.cluster_cache.cache.ClusterValkeyCache",
20-
"LOCATION": "valkey://127.0.0.1:7005:0,valkey://127.0.0.1:7002:0",
20+
"LOCATION": "valkey://127.0.0.1:16379:0,valkey://127.0.0.1:16380:0",
2121
"OPTIONS": {
2222
"CLIENT_CLASS": "django_valkey.cluster_cache.client.DefaultClusterClient"
2323
},
2424
},
2525
"with_prefix": {
2626
"BACKEND": "django_valkey.cluster_cache.cache.ClusterValkeyCache",
27-
"LOCATION": "valkey://127.0.0.1:7005?db=0",
27+
"LOCATION": "valkey://127.0.0.1:16379?db=0",
2828
"OPTIONS": {
2929
"CLIENT_CLASS": "django_valkey.cluster_cache.client.DefaultClusterClient"
3030
},

0 commit comments

Comments
 (0)