Skip to content

Commit

Permalink
Add Valkey support (#767)
Browse files Browse the repository at this point in the history
* add valkey stub

* add .idea files to gitignore

* add valkey-cli to sail bin

* fix valkey stub
add valkey support to InteractsWithDockerComposeServices.php file

* Update .gitignore

* Update sail

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
ariaieboy and taylorotwell authored Dec 30, 2024
1 parent f649351 commit f77164c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
13 changes: 13 additions & 0 deletions bin/sail
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function display_help {
echo " ${GREEN}sail psql${NC} Start a PostgreSQL CLI session within the 'pgsql' container"
echo " ${GREEN}sail mongodb${NC} Start a Mongo Shell session within the 'mongodb' container"
echo " ${GREEN}sail redis${NC} Start a Redis CLI session within the 'redis' container"
echo " ${GREEN}sail valkey${NC} Start a Valkey CLI session within the 'valkey' container"
echo
echo "${YELLOW}Debugging:${NC}"
echo " ${GREEN}sail debug ...${NC} Run an Artisan command in debug mode"
Expand Down Expand Up @@ -551,6 +552,18 @@ elif [ "$1" == "redis" ]; then
sail_is_not_running
fi

# Initiate a Valkey CLI terminal session within the "valkey" container...
elif [ "$1" == "valkey" ]; then
shift 1

if [ "$EXEC" == "yes" ]; then
ARGS+=(exec)
[ ! -t 0 ] && ARGS+=(-T)
ARGS+=(valkey valkey-cli)
else
sail_is_not_running
fi

# Share the site...
elif [ "$1" == "share" ]; then
shift 1
Expand Down
7 changes: 6 additions & 1 deletion src/Console/Concerns/InteractsWithDockerComposeServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ trait InteractsWithDockerComposeServices
'mariadb',
'mongodb',
'redis',
'valkey',
'memcached',
'meilisearch',
'typesense',
Expand Down Expand Up @@ -93,7 +94,7 @@ protected function buildDockerCompose(array $services)
// Merge volumes...
collect($services)
->filter(function ($service) {
return in_array($service, ['mysql', 'pgsql', 'mariadb', 'mongodb', 'redis', 'meilisearch', 'typesense', 'minio']);
return in_array($service, ['mysql', 'pgsql', 'mariadb', 'mongodb', 'redis', 'valkey', 'meilisearch', 'typesense', 'minio']);
})->filter(function ($service) use ($compose) {
return ! array_key_exists($service, $compose['volumes'] ?? []);
})->each(function ($service) use (&$compose) {
Expand Down Expand Up @@ -164,6 +165,10 @@ protected function replaceEnvVariables(array $services)
$environment = str_replace('REDIS_HOST=127.0.0.1', 'REDIS_HOST=redis', $environment);
}

if (in_array('valkey',$services)){
$environment = str_replace('REDIS_HOST=127.0.0.1', 'REDIS_HOST=valkey', $environment);
}

if (in_array('mongodb', $services)) {
$environment .= "\nMONGODB_URI=mongodb://mongodb:27017";
$environment .= "\nMONGODB_DATABASE=laravel";
Expand Down
12 changes: 12 additions & 0 deletions stubs/valkey.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
valkey:
image: 'valkey/valkey:alpine'
ports:
- '${FORWARD_VALKEY_PORT:-6379}:6379'
volumes:
- 'sail-valkey:/data'
networks:
- sail
healthcheck:
test: ["CMD", "valkey-cli", "ping"]
retries: 3
timeout: 5s

0 comments on commit f77164c

Please sign in to comment.