Skip to content

Commit 9ad6c98

Browse files
authored
feat(*): start mongo-express on demand, constraint v1.24.4, update readme (#22)
* feat: start mongo-express on demand, update readme, constraint v1.24.4 * whitelist latest release link * Small README.md changes * test: add `sleep 3` * Remove sleep in mongo-express entrypoint (we already have a delayed start) * And we don't need to override mongo-express entrypoint in this case * Add `condition: service_healthy` * Say "on demand" for Mongo Express
1 parent 4323123 commit 9ad6c98

File tree

7 files changed

+101
-78
lines changed

7 files changed

+101
-78
lines changed

.github/workflows/doc-links.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
path: sources
2424

25-
- name: Lauch localhost server
25+
- name: Launch localhost server
2626
run: |
2727
sudo npm install --global http-server
2828
http-server ./sources &
@@ -36,4 +36,4 @@ jobs:
3636
run: |
3737
gem install awesome_bot
3838
cd sources
39-
awesome_bot README.md --skip-save-results --allow-dupe --base-url http://localhost:8080/ --white-list ddev.site
39+
awesome_bot README.md --skip-save-results --allow-dupe --base-url http://localhost:8080/ --white-list ddev.site,github.com/ddev/ddev-mongo/releases/latest

README.md

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,91 @@
1-
[![tests](https://github.com/ddev/ddev-mongo/actions/workflows/tests.yml/badge.svg)](https://github.com/ddev/ddev-mongo/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2024.svg)
1+
[![add-on registry](https://img.shields.io/badge/DDEV-Add--on_Registry-blue)](https://addons.ddev.com)
2+
[![tests](https://github.com/ddev/ddev-mongo/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/ddev/ddev-mongo/actions/workflows/tests.yml?query=branch%3Amain)
3+
[![last commit](https://img.shields.io/github/last-commit/ddev/ddev-mongo)](https://github.com/ddev/ddev-mongo/commits)
4+
[![release](https://img.shields.io/github/v/release/ddev/ddev-mongo)](https://github.com/ddev/ddev-mongo/releases/latest)
25

3-
## What is ddev-mongo?
6+
# DDEV Mongo
47

5-
This repository is an add-on that provides Mongo and Mongo Express for [DDEV](https://ddev.readthedocs.io/en/stable/).
8+
## Overview
69

7-
It's based on [MongoDb from Docker Hub](https://hub.docker.com/_/mongo?tab=description#-via-docker-stack-deploy-or-docker-compose), [DDEV custom compose files](https://ddev.readthedocs.io/en/stable/users/extend/custom-compose-files/) and [API Platform tutorial](https://api-platform.com/docs/core/mongodb/#enabling-mongodb-support).
10+
[MongoDB](https://www.mongodb.com/) is a source-available, cross-platform, document-oriented database program. Classified as a NoSQL database product, MongoDB uses JSON-like documents with optional schemas.
811

9-
## Installation
10-
11-
For DDEV v1.23.5 or above run
12-
13-
```bash
14-
ddev add-on get ddev/ddev-mongo
15-
```
12+
This add-on integrates MongoDB and Mongo Express into your [DDEV](https://ddev.com/) project.
1613

17-
For earlier versions of DDEV run
14+
It's based on [MongoDB from Docker Hub](https://hub.docker.com/_/mongo?tab=description), [DDEV custom compose files](https://ddev.readthedocs.io/en/stable/users/extend/custom-compose-files/) and [API Platform tutorial](https://api-platform.com/docs/core/mongodb/#enabling-mongodb-support).
1815

19-
```bash
20-
ddev get ddev/ddev-mongo
21-
```
22-
23-
Then restart your project
16+
## Installation
2417

2518
```bash
19+
ddev add-on get ddev/ddev-mongo
2620
ddev restart
2721
```
2822

23+
After installation, make sure to commit the `.ddev` directory to version control.
24+
2925
## Configuration
3026

3127
1. Your project will likely require the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle)
3228
`ddev composer require doctrine/mongodb-odm-bundle:^4.0.0@beta doctrine/mongodb-odm:^2.0.0@beta`
3329

3430
2. In your application `.env` or other client, set the connection string:
3531

36-
```
32+
```dotenv
3733
MONGODB_URL=mongodb://db:db@mongo:27017
3834
```
3935

40-
Mongo Express will now be accessible by running `ddev mongo-express` command.
41-
42-
## Features
43-
44-
### `ddev mongosh` command
36+
Mongo Express can now be started on demand using the `ddev mongo-express` command. (This optional feature is available starting from DDEV v1.24.4+.)
4537

46-
This command will run the `mongosh` (mongoDB Shell) command in the `mongo` container. Please [read the documentation](https://www.mongodb.com/docs/mongodb-shell/) for more information.
38+
## Usage
4739

48-
### `ddev mongo-express` command
49-
50-
This command opens your browser to the Mongo Express page.
40+
| Command | Description |
41+
| ------- | ----------- |
42+
| `ddev mongosh` | Run MongoDB Shell, see the [documentation](https://www.mongodb.com/docs/mongodb-shell/) |
43+
| `ddev mongo-express` | Start web-based MongoDB admin interface |
44+
| `ddev describe` | View service status and used ports for MongoDB |
45+
| `ddev logs -s mongo` | Check MongoDB logs |
46+
| `ddev logs -s mongo-express` | Check Mongo Express logs (if it's started) |
5147

5248
## Caveats:
5349

54-
- The php extension (phpX.X-mongodb) is set up in `.ddev/config.mongo.yaml` using `webimage_extra_packages`. You may want to edit your config.yaml to do what you want and remove the config.mongo.yaml.
50+
- The php extension (`phpX.X-mongodb`) is set up in `.ddev/config.mongo.yaml` using `webimage_extra_packages`. You may want to edit your `.ddev/config.yaml` to do what you want and remove the `.ddev/config.mongo.yaml`.
5551
- You can't define custom MongoDB configuration with this current setup.
5652
- You can't use `ddev import-db` to import to mongo.
5753

58-
**Based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/mongodb)**
54+
## Advanced Customization
55+
56+
If you don't want to authenticate with the default admin user, create a new file `.ddev/docker-compose.mongo_extra.yaml`:
57+
58+
```yaml
59+
services:
60+
mongo:
61+
environment:
62+
- MONGO_INITDB_ROOT_USERNAME=
63+
- MONGO_INITDB_ROOT_PASSWORD=
64+
mongo-express:
65+
environment:
66+
- ME_CONFIG_MONGODB_URL=mongodb://mongo:27017
67+
```
68+
69+
(Don't forget to update your application's `.env` file.)
70+
71+
To change the Docker image:
72+
73+
```bash
74+
ddev dotenv set .ddev/.env.mongo --mongo-docker-image=mongo:5-focal
75+
ddev add-on get ddev/ddev-mongo
76+
ddev restart
77+
```
78+
79+
Make sure to commit the `.ddev/.env.mongo` file to version control.
80+
81+
All customization options (use with caution):
82+
83+
| Variable | Flag | Default |
84+
| -------- | ---- | ------- |
85+
| `MONGO_DOCKER_IMAGE` | `--mongo-docker-image` | `mongo:5-focal` |
86+
| `MONGO_EXPRESS_DOCKER_IMAGE` | `--mongo-express-docker-image` | `mongo-express:1.0` |
87+
88+
## Credits
5989

6090
**Originally contributed by [@wtfred](https://github.com/wtfred)**
6191

commands/host/mongo-express

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
## #ddev-generated: If you want to edit and own this file, remove this line.
44
## Description: Launch a browser with Mongo Express
@@ -11,6 +11,9 @@ if [ "${DDEV_PRIMARY_URL%://*}" != "http" ] && [ -z "${GITPOD_WORKSPACE_ID:-}" ]
1111
PROTOCOL="HTTPS"
1212
fi
1313

14+
# Start mongo-express if it's not started
15+
ddev exec -s mongo-express true >/dev/null 2>&1 || ddev start --profiles mongo-express
16+
1417
# Fetch the appropriate port within the mongo-express container
1518
DDEV_MONGO_EXPRESS_PORT=$(ddev exec -s mongo-express sh -c "printenv | grep -w ${PROTOCOL}_EXPOSE | cut -d '=' -f 2 | cut -d ':' -f 1")
1619

@@ -20,4 +23,3 @@ if [ -z "$DDEV_MONGO_EXPRESS_PORT" ]; then
2023
fi
2124

2225
ddev launch :"$DDEV_MONGO_EXPRESS_PORT"
23-

commands/mongo/mongosh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#ddev-generated
33
# Remove the line above if you don't want this file to be overwritten when you run
44
# ddev get ddev/ddev-mongo
55
#
66
# This file comes from https://github.com/ddev/ddev-mongo
77
#
8-
## Description: Run mongosh command
8+
## Description: Run MongoDB Shell command
99
## Usage: mongosh <command>
1010
## ExecRaw: true
1111
## Example: "ddev mongosh "mongodb://mongo:27017"

docker-compose.mongo.yaml

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,57 @@
11
#ddev-generated
2-
# Remove the line above if you don't want this file to be overwritten when you run
3-
# ddev get ddev/ddev-mongo
4-
#
5-
# This file comes from https://github.com/ddev/ddev-mongo
6-
#
72
services:
83
mongo:
94
container_name: ddev-${DDEV_SITENAME}-mongo
10-
image: mongo:5-focal
5+
image: ${MONGO_DOCKER_IMAGE:-mongo:5-focal}
116
volumes:
12-
- type: "volume"
13-
source: mongo
14-
target: "/data/db"
15-
volume:
16-
nocopy: true
17-
- type: "volume"
18-
source: mongo-config
19-
target: "/data/configdb"
20-
volume:
21-
nocopy: true
22-
- ".:/mnt/ddev_config"
7+
- type: "volume"
8+
source: mongo
9+
target: "/data/db"
10+
volume:
11+
nocopy: true
12+
- type: "volume"
13+
source: mongo-config
14+
target: "/data/configdb"
15+
volume:
16+
nocopy: true
17+
- ".:/mnt/ddev_config"
18+
- "ddev-global-cache:/mnt/ddev-global-cache"
2319
restart: "no"
2420
expose:
25-
- "27017"
21+
- "27017"
2622
labels:
2723
com.ddev.site-name: ${DDEV_SITENAME}
28-
com.ddev.approot: $DDEV_APPROOT
24+
com.ddev.approot: ${DDEV_APPROOT}
2925
environment:
30-
- MONGO_INITDB_ROOT_USERNAME=db
31-
- MONGO_INITDB_ROOT_PASSWORD=db
32-
# See https://github.com/docker-library/docs/tree/master/mongo#mongo_initdb_database
33-
# - MONGO_INITDB_DATABASE=db
26+
- MONGO_INITDB_ROOT_USERNAME=db
27+
- MONGO_INITDB_ROOT_PASSWORD=db
28+
# See https://github.com/docker-library/docs/tree/master/mongo#mongo_initdb_database
29+
# - MONGO_INITDB_DATABASE=db
3430
healthcheck:
3531
test: ["CMD-SHELL", "mongo --eval 'db.runCommand(\"ping\").ok' localhost:27017/test --quiet"]
3632
timeout: 60s
3733

3834
mongo-express:
3935
container_name: ddev-${DDEV_SITENAME}-mongo-express
40-
image: mongo-express:1.0
36+
image: ${MONGO_EXPRESS_DOCKER_IMAGE:-mongo-express:1.0}
4137
restart: "no"
4238
labels:
4339
com.ddev.site-name: ${DDEV_SITENAME}
4440
com.ddev.approot: ${DDEV_APPROOT}
45-
com.ddev.platform: ddev
4641
expose:
47-
- "8081"
42+
- "8081"
4843
environment:
49-
VIRTUAL_HOST: $DDEV_HOSTNAME
50-
ME_CONFIG_MONGODB_ENABLE_ADMIN: "true"
51-
ME_CONFIG_BASICAUTH: "false"
52-
ME_CONFIG_MONGODB_URL: "mongodb://db:db@mongo:27017"
53-
HTTP_EXPOSE: "9091:8081"
54-
HTTPS_EXPOSE: "9092:8081"
44+
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
45+
- ME_CONFIG_BASICAUTH=false
46+
- ME_CONFIG_MONGODB_URL=mongodb://db:db@mongo:27017
47+
- VIRTUAL_HOST=$DDEV_HOSTNAME
48+
- HTTP_EXPOSE=9091:8081
49+
- HTTPS_EXPOSE=9092:8081
5550
depends_on:
56-
- mongo
57-
entrypoint: [sh, -c, "sleep 5s && tini -- /docker-entrypoint.sh mongo-express"]
51+
mongo:
52+
condition: service_healthy
53+
profiles:
54+
- mongo-express
5855

5956
volumes:
6057
mongo:

install.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@ pre_install_actions:
44
- |
55
#ddev-description:Create config.mongo.yaml with webimage_extra_packages in it
66
printf '#ddev-generated\nwebimage_extra_packages: ["php${DDEV_PHP_VERSION}-mongodb"]\n' >.ddev/config.mongo.yaml
7-
# Ensure we're on DDEV 1.23+. It's required for the `mongo-express` command (launch by port).
8-
# ddev_version_constraint (see below) is only available in DDEV 1.23.4+, so we keep this check for now.
9-
# Should be removed when DDEV 1.24 is released.
10-
- |
11-
#ddev-nodisplay
12-
#ddev-description:Checking DDEV version
13-
(ddev debug capabilities | grep corepack >/dev/null) || (echo "Please upgrade DDEV to v1.23+ to enable launching." && false)
147
15-
ddev_version_constraint: ">= v1.23.0"
8+
ddev_version_constraint: ">= v1.24.4"
169

1710
post_install_actions:
1811
- |
@@ -24,7 +17,6 @@ post_install_actions:
2417
- |
2518
echo "You can now use 'ddev mongo-express' to launch Mongo Express UI"
2619
27-
# list of files and directories listed that are copied into project .ddev directory
2820
project_files:
2921
- commands/mongo/mongosh
3022
- commands/host/mongo-express

tests/test.bats

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ health_checks() {
4747
assert_success
4848
assert_output --partial '"ok":1'
4949

50+
# Start mongo-express profile
5051
DDEV_DEBUG=true run ddev mongo-express
5152
assert_success
53+
assert_output --partial "mongo-express"
5254
assert_output --partial "FULLURL https://${PROJNAME}.ddev.site:9092"
5355

5456
run curl -sfI https://${PROJNAME}.ddev.site:9092/db/admin/expArr/system.users

0 commit comments

Comments
 (0)