Skip to content

Commit

Permalink
Add MongoDB extension and service (#748)
Browse files Browse the repository at this point in the history
* Add MongoDB service

Use mongodb-atlas-local to provide most cloud features locally

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
GromNaN and taylorotwell authored Nov 7, 2024
1 parent ea7ce73 commit 2304fb2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 deletions.
13 changes: 13 additions & 0 deletions bin/sail
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function display_help {
echo " ${GREEN}sail mysql${NC} Start a MySQL CLI session within the 'mysql' container"
echo " ${GREEN}sail mariadb${NC} Start a MySQL CLI session within the 'mariadb' container"
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
echo "${YELLOW}Debugging:${NC}"
Expand Down Expand Up @@ -526,6 +527,18 @@ elif [ "$1" == "root-shell" ] || [ "$1" == "root-bash" ]; then
sail_is_not_running
fi

# Initiate a MongoDB Shell within the "mongodb" container...
elif [ "$1" == "mongodb" ]; then
shift 1

if [ "$EXEC" == "yes" ]; then
ARGS+=(exec)
[ ! -t 0 ] && ARGS+=(-T)
ARGS+=(mongodb mongosh --port "${FORWARD_MONGODB_PORT:-27017}" --username "$MONGODB_USERNAME" --password "$MONGODB_PASSWORD" --authenticationDatabase admin)
else
sail_is_not_running
fi

# Initiate a Redis CLI terminal session within the "redis" container...
elif [ "$1" == "redis" ]; then
shift 1
Expand Down
2 changes: 1 addition & 1 deletion runtimes/8.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get update && apt-get upgrade -y \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd php8.0-imagick \
php8.0-curl php8.0-memcached \
php8.0-curl php8.0-memcached php8.0-mongodb \
php8.0-imap php8.0-mysql php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline php8.0-pcov \
Expand Down
2 changes: 1 addition & 1 deletion runtimes/8.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get update && apt-get upgrade -y \
&& apt-get update \
&& apt-get install -y php8.1-cli php8.1-dev \
php8.1-pgsql php8.1-sqlite3 php8.1-gd php8.1-imagick \
php8.1-curl \
php8.1-curl php8.1-mongodb \
php8.1-imap php8.1-mysql php8.1-mbstring \
php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
php8.1-intl php8.1-readline \
Expand Down
2 changes: 1 addition & 1 deletion runtimes/8.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get update && apt-get upgrade -y \
&& apt-get update \
&& apt-get install -y php8.2-cli php8.2-dev \
php8.2-pgsql php8.2-sqlite3 php8.2-gd php8.2-imagick \
php8.2-curl \
php8.2-curl php8.2-mongodb \
php8.2-imap php8.2-mysql php8.2-mbstring \
php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap \
php8.2-intl php8.2-readline \
Expand Down
2 changes: 1 addition & 1 deletion runtimes/8.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN apt-get update && apt-get upgrade -y \
&& apt-get update \
&& apt-get install -y php8.3-cli php8.3-dev \
php8.3-pgsql php8.3-sqlite3 php8.3-gd \
php8.3-curl \
php8.3-curl php8.3-mongodb \
php8.3-imap php8.3-mysql php8.3-mbstring \
php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap \
php8.3-intl php8.3-readline \
Expand Down
2 changes: 1 addition & 1 deletion runtimes/8.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN apt-get update && apt-get upgrade -y \
&& apt-get update \
&& apt-get install -y php8.4-cli php8.4-dev \
php8.4-pgsql php8.4-sqlite3 php8.4-gd \
php8.4-curl \
php8.4-curl php8.4-mongodb \
php8.4-imap php8.4-mysql php8.4-mbstring \
php8.4-xml php8.4-zip php8.4-bcmath php8.4-soap \
php8.4-intl php8.4-readline \
Expand Down
8 changes: 7 additions & 1 deletion src/Console/Concerns/InteractsWithDockerComposeServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ trait InteractsWithDockerComposeServices
'mysql',
'pgsql',
'mariadb',
'mongodb',
'redis',
'memcached',
'meilisearch',
Expand Down Expand Up @@ -92,7 +93,7 @@ protected function buildDockerCompose(array $services)
// Merge volumes...
collect($services)
->filter(function ($service) {
return in_array($service, ['mysql', 'pgsql', 'mariadb', 'redis', 'meilisearch', 'typesense', 'minio']);
return in_array($service, ['mysql', 'pgsql', 'mariadb', 'mongodb', 'redis', 'meilisearch', 'typesense', 'minio']);
})->filter(function ($service) use ($compose) {
return ! array_key_exists($service, $compose['volumes'] ?? []);
})->each(function ($service) use (&$compose) {
Expand Down Expand Up @@ -163,6 +164,11 @@ protected function replaceEnvVariables(array $services)
$environment = str_replace('REDIS_HOST=127.0.0.1', 'REDIS_HOST=redis', $environment);
}

if (in_array('mongodb', $services)) {
$environment .= "\nMONGODB_URI=mongodb://mongodb:27017";
$environment .= "\nMONGODB_DATABASE=laravel";
}

if (in_array('meilisearch', $services)) {
$environment .= "\nSCOUT_DRIVER=meilisearch";
$environment .= "\nMEILISEARCH_HOST=http://meilisearch:7700\n";
Expand Down
19 changes: 19 additions & 0 deletions stubs/mongodb.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mongodb:
image: 'mongodb/mongodb-atlas-local:latest'
environment:
- MONGODB_INITDB_ROOT_USERNAME=${MONGODB_USERNAME:-}
- MONGODB_INITDB_ROOT_PASSWORD=${MONGODB_PASSWORD:-}
volumes:
- 'sail-mongodb:/data/db'
ports:
- '${FORWARD_MONGODB_PORT:-27017}:27017'
networks:
- sail
healthcheck:
test:
- CMD
- mongosh
- 'mongodb://localhost:27017/admin'
- '--eval=db.runCommand({ping:1})'
retries: 3
timeout: 5s

0 comments on commit 2304fb2

Please sign in to comment.