Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker Compose-Based Redis Environment for go-redis CI #3210

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/test-on-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---

name: Build and Test using containerized environment

on:
push:
paths-ignore:
- 'docs/**'
- '**/*.md'
- '**/*.rst'
branches:
- master
- '[0-9].*'
pull_request:
branches:
- master
- '[0-9].*'
schedule:
- cron: '0 1 * * *' # nightly build

jobs:

build:
name: Build and Test
runs-on: ubuntu-latest
env:
REDIS_ENV_WORK_DIR: ${{ github.workspace }}/redis-env-work
REDIS_ENV_CONF_DIR: ${{ github.workspace }}/src/test/resources/env
CLIENT_LIBS_IMAGE_PREFIX: "redislabs/client-libs-test"
strategy:
fail-fast: false
matrix:
redis_version:
- "7.4.1"
- "7.2.6"
- "6.2.16"
- "8.0-M01"
go_version:
- "1.19.x"
- "1.20.x"
- "1.21.x"
steps:
- name: Set up ${{ matrix.go_version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go_version }}

- name: Checkout code
uses: actions/checkout@v4

# Set up Docker Compose environment
- name: Set up Docker Compose environment
run: |
mkdir -m 777 $REDIS_ENV_WORK_DIR
export REDIS_VERSION="${{ matrix.redis_version }}"
export COMPOSE_ENV_FILES="src/test/resources/env/.env"
if [[ "${{ matrix.redis_version }}" == "6.2.16" ]]; then
COMPOSE_ENV_FILES+=",src/test/resources/env/.env.v${{ matrix.redis_version }}"
fi
docker compose -f src/test/resources/env/docker-compose.yml up -d

- name: Run tests
env:
GO_VERSION: ${{ matrix.go_version }}
run: |
set -e
GO_MOD_DIRS=$(find . -type d -name go.mod | xargs -n 1 dirname)
for dir in $GO_MOD_DIRS; do
if echo "$dir" | grep -q "./example" && [ "$GO_VERSION" = "19" ]; then
echo "Skipping go test in $dir due to Go version 1.19 and dir contains ./example"
continue
fi
echo "Running tests in $dir"
(
cd "$dir"
go mod tidy -compat=1.18
go test ./... -short -race
go test ./... -run=NONE -bench=. -benchmem
env GOOS=linux GOARCH=386 go test ./...
go test -coverprofile=coverage.txt -covermode=atomic ./...
go vet
)
done

- name: Build custom vet tool
run: |
cd internal/customvet && go build .
go vet -vettool ./internal/customvet/customvet

# Collect logs on failure
- name: Collect logs on failure
if: failure() # This runs only if the previous steps failed
run: |
echo "Collecting logs from $WORK_DIR..."
ls -la $REDIS_ENV_WORK_DIR
# Upload logs as artifacts
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: redis-env-work-logs
path: ${{ env.REDIS_ENV_WORK_DIR }}
# Bring down the Docker Compose test environment
- name: Tear down Docker Compose environment
if: always()
run: |
docker compose $COMPOSE_ENV_FILES -f src/test/resources/env/docker-compose.yml down
continue-on-error: true
# Upload code coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ github.event_name == 'schedule' || (github.event_name == 'push') || github.event_name == 'workflow_dispatch'}}
uses: codecov/test-results-action@v1
with:
fail_ci_if_error: false
files: ./target/surefire-reports/TEST*
token: ${{ secrets.CODECOV_TOKEN }}
140 changes: 140 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---

services:

redis:
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.0-M01}
container_name: redis-standalone
environment:
- TLS_ENABLED=yes
- REDIS_CLUSTER=no
- PORT=6379
- TLS_PORT=6666
command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --tls-auth-clients optional --save ""}
ports:
- 6379:6379
- 9123:6379 # Sentinel port
- 6666:6666 # TLS port
volumes:
- "./dockers/standalone:/redis/work"
profiles:
- standalone
- sentinel
- replica
- all-stack
- all

replica:
image: ${REDIS_IMAGE:-redis:8.0-M01}
container_name: redis-replica
depends_on:
- redis
command: redis-server --replicaof redis 6379 --protected-mode no --save ""
ports:
- 6380:6379
profiles:
- replica
- all-stack
- all

cluster:
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.0-M01}
container_name: redis-cluster
environment:
- REDIS_CLUSTER=yes
- NODES=6
- REPLICAS=1
- TLS_ENABLED=yes
- PORT=16379
- TLS_PORT=27379
command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --save ""}
ports:
- "16379-16381:16379-16381"
volumes:
- "./dockers/cluster:/redis/work"
profiles:
- cluster
- all-stack
- all

sentinel:
image: ${REDIS_IMAGE:-redis:8.0-M01}
container_name: redis-sentinel1
depends_on:
- redis
entrypoint: "redis-sentinel /redis.conf --port 9123"
ports:
- 9126:9126
volumes:
- "./dockers/sentinel.conf:/redis.conf"
profiles:
- sentinel
- all-stack
- all

sentinel2:
image: ${REDIS_IMAGE:-redis:8.0-M01}
container_name: redis-sentinel2
depends_on:
- redis
entrypoint: "redis-sentinel /redis.conf --port 9124"
ports:
- 9127:9127
volumes:
- "./dockers/sentinel.conf:/redis.conf"
profiles:
- sentinel
- all-stack
- all

sentinel3:
image: ${REDIS_IMAGE:-redis:8.0-M01}
container_name: redis-sentinel3
depends_on:
- redis
entrypoint: "redis-sentinel /redis.conf --port 26381"
ports:
- 9128:9128
volumes:
- "./dockers/sentinel.conf:/redis.conf"
profiles:
- sentinel
- all-stack
- all

sentinel-slave1:
image: ${REDIS_IMAGE:-redis:8.0-M01}
container_name: redis-sentinel1-slave
depends_on:
- redis
command: redis-server --slaveof redis 9123 --protected-mode no --save ""
ports:
- 9124:9123
profiles:
- sentinel
- all-stack
- all

sentinel-slave2:
image: ${REDIS_IMAGE:-redis:8.0-M01}
container_name: redis-sentinel2-slave
depends_on:
- redis
command: redis-server --slaveof redis 9123 --protected-mode no --save ""
ports:
- 9125:9123
profiles:
- sentinel
- all-stack
- all

redis-stack:
image: ${REDIS_STACK_IMAGE:-redis/redis-stack-server:edge}
container_name: redis-stack
ports:
- 6349:6379
environment:
- "REDIS_ARGS=${REDIS_STACK_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --save ''}"
profiles:
- standalone
- all-stack
1 change: 1 addition & 0 deletions dockers/cluster/cluster-nodes.info
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-0 node-1 node-2 node-3 node-4 node-5
7 changes: 7 additions & 0 deletions dockers/cluster/node-0/nodes.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
16151e686272aa1dd2d15d4af407b6be45c9eca1 127.0.0.1:16384@26384,,tls-port=27384,shard-id=78410864729d91b91858e4f921bcd314095cfcc6 slave 3a1250b30cc37fca6db12b82fdefcbf615dec08f 1734269951169 1734269951128 1 connected
a0970bd542e1e5b7512bfc61deac5244e4478c58 127.0.0.1:16382@26382,,tls-port=27382,shard-id=8ee145d9d4fab776f3f51de69974dc0377adb434 slave 17003be25313b117da88e1dfefdb9ddb6bf68c90 0 1734269951203 2 connected
3a1250b30cc37fca6db12b82fdefcbf615dec08f 127.0.0.1:16379@26379,,tls-port=27379,shard-id=78410864729d91b91858e4f921bcd314095cfcc6 myself,master - 0 0 1 connected 0-5460
0287949c6e8aa2fb3f26d81820cc54b82bfd551f 127.0.0.1:16383@26383,,tls-port=27383,shard-id=4554bc07be3de979d00342a6de84369994bb059c slave 4759591cd1762d973a5691128c97200deb57762f 1734269951169 1734269951128 3 connected
4759591cd1762d973a5691128c97200deb57762f 127.0.0.1:16381@26381,,tls-port=27381,shard-id=4554bc07be3de979d00342a6de84369994bb059c master - 0 1734269951169 3 connected 10923-16383
17003be25313b117da88e1dfefdb9ddb6bf68c90 127.0.0.1:16380@26380,,tls-port=27380,shard-id=8ee145d9d4fab776f3f51de69974dc0377adb434 master - 0 1734269951169 2 connected 5461-10922
vars currentEpoch 6 lastVoteEpoch 0
12 changes: 12 additions & 0 deletions dockers/cluster/node-0/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

port 16379

tls-port 27379

include /redis/work/tls/redis-tls.conf

cluster-enabled yes

cluster-config-file nodes.conf

protected-mode no
Loading
Loading