Skip to content

Commit cec03c8

Browse files
feat(*): Add mongo-express command (#19)
1 parent 208ef2a commit cec03c8

File tree

9 files changed

+164
-79
lines changed

9 files changed

+164
-79
lines changed

.githooks/commit-msg

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/doc-links.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Documentation links
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
markdown-test-links:
17+
name: Markdown test links
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Clone sources
21+
uses: actions/checkout@v4
22+
with:
23+
path: sources
24+
25+
- name: Lauch localhost server
26+
run: |
27+
sudo npm install --global http-server
28+
http-server ./sources &
29+
30+
- name: Set up Ruby 2.6
31+
uses: ruby/setup-ruby@v1
32+
with:
33+
ruby-version: 2.6
34+
35+
- name: Check links in Markdown files
36+
run: |
37+
gem install awesome_bot
38+
cd sources
39+
awesome_bot README.md --skip-save-results --allow-dupe --base-url http://localhost:8080/ --white-list ddev.site

.github/workflows/release.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
name: Create Release
2-
# example: gh workflow run release.yml -f tag_name=v1.1.4 -f draft=true
2+
# example: gh workflow run release.yml -f tag_name=v1.1.4
33
on:
44
workflow_dispatch:
5-
branches:
6-
- main
75
inputs:
86
tag_name:
97
type: string
108
description: Tag name
119
required: true
12-
draft:
13-
type: boolean
14-
description: Draft release
15-
default: false
16-
prerelease:
17-
type: boolean
18-
description: Prerelease
19-
default: false
2010

2111
jobs:
2212
create-release:
@@ -45,7 +35,7 @@ jobs:
4535
- name: Check version ${{ env.VERSION_NUMBER }} consistency in files
4636
# Check CHANGELOG.md
4737
run: |
48-
38+
4939
# Check top ## [VERSION_NUMBER](GITHUB_URL/releases/tag/VERSION_NUMBER) - yyyy-mm-dd in CHANGELOG.md
5040
CURRENT_DATE=$(date +'%Y-%m-%d')
5141
echo $CURRENT_DATE
@@ -58,7 +48,7 @@ jobs:
5848
echo "CHANGELOG VERSION KO"
5949
exit 1
6050
fi
61-
51+
6252
# Check top [_Compare with previous release_](GITHUB_URL/compare/LAST_TAG...VERSION_NUMBER) in CHANGELOG.md
6353
COMPARISON=$(grep -oP "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/\K(.*)$" CHANGELOG.md | head -1)
6454
LAST_TAG=$(curl -Ls -o /dev/null -w %{url_effective} $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/latest | grep -oP "\/tag\/\K(.*)$")
@@ -73,7 +63,7 @@ jobs:
7363
fi
7464
7565
- name: Create Tag ${{ github.event.inputs.tag_name }}
76-
uses: actions/github-script@v6
66+
uses: actions/github-script@v7
7767
with:
7868
github-token: ${{ github.token }}
7969
script: |
@@ -98,3 +88,10 @@ jobs:
9888
tag_name: ${{ github.event.inputs.tag_name }}
9989
draft: ${{ github.event.inputs.draft }}
10090
prerelease: ${{ github.event.inputs.prerelease }}
91+
92+
test-release:
93+
name: Test release
94+
needs: [create-release]
95+
uses: ./.github/workflows/tests.yml
96+
with:
97+
debug_enabled: false

.github/workflows/tests.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ name: tests
22
on:
33
pull_request:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
paths-ignore:
7-
- '**.md'
7+
- "**.md"
88

99
schedule:
10-
- cron: '44 08 * * *'
10+
- cron: "44 08 * * *"
1111

1212
workflow_dispatch:
1313
inputs:
@@ -16,13 +16,19 @@ on:
1616
description: Debug with tmate
1717
required: false
1818
default: false
19+
workflow_call:
20+
inputs:
21+
debug_enabled:
22+
type: boolean
23+
description: Debug with tmate
24+
required: false
25+
default: false
1926

2027
permissions:
2128
actions: write
2229

2330
jobs:
2431
tests:
25-
2632
strategy:
2733
matrix:
2834
ddev_version: [stable, HEAD]

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,58 @@
22

33
## What is ddev-mongo?
44

5-
This repository provides Mongo and Mongo Express add-on to [DDEV](https://ddev.readthedocs.io).
5+
This repository provides Mongo and Mongo Express add-on to [DDEV](https://ddev.readthedocs.io/en/stable/).
66

77
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).
88

9+
## Installation
10+
11+
For DDEV v1.23.5 or above run
12+
13+
```bash
14+
ddev add-on get ddev/ddev-mongo
15+
```
16+
17+
For earlier versions of DDEV run
18+
19+
```bash
20+
ddev get ddev/ddev-mongo
21+
```
22+
23+
Then restart your project
24+
25+
```bash
26+
ddev restart
27+
```
28+
929
## Configuration
1030

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

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

16-
```
17-
MONGODB_URL=mongodb://db:db@mongo:27017
18-
MONGODB_DB=api
19-
```
20-
21-
Mongo Express will now be accessible from `http://<project>.ddev.site:9091`
36+
```
37+
MONGODB_URL=mongodb://db:db@mongo:27017
38+
```
2239

40+
Mongo Express will now be accessible by running `ddev mongo-express` command.
2341

2442
## Features
2543

2644
### `ddev mongosh` command
2745

2846
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.
2947

48+
### `ddev mongo-express` command
3049

31-
## Caveats:
50+
This command opens your browser to the Mongo Express page.
3251

33-
* The php extension (phpX.X-mongodb) is set up in `.ddev/config.mongo.yaml` using `webimage_extra_packages`. If you have an earlier `webimage_extra_packages` in your config.yaml, this will override it. You may want to edit your config.yaml to do what you want and remove the config.mongo.yaml.
34-
* You can't define custom MongoDB configuration with this current setup.
35-
* You can't use `ddev import-db` to import to mongo.
52+
## Caveats:
3653

54+
- The php extension (phpX.X-mongodb) is set up in `.ddev/config.mongo.yaml` using `webimage_extra_packages`. If you have an earlier `webimage_extra_packages` in your config.yaml, this will override it. You may want to edit your config.yaml to do what you want and remove the config.mongo.yaml.
55+
- You can't define custom MongoDB configuration with this current setup.
56+
- You can't use `ddev import-db` to import to mongo.
3757

3858
**Based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/mongodb)**
3959

commands/host/mongo-express

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
## #ddev-generated: If you want to edit and own this file, remove this line.
4+
## Description: Launch a browser with Mongo Express
5+
## Usage: mongo-express
6+
## Example: "ddev mongo-express"
7+
8+
# Determine whether to use HTTP or HTTPS based on environment
9+
PROTOCOL="HTTP"
10+
if [ "${DDEV_PRIMARY_URL%://*}" != "http" ] && [ -z "${GITPOD_WORKSPACE_ID:-}" ] && [ "${CODESPACES:-}" != "true" ]; then
11+
PROTOCOL="HTTPS"
12+
fi
13+
14+
# Fetch the appropriate port within the mongo-express container
15+
DDEV_MONGO_EXPRESS_PORT=$(ddev exec -s mongo-express sh -c "printenv | grep -w ${PROTOCOL}_EXPOSE | cut -d '=' -f 2 | cut -d ':' -f 1")
16+
17+
if [ -z "$DDEV_MONGO_EXPRESS_PORT" ]; then
18+
echo "Error: Could not retrieve Mongo Express port."
19+
exit 1
20+
fi
21+
22+
ddev launch :"$DDEV_MONGO_EXPRESS_PORT"
23+

docker-compose.mongo_norouter.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ddev-generated
2+
# If omit_containers[ddev-router] then this file will be replaced
3+
# with another with a `ports` statement to directly expose port 9091 to 8081
4+
services: {}

install.yaml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
name: mongo
22

33
pre_install_actions:
4-
- |
5-
#ddev-description:Create config.mongo.yaml with webimage_extra_packages in it
6-
printf '#ddev-generated\nwebimage_extra_packages: ["php${DDEV_PHP_VERSION}-mongodb"]\n' >.ddev/config.mongo.yaml
4+
- |
5+
#ddev-description:Create config.mongo.yaml with webimage_extra_packages in it
6+
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 `redis-commander` command (launch by port).
8+
- |
9+
#ddev-nodisplay
10+
#ddev-description:Checking DDEV version
11+
(ddev debug capabilities | grep corepack >/dev/null) || (echo "Please upgrade DDEV to v1.23+ to enable launching." && false)
12+
13+
post_install_actions:
14+
- |
15+
#ddev-description:If router disabled, directly expose port
16+
#
17+
if ( {{ contains "ddev-router" (list .DdevGlobalConfig.omit_containers | toString) }} ); then
18+
printf "#ddev-generated\nservices:\n mongo-express:\n ports:\n - 9091:8081\n" > docker-compose.mongo_norouter.yaml
19+
fi
20+
- |
21+
echo "You can now use 'ddev mongo-express' to launch Mongo Express UI"
722
823
# list of files and directories listed that are copied into project .ddev directory
924
project_files:
10-
- commands/mongo/mongosh
11-
- docker-compose.mongo.yaml
25+
- commands/mongo/mongosh
26+
- commands/host/mongo-express
27+
- docker-compose.mongo.yaml
28+
- docker-compose.mongo_norouter.yaml

tests/test.bats

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
setup() {
22
set -eu -o pipefail
3+
brew_prefix=$(brew --prefix)
4+
load "${brew_prefix}/lib/bats-support/load.bash"
5+
load "${brew_prefix}/lib/bats-assert/load.bash"
36
export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
47
export TESTDIR=~/tmp/testmongo
58
mkdir -p $TESTDIR
@@ -19,12 +22,11 @@ teardown() {
1922
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
2023
}
2124

22-
@test "install from directory" {
23-
set -eu -o pipefail
24-
cd ${TESTDIR}
25-
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
26-
ddev get ${DIR} >/dev/null
27-
ddev restart >/dev/null
25+
health_checks() {
26+
set +u # bats-assert has unset variables so turn off unset check
27+
# ddev restart is required because we have done `ddev add-on get` on a new service
28+
run ddev restart
29+
assert_success
2830
curl -sI ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | grep "HTTP/1.1 200 OK"
2931
out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user")
3032
[ "${out}" = "db" ]
@@ -39,26 +41,25 @@ teardown() {
3941
echo "$result"
4042
exit 1
4143
fi
44+
# Make sure `ddev mongo-express` works
45+
DDEV_DEBUG=true run ddev mongo-express
46+
assert_success
47+
assert_output --partial "FULLURL https://${PROJNAME}.ddev.site:9092"
4248
}
4349

50+
@test "install from directory" {
51+
set -eu -o pipefail
52+
cd ${TESTDIR}
53+
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
54+
ddev add-on get ${DIR} >/dev/null
55+
health_checks
56+
}
57+
58+
# bats test_tags=release
4459
@test "install from release" {
4560
set -eu -o pipefail
4661
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
47-
echo "# ddev get ddev/ddev-mongo with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
48-
ddev get ddev/ddev-mongo >/dev/null
49-
ddev restart >/dev/null
50-
curl -sI ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | grep "HTTP/1.1 200 OK"
51-
out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user")
52-
[ "${out}" = "db" ]
53-
(ddev exec php -i | grep mongodb.debug) || (echo "# php mongodb extension not found" >&3 || exit 1)
54-
# Test mongosh
55-
result=$(ddev mongosh "mongodb://db:db@mongo:27017/test?authSource=admin" --quiet --eval '"printjson(db.getUsers())"' --json | grep "ok" | sed 's/: 1/ /g' | sed 's/ //g' | tr ' \n' '#')
56-
if [[ $result == "ok#" ]]
57-
then
58-
echo "# Mongosh OK" >&3
59-
else
60-
echo "# Mongosh KO"
61-
echo "$result"
62-
exit 1
63-
fi
62+
echo "# ddev add-on get ddev/ddev-mongo with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
63+
ddev add-on get ddev/ddev-mongo >/dev/null
64+
health_checks
6465
}

0 commit comments

Comments
 (0)