Skip to content

Commit

Permalink
Update: 迁移使用 redis 新容器
Browse files Browse the repository at this point in the history
Update: 修复测试
  • Loading branch information
NHZEX committed Apr 7, 2024
1 parent 32f8b5e commit 347d0e5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/actions/ci-prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
run: |
docker network create imi-ci-service-network --subnet 172.10.12.0/24
docker compose -f ./.github/service/redis-cluster/docker-compose.yml up -d
docker compose -f ./.github/docker-compose.yml up -d ${{ inputs.env }} redis-new
docker compose -f ./.github/docker-compose.yml up -d ${{ inputs.env }}
docker exec ${{ inputs.env }} php -v
docker exec ${{ inputs.env }} php -m
docker exec ${{ inputs.env }} php --ri redis
Expand Down
49 changes: 28 additions & 21 deletions .github/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,30 @@ services:
volumes:
- "${GITHUB_WORKSPACE}:/imi:rw"

redis:
image: redis:6-alpine
container_name: redis
depends_on:
- shared-tmp
command: redis-server /etc/redis.conf
volumes:
- ./redis.conf:/etc/redis.conf
- /run/shared:/run/shared
ports:
- 6379:6379
# redis:
# image: redis:6-alpine
# container_name: redis
# depends_on:
# - shared-tmp
# command: redis-server /etc/redis.conf
# volumes:
# - ./redis.conf:/etc/redis.conf
# - /run/shared:/run/shared
# ports:
# - 6379:6379

redis-new:
redis:
image: bitnami/redis:7.2
container_name: redis-new
container_name: redis
depends_on:
- shared-tmp
volumes:
- "${GITHUB_WORKSPACE}/.github/service/redis-tls/certs:/opt/bitnami/redis/certs"
- "${GITHUB_WORKSPACE}/.github/service/redis-tls/redis-overrides.conf:/opt/bitnami/redis/redis-overrides.conf"
- /run/shared:/run/shared
environment:
REDIS_PORT_NUMBER: 6377
REDIS_OVERRIDES_FILE: "/opt/bitnami/redis/redis-overrides.conf"
REDIS_PORT_NUMBER: 6379
REDIS_PASSWORD: "l83aa26"
REDIS_TLS_ENABLED: "true"
REDIS_TLS_PORT_NUMBER: 6443
Expand All @@ -71,13 +73,18 @@ services:
REDIS_TLS_CA_FILE: "/opt/bitnami/redis/certs/ca.crt"
REDIS_TLS_AUTH_CLIENTS: "yes"
healthcheck:
test: ["CMD-SHELL", "redis-cli -h 127.0.0.1 -p 6377 -a l83aa26 INFO | grep 'redis_version'"]
test: ["CMD-SHELL", "redis-cli -h 127.0.0.1 -p $${REDIS_PORT_NUMBER:-6379} -a $${REDIS_PASSWORD} INFO | grep 'redis_version'"]
interval: 3s
timeout: 60s
retries: 30
ports:
- "6377:6377"
- "6379:6379"
- "6443:6443"
networks:
proxies:
aliases:
- redis
ipv4_address: 172.10.12.111

rabbitmq:
container_name: rabbitmq
Expand Down Expand Up @@ -124,13 +131,13 @@ services:
- shared-tmp
- mysql
- redis
- redis-new
- rabbitmq
- kafka1
- postgres
environment:
MYSQL_SERVER_HOST: mysql
REDIS_SERVER_HOST: ${REDIS_SERVER_HOST}
REDIS_SERVER_HOST: ${REDIS_SERVER_HOST:-redis}
REDIS_SERVER_PASSWORD: ${REDIS_SERVER_PASSWORD:-l83aa26}
PGSQL_SERVER_HOST: postgres
MYSQL_SERVER_PASSWORD: ""
AMQP_SERVER_HOST: "rabbitmq"
Expand All @@ -140,7 +147,7 @@ services:
REDIS_SERVER_CLUSTER_SEEDS: "172.10.12.2:6379,172.10.12.3:6379,172.10.12.4:6379,172.10.12.5:6379,172.10.12.6:6379,172.10.12.7:6379"
REDIS_SERVER_TLS_CLUSTER_SEEDS: "172.10.12.2:6443,172.10.12.3:6443,172.10.12.4:6443,172.10.12.5:6443,172.10.12.6:6443,172.10.12.7:6443"
REDIS_SERVER_UNIX_SOCK: "/run/shared/redis.sock"
REDIS_SERVER_TLS_HOST: "redis-new"
REDIS_SERVER_TLS_HOST: "redis"
REDIS_SERVER_TLS_PORT: "6443"
REDIS_SERVER_TLS_PASSWORD: "l83aa26"
REDIS_SERVER_TLS_CA_FILE: "/imi/.github/service/redis-tls/certs/ca.crt"
Expand All @@ -162,13 +169,13 @@ services:
- shared-tmp
- mysql
- redis
- redis-new
- rabbitmq
- kafka1
- postgres
environment:
MYSQL_SERVER_HOST: mysql
REDIS_SERVER_HOST: ${REDIS_SERVER_HOST}
REDIS_SERVER_PASSWORD: ${REDIS_SERVER_PASSWORD:-l83aa26}
PGSQL_SERVER_HOST: postgres
MYSQL_SERVER_PASSWORD: ""
AMQP_SERVER_HOST: "rabbitmq"
Expand All @@ -178,7 +185,7 @@ services:
REDIS_SERVER_CLUSTER_SEEDS: "172.10.12.2:6379,172.10.12.3:6379,172.10.12.4:6379,172.10.12.5:6379,172.10.12.6:6379,172.10.12.7:6379"
REDIS_SERVER_TLS_CLUSTER_SEEDS: "172.10.12.2:6443,172.10.12.3:6443,172.10.12.4:6443,172.10.12.5:6443,172.10.12.6:6443,172.10.12.7:6443"
REDIS_SERVER_UNIX_SOCK: "/run/shared/redis.sock"
REDIS_SERVER_TLS_HOST: "redis-new"
REDIS_SERVER_TLS_HOST: "redis"
REDIS_SERVER_TLS_PORT: "6443"
REDIS_SERVER_TLS_PASSWORD: "l83aa26"
REDIS_SERVER_TLS_CA_FILE: "/imi/.github/service/redis-tls/certs/ca.crt"
Expand Down
2 changes: 2 additions & 0 deletions .github/service/redis-tls/redis-overrides.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unixsocket /run/shared/redis.sock
unixsocketperm 777
25 changes: 10 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
REPOSITORY_OWNER: ${{ github.repository_owner }}
IMAGE_VERSION: ${{ matrix.swoole.version }}
MYSQL_DOCKER_VERSION: "8.0"
REDIS_SERVER_HOST: redis
ROADRUNNER_DOCKER_VERSION: ${{ matrix.roadrunner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
Expand All @@ -61,13 +60,13 @@ jobs:
run: |
docker ps
docker logs shared-tmp || true
docker logs redis-new || true
docker logs redis || true
docker exec ${ENV_SERVICE} bash -c "ls -lha /run/shared"
echo ">>> redis-cluster-node-0"
docker exec ${ENV_SERVICE} bash -c "echo -e 'auth l83aa26\r\ninfo server' | nc redis-cluster-node-0-1 6379 -w 1"
docker exec ${ENV_SERVICE} bash -c "echo -e 'auth l83aa26\r\ncluster info\r\ncluster nodes' | nc redis-cluster-node-0-1 6379 -w 1"
echo ">>> redis-new"
docker exec ${ENV_SERVICE} bash -c "echo -e 'auth l83aa26\r\ninfo server' | nc redis-new 6377 -w 1"
echo ">>> redis"
docker exec ${ENV_SERVICE} bash -c "echo -e 'auth l83aa26\r\ninfo server' | nc redis 6379 -w 1"
- name: Test
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test
Expand Down Expand Up @@ -143,6 +142,10 @@ jobs:
env:
MYSQL_DOCKER_VERSION: "8.0"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REDIS_SERVER_HOST: "127.0.0.1"
REDIS_SERVER_PASSWORD: "l83aa26"
REDIS_SERVER_CLUSTER_PASSWORD: "l83aa26"
REDIS_SERVER_CLUSTER_SEEDS: "172.10.12.2:6379,172.10.12.3:6379,172.10.12.4:6379,172.10.12.5:6379,172.10.12.6:6379,172.10.12.7:6379"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -152,7 +155,7 @@ jobs:
sudo apt update && sudo apt install -y rsync netcat-openbsd tree
docker network create imi-ci-service-network --subnet 172.10.12.0/24
docker compose -f ./.github/service/redis-cluster/docker-compose.yml up -d
docker compose -f ./.github/docker-compose.yml up -d mysql postgres redis redis-new rabbitmq kafka1
docker compose -f ./.github/docker-compose.yml up -d mysql postgres redis rabbitmq kafka1
echo "127.0.0.1 kafka1" | sudo tee -a /etc/hosts
- name: Setup swoole-cli
run: .github/script/install-swoole-cli.sh ${{ matrix.swoole-cli }}
Expand Down Expand Up @@ -199,10 +202,7 @@ jobs:
find /run/shared -name *.sock
tree -alfugh /run/shared
echo ">>> redis"
echo -e 'info server' | nc 127.0.0.1 6379 -w 1
echo ">>> ====="
echo ">>> redis-new"
echo -e 'auth l83aa26\r\ninfo server' | nc 127.0.0.1 6377 -w 1
echo -e 'auth l83aa26\r\ninfo server' | nc 127.0.0.1 6379 -w 1
echo ">>> ====="
docker compose -f ./.github/service/redis-cluster/docker-compose.yml logs
echo ">>> redis-cluster"
Expand All @@ -211,9 +211,6 @@ jobs:
docker compose -f ./.github/service/redis-cluster/docker-compose.yml exec node-0 cat /bitnami/redis/data/nodes.conf
- name: Test
if: ${{ env.test_prepared && always() }}
env:
REDIS_SERVER_CLUSTER_PASSWORD: "l83aa26"
REDIS_SERVER_CLUSTER_SEEDS: "172.10.12.2:6379,172.10.12.3:6379,172.10.12.4:6379,172.10.12.5:6379,172.10.12.6:6379,172.10.12.7:6379"
run: composer test
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
Expand All @@ -224,10 +221,8 @@ jobs:
- name: Test redis
if: ${{ env.test_prepared && always() }}
env:
REDIS_SERVER_CLUSTER_PASSWORD: "l83aa26"
REDIS_SERVER_CLUSTER_SEEDS: "172.10.12.2:6379,172.10.12.3:6379,172.10.12.4:6379,172.10.12.5:6379,172.10.12.6:6379,172.10.12.7:6379"
REDIS_SERVER_TLS_CLUSTER_SEEDS: "172.10.12.2:6443,172.10.12.3:6443,172.10.12.4:6443,172.10.12.5:6443,172.10.12.6:6443,172.10.12.7:6443"
REDIS_SERVER_UNIX_SOCK: "/run/shared/redis.sock"
REDIS_SERVER_TLS_CLUSTER_SEEDS: "172.10.12.2:6443,172.10.12.3:6443,172.10.12.4:6443,172.10.12.5:6443,172.10.12.6:6443,172.10.12.7:6443"
REDIS_SERVER_TLS_HOST: "127.0.0.1"
REDIS_SERVER_TLS_PORT: "6443"
REDIS_SERVER_TLS_PASSWORD: "l83aa26"
Expand Down
2 changes: 2 additions & 0 deletions src/Components/amqp/tests/PHPUnitHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function executeBeforeFirstTest(): void
App::run('AMQPApp', CliApp::class, static function (): void {
});
break;
default:
throw new \RuntimeException('Unsupported AMQP_TEST_MODE');
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Components/amqp/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ function startServer(): void
$redis = new \Redis();
$host = env('REDIS_SERVER_HOST', '127.0.0.1');
$port = env('REDIS_SERVER_PORT', 6379);
$password = env('REDIS_SERVER_PASSWORD');
if (!(str_contains($host, '/') ? $redis->connect($host) : $redis->connect($host, $port)))
{
exit('Redis connect failed');
}
if ($password)
{
$redis->auth($password);
}
$redis->del($redis->keys('imi-amqp:*'));
$redis->close();
})();
Expand Down
4 changes: 2 additions & 2 deletions src/Components/redis/tests/Tests/RedisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testPhpRedisUnixSockConnection(): void
host: env('REDIS_SERVER_UNIX_SOCK'),
port: 0,
seeds: null,
password: null,
password: env('REDIS_SERVER_PASSWORD'),
database: 0,
prefix: '',
timeout: 1,
Expand Down Expand Up @@ -172,7 +172,7 @@ public function testPredisUnixSockConnection(): void
host: env('REDIS_SERVER_UNIX_SOCK'),
port: 0,
seeds: null,
password: null,
password: env('REDIS_SERVER_PASSWORD'),
database: 0,
prefix: '',
timeout: 1,
Expand Down

0 comments on commit 347d0e5

Please sign in to comment.