diff --git a/.githooks/commit-msg b/.githooks/commit-msg deleted file mode 100644 index 1608390..0000000 --- a/.githooks/commit-msg +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -if [ -z "$1" ]; then - echo "Missing argument (commit message). Did you try to run this manually?" - exit 1 -fi - -commitTitle="$(cat $1 | head -n1)" - -# ignore merge -if echo "$commitTitle" | grep -qE "^Merge"; then - echo "Commit hook: ignoring merge" - exit 0 -fi - -# check commit message -REGEX='^(feat|fix|docs|style|refactor|ci|test|chore|comment)\(.*\)\:.*' -if ! echo "$commitTitle" | grep -qE ${REGEX}; then - echo "Your commit title '$commitTitle' did not follow conventional commit message rules:" - echo "Please comply with the regex ${REGEX}" - exit 1 -fi diff --git a/.github/workflows/doc-links.yml b/.github/workflows/doc-links.yml new file mode 100644 index 0000000..e09ab28 --- /dev/null +++ b/.github/workflows/doc-links.yml @@ -0,0 +1,39 @@ +name: Documentation links + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + markdown-test-links: + name: Markdown test links + runs-on: ubuntu-latest + steps: + - name: Clone sources + uses: actions/checkout@v4 + with: + path: sources + + - name: Lauch localhost server + run: | + sudo npm install --global http-server + http-server ./sources & + + - name: Set up Ruby 2.6 + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + + - name: Check links in Markdown files + run: | + gem install awesome_bot + cd sources + awesome_bot README.md --skip-save-results --allow-dupe --base-url http://localhost:8080/ --white-list ddev.site diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f49b782..81d4681 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,22 +1,12 @@ name: Create Release -# example: gh workflow run release.yml -f tag_name=v1.1.4 -f draft=true +# example: gh workflow run release.yml -f tag_name=v1.1.4 on: workflow_dispatch: - branches: - - main inputs: tag_name: type: string description: Tag name required: true - draft: - type: boolean - description: Draft release - default: false - prerelease: - type: boolean - description: Prerelease - default: false jobs: create-release: @@ -45,7 +35,7 @@ jobs: - name: Check version ${{ env.VERSION_NUMBER }} consistency in files # Check CHANGELOG.md run: | - + # Check top ## [VERSION_NUMBER](GITHUB_URL/releases/tag/VERSION_NUMBER) - yyyy-mm-dd in CHANGELOG.md CURRENT_DATE=$(date +'%Y-%m-%d') echo $CURRENT_DATE @@ -58,7 +48,7 @@ jobs: echo "CHANGELOG VERSION KO" exit 1 fi - + # Check top [_Compare with previous release_](GITHUB_URL/compare/LAST_TAG...VERSION_NUMBER) in CHANGELOG.md COMPARISON=$(grep -oP "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/\K(.*)$" CHANGELOG.md | head -1) 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: fi - name: Create Tag ${{ github.event.inputs.tag_name }} - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{ github.token }} script: | @@ -98,3 +88,10 @@ jobs: tag_name: ${{ github.event.inputs.tag_name }} draft: ${{ github.event.inputs.draft }} prerelease: ${{ github.event.inputs.prerelease }} + + test-release: + name: Test release + needs: [create-release] + uses: ./.github/workflows/tests.yml + with: + debug_enabled: false diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cbbe159..5ec18cd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,12 +2,12 @@ name: tests on: pull_request: push: - branches: [ main ] + branches: [main] paths-ignore: - - '**.md' + - "**.md" schedule: - - cron: '44 08 * * *' + - cron: "44 08 * * *" workflow_dispatch: inputs: @@ -16,13 +16,19 @@ on: description: Debug with tmate required: false default: false + workflow_call: + inputs: + debug_enabled: + type: boolean + description: Debug with tmate + required: false + default: false permissions: actions: write jobs: tests: - strategy: matrix: ddev_version: [stable, HEAD] diff --git a/README.md b/README.md index 581467c..e93a999 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,30 @@ ## What is ddev-mongo? -This repository provides Mongo and Mongo Express add-on to [DDEV](https://ddev.readthedocs.io). +This repository provides Mongo and Mongo Express add-on to [DDEV](https://ddev.readthedocs.io/en/stable/). 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). +## Installation + +For DDEV v1.23.5 or above run + +```bash +ddev add-on get ddev/ddev-mongo +``` + +For earlier versions of DDEV run + +```bash +ddev get ddev/ddev-mongo +``` + +Then restart your project + +```bash +ddev restart +``` + ## Configuration 1. Your project will likely require the [Doctrine MongoDB ODM bundle](https://github.com/doctrine/DoctrineMongoDBBundle) @@ -13,13 +33,11 @@ It's based on [MongoDb from Docker Hub](https://hub.docker.com/_/mongo?tab=descr 2. In your application `.env` or other client, set the connection string: - ``` - MONGODB_URL=mongodb://db:db@mongo:27017 - MONGODB_DB=api - ``` - -Mongo Express will now be accessible from `http://.ddev.site:9091` + ``` + MONGODB_URL=mongodb://db:db@mongo:27017 + ``` +Mongo Express will now be accessible by running `ddev mongo-express` command. ## Features @@ -27,13 +45,15 @@ Mongo Express will now be accessible from `http://.ddev.site:9091` 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. +### `ddev mongo-express` command -## Caveats: +This command opens your browser to the Mongo Express page. -* 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. -* You can't define custom MongoDB configuration with this current setup. -* You can't use `ddev import-db` to import to mongo. +## Caveats: +- 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. +- You can't define custom MongoDB configuration with this current setup. +- You can't use `ddev import-db` to import to mongo. **Based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/mongodb)** diff --git a/commands/host/mongo-express b/commands/host/mongo-express new file mode 100644 index 0000000..a66a892 --- /dev/null +++ b/commands/host/mongo-express @@ -0,0 +1,23 @@ +#!/bin/bash + +## #ddev-generated: If you want to edit and own this file, remove this line. +## Description: Launch a browser with Mongo Express +## Usage: mongo-express +## Example: "ddev mongo-express" + +# Determine whether to use HTTP or HTTPS based on environment +PROTOCOL="HTTP" +if [ "${DDEV_PRIMARY_URL%://*}" != "http" ] && [ -z "${GITPOD_WORKSPACE_ID:-}" ] && [ "${CODESPACES:-}" != "true" ]; then + PROTOCOL="HTTPS" +fi + +# Fetch the appropriate port within the mongo-express container +DDEV_MONGO_EXPRESS_PORT=$(ddev exec -s mongo-express sh -c "printenv | grep -w ${PROTOCOL}_EXPOSE | cut -d '=' -f 2 | cut -d ':' -f 1") + +if [ -z "$DDEV_MONGO_EXPRESS_PORT" ]; then + echo "Error: Could not retrieve Mongo Express port." + exit 1 +fi + +ddev launch :"$DDEV_MONGO_EXPRESS_PORT" + diff --git a/docker-compose.mongo_norouter.yaml b/docker-compose.mongo_norouter.yaml new file mode 100644 index 0000000..44cead2 --- /dev/null +++ b/docker-compose.mongo_norouter.yaml @@ -0,0 +1,4 @@ +#ddev-generated +# If omit_containers[ddev-router] then this file will be replaced +# with another with a `ports` statement to directly expose port 9091 to 8081 +services: {} diff --git a/install.yaml b/install.yaml index d28fa22..b3d0a21 100644 --- a/install.yaml +++ b/install.yaml @@ -1,11 +1,28 @@ name: mongo pre_install_actions: -- | - #ddev-description:Create config.mongo.yaml with webimage_extra_packages in it - printf '#ddev-generated\nwebimage_extra_packages: ["php${DDEV_PHP_VERSION}-mongodb"]\n' >.ddev/config.mongo.yaml + - | + #ddev-description:Create config.mongo.yaml with webimage_extra_packages in it + printf '#ddev-generated\nwebimage_extra_packages: ["php${DDEV_PHP_VERSION}-mongodb"]\n' >.ddev/config.mongo.yaml + # Ensure we're on DDEV 1.23+. It's required for the `redis-commander` command (launch by port). + - | + #ddev-nodisplay + #ddev-description:Checking DDEV version + (ddev debug capabilities | grep corepack >/dev/null) || (echo "Please upgrade DDEV to v1.23+ to enable launching." && false) + +post_install_actions: + - | + #ddev-description:If router disabled, directly expose port + # + if ( {{ contains "ddev-router" (list .DdevGlobalConfig.omit_containers | toString) }} ); then + printf "#ddev-generated\nservices:\n mongo-express:\n ports:\n - 9091:8081\n" > docker-compose.mongo_norouter.yaml + fi + - | + echo "You can now use 'ddev mongo-express' to launch Mongo Express UI" # list of files and directories listed that are copied into project .ddev directory project_files: -- commands/mongo/mongosh -- docker-compose.mongo.yaml + - commands/mongo/mongosh + - commands/host/mongo-express + - docker-compose.mongo.yaml + - docker-compose.mongo_norouter.yaml diff --git a/tests/test.bats b/tests/test.bats index da48b9b..2892ae2 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -1,5 +1,8 @@ setup() { set -eu -o pipefail + brew_prefix=$(brew --prefix) + load "${brew_prefix}/lib/bats-support/load.bash" + load "${brew_prefix}/lib/bats-assert/load.bash" export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." export TESTDIR=~/tmp/testmongo mkdir -p $TESTDIR @@ -19,12 +22,11 @@ teardown() { [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} } -@test "install from directory" { - set -eu -o pipefail - cd ${TESTDIR} - echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ${DIR} >/dev/null - ddev restart >/dev/null +health_checks() { + set +u # bats-assert has unset variables so turn off unset check + # ddev restart is required because we have done `ddev add-on get` on a new service + run ddev restart + assert_success curl -sI ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | grep "HTTP/1.1 200 OK" out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user") [ "${out}" = "db" ] @@ -39,26 +41,25 @@ teardown() { echo "$result" exit 1 fi + # Make sure `ddev mongo-express` works + DDEV_DEBUG=true run ddev mongo-express + assert_success + assert_output --partial "FULLURL https://${PROJNAME}.ddev.site:9092" } +@test "install from directory" { + set -eu -o pipefail + cd ${TESTDIR} + echo "# ddev add-on get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev add-on get ${DIR} >/dev/null + health_checks +} + +# bats test_tags=release @test "install from release" { set -eu -o pipefail cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) - echo "# ddev get ddev/ddev-mongo with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ddev/ddev-mongo >/dev/null - ddev restart >/dev/null - curl -sI ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | grep "HTTP/1.1 200 OK" - out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user") - [ "${out}" = "db" ] - (ddev exec php -i | grep mongodb.debug) || (echo "# php mongodb extension not found" >&3 || exit 1) - # Test mongosh - 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' '#') - if [[ $result == "ok#" ]] - then - echo "# Mongosh OK" >&3 - else - echo "# Mongosh KO" - echo "$result" - exit 1 - fi + echo "# ddev add-on get ddev/ddev-mongo with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev add-on get ddev/ddev-mongo >/dev/null + health_checks }