Skip to content

Commit 8be3169

Browse files
committed
changed CI to use valkey image directly
1 parent f4716cf commit 8be3169

File tree

7 files changed

+365
-56
lines changed

7 files changed

+365
-56
lines changed

.github/workflows/ci.yml

+52-56
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,60 @@ name: CI
33
on: [push, pull_request]
44

55
jobs:
6-
test:
6+
populate-cache:
77
runs-on: ubuntu-latest
8+
timeout-minutes: 60
9+
name: Update docker cache
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Cache docker images
13+
id: custom-cache
14+
uses: actions/cache@v4
15+
with:
16+
path: ./custom-cache/
17+
key: custom-cache
18+
- if: ${{ steps.custom-cache.outputs.cache-hit != 'true' || github.event_name == 'schedule' }}
19+
name: Update cache
20+
run: |
21+
mkdir -p ./custom-cache/
22+
docker compose --profile all build
23+
docker pull valkey/valkey:latest
24+
docker save django-valkey-cluster:latest valkey/valkey:latest -o ./custom-cache/all.tar
825
26+
test:
27+
runs-on: ubuntu-latest
28+
needs: [populate-cache]
29+
timeout-minutes: 60
930
strategy:
1031
fail-fast: false
1132
matrix:
1233
python-version:
1334
- '3.10'
1435
- '3.11'
1536
- '3.12'
16-
# - '3.13'
37+
# - '3.13'
1738
django-version:
1839
- '4.2'
1940
- '5.0'
2041
- '5.1'
21-
valkey-version:
22-
- 'latest'
23-
- '7.2'
24-
25-
services:
26-
valkey:
27-
image: valkey/valkey:${{ matrix.valkey-version }}
28-
ports:
29-
- 6379:6379
30-
options: >-
31-
--health-cmd "valkey-cli ping"
32-
--health-interval 10s
33-
--health-timeout 5s
34-
--health-retries 5
35-
--volume /tmp:/tmp
36-
env:
37-
VALKEY_EXTRA_FLAGS: '--save "" --unixsocket /tmp/valkey.sock --unixsocketperm 777'
38-
39-
sentinel:
40-
image: bitnami/valkey-sentinel:${{ matrix.valkey-version }}
41-
ports:
42-
- 26379:26379
43-
options: >-
44-
--health-cmd "valkey-cli -p 26379 ping"
45-
--health-interval 10s
46-
--health-timeout 5s
47-
--health-retries 5
48-
--volume /tmp:/tmp
49-
env:
50-
VALKEY_SENTINEL_QUORUM: "1"
51-
VALKEY_SENTINEL_AOF_ENABLED: "no"
42+
env:
43+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
5244
steps:
5345
- uses: actions/checkout@v4
5446

5547
- name: Set up Python ${{ matrix.python-version }}
5648
uses: actions/setup-python@v5
5749
with:
5850
python-version: ${{ matrix.python-version }}
51+
- name: Cache docker images
52+
id: custom-cache
53+
uses: actions/cache@v4
54+
with:
55+
path: ./custom-cache/
56+
fail-on-cache-miss: true
57+
key: custom-cache
58+
- name: Use Cache
59+
run: docker image load -i ./custom-cache/all.tar
5960

6061
# - name: Cache
6162
# id: cached-poetry
@@ -83,30 +84,25 @@ jobs:
8384
8485
- name: tests
8586
run: |
86-
VALKEY_PRIMARY=$(tests/start_valkey.sh)
87-
VALKEY_SENTINEL=$(tests/start_valkey.sh --sentinel)
88-
CONTAINERS="$VALKEY_PRIMARY $VALKEY_SENTINEL"
89-
trap "docker stop $CONTAINERS && docker rm $CONTAINERS" EXIT
90-
tests/wait_for_valkey.sh $VALKEY_PRIMARY 6379
91-
tests/wait_for_valkey.sh $VALKEY_SENTINEL 26379
92-
87+
poetry run invoke devenv
88+
chmod +x ./util/wait-for-it.sh
89+
./util/wait-for-it.sh localhost:6379
9390
94-
poetry run pytest tests/*.py --ds=tests.settings.sqlite
95-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_herd
96-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_json
97-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_lz4
98-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_msgpack
99-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_sentinel
100-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_sentinel_opts
101-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_sharding
102-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_usock
103-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_zlib
104-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_zstd
105-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_gzip
106-
poetry run pytest tests/*.py --ds=tests.settings.sqlite_bz2
107-
poetry run pytest tests/tests_async/*.py --ds=tests.settings.sqlite_async
108-
poetry run pytest tests/tests_async/*.py --ds=tests.settings.sqlite_async_herd
91+
poetry run pytest tests/*.py --ds=tests.settings.sqlite -x
92+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_herd -x
93+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_json -x
94+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_lz4 -x
95+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_msgpack -x
96+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_sentinel -x
97+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_sentinel_opts -x
98+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_sharding -x
99+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_zlib -x
100+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_zstd -x
101+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_gzip -x
102+
poetry run pytest tests/*.py --ds=tests.settings.sqlite_bz2 -x
103+
poetry run pytest tests/tests_async/*.py --ds=tests.settings.sqlite_async -x
104+
poetry run pytest tests/tests_async/*.py --ds=tests.settings.sqlite_async_herd -x
105+
# poetry run pytest tests/*.py --ds=tests.settings.sqlite_usock -x
109106

110107
env:
111108
DJANGO: ${{ matrix.django-version }}
112-
VALKEY: ${{ matrix.valkey-version }}

compose.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
3+
---
4+
5+
services:
6+
7+
valkey:
8+
image: valkey/valkey:latest
9+
container_name: valkey-standalone
10+
ports:
11+
- "6379:6379"
12+
profiles:
13+
- standalone
14+
- sentinel
15+
- replica
16+
- all
17+
command: ['valkey-server', '--save', '""']
18+
19+
20+
cluster:
21+
container_name: valkey-cluster
22+
build:
23+
context: .
24+
dockerfile: dockers/Dockerfile.cluster
25+
ports:
26+
- "16379:16379"
27+
- "16380:16380"
28+
- "16381:16381"
29+
- "16382:16382"
30+
- "16383:16383"
31+
- "16384:16384"
32+
volumes:
33+
- "./dockers/cluster.valkey.conf:/valkey.conf:ro"
34+
profiles:
35+
- cluster
36+
- all
37+
38+
sentinel:
39+
image: valkey/valkey:latest
40+
container_name: valkey-sentinel
41+
depends_on:
42+
- valkey
43+
entrypoint: "/usr/local/bin/valkey-sentinel /valkey.conf --port 26379"
44+
ports:
45+
- "26379:26379"
46+
volumes:
47+
- "./dockers/sentinel.conf:/valkey.conf"
48+
profiles:
49+
- sentinel
50+
- all

dockers/Dockerfile.cluster

+6
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

+2
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

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
EOF
32+
33+
set -x
34+
/usr/local/bin/valkey-server /nodes/$PORT/valkey.conf
35+
sleep 1
36+
if [ $? -ne 0 ]; then
37+
echo "Valkey failed to start, exiting."
38+
continue
39+
fi
40+
echo 127.0.0.1:$PORT >> /nodes/nodemap
41+
done
42+
if [ -z "${VALKEY_PASSWORD}" ]; then
43+
echo yes | /usr/local/bin/valkey-cli --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
44+
else
45+
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
46+
fi
47+
tail -f /valkey.log

dockers/sentinel.conf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sentinel resolve-hostnames yes
2+
sentinel monitor mymaster valkey 6379 1
3+
sentinel down-after-milliseconds mymaster 5000
4+
sentinel failover-timeout mymaster 60000
5+
sentinel parallel-syncs mymaster 1

0 commit comments

Comments
 (0)